UP | HOME
Sachin Patil

Sachin

Free Software developer & Emacser

Network utilities

Published on Mar 24, 2012 by Sachin.

Few network configuration which can be performed using CLI, this post covers examples with syntax.

(Updated on Aug 09, 2018)

Note: You must be root or sudo user to run following commands. ifconfig has been deprecated in favor of ip

Assign IP address

Syntax

1: ifconfig <INTERFACE> <IP-ADDRESS> netmask <NETMASK>
2: # or
3: ip addr add <IP-ADDRESS/CIDR> dev <INTERFACE>

Example

1: ifconfig eth0 192.168.1.11 netmask 255.255.255.0
2: # or
3: ip addr add 192.168.1.11/24 dev eth0

Add gateway/route

Syntax

1: route add default gw <GATEWAY-IP> <INTERFACE>
2: # or
3: ip route add default via <GATEWAY-IP> dev <INTERFACE>

Example

1: route add default gw 192.168.1.1 eth0
2: # or
3: ip route add default via 192.168.1.1 dev eth0

Temporary spoof MAC address

Syntax

1: ip link set down dev DEVICE_NAME
2: ip link set dev DEVICE_NAME address AA:BB:CC:DD:EE:FF
3: ip link set up dev DEVICE_NAME

Example

1: ip link set down dev enp0s21
2: ip link set dev enp0s21 address AA:BB:CC:DD:EE:FF
3: ip link set up dev enp0s21

Set DNS address

Optionally DNS can be entered in the file /etc/resolv.conf in following format

1: # /etc/resolv.conf
2: nameserver 8.8.8.8
3: nameserver 8.8.4.4

All the above changes will be temporary(unless you reboot the system)

Additional scenario

  • You want 10.10.10.x address space to bypass default gateway of the network. You can reach network range of 10.10.10.0/24 via 192.168.1.11 on device eth0

    ip route add 10.10.10.0/24 via 192.168.1.11 dev eth0
    
  • Make routes persistent(on Fedora/RHEL)

    Add following entry into the file /etc/sysconfig/network-scripts/route-DEVICE_NAME

    10.10.10.0/24 via 192.168.1.11 dev DEVICE_NAME
    

CLI to control NetworkManager

Check overall status

nmcli general status

Show all connections

nmcli connection

Show details for specific connection

Syntax

nmcli connection show <GENERAL.NAME>

Example

nmcli connection show my-dsl-conn

Connect using connection name

Syntax

nmcli connection up <GENERAL.NAME>

Example

nmcli connection up my-dsl-conn