ip

Useful basic commands

  1. View all network interfaces

$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
...

# eg. show specific network interface
$ ip link show test0
4: test0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether 32:25:da:4e:93:fa brd ff:ff:ff:ff:ff:ff
...
  1. Add a new network interface

$ ip link add [iface_name] type [iface_type]

# eg. add a dummy interface with name test0
$ ip link add test0 type dummy
  1. Configure IP address on the interface

  1. Set the network interface up/down

Example 1: Create a dummy interface

Create a dummy interface test0 with IP address value of 192.168.1.222

Example 2: Reset configurations on interface

Example 3: Replace default route

Suppose we have an interface eth0 with a lower metric (preferred) over another interface eth1

  • Now, all traffic not destined for 192.168.0.0 (eth1 specific address) will exit via eth0, with the default gateway of 192.168.1.1

  • We can run a few commands to make eth1 the preferred route, to force all traffic to exit via the gateway address 192.168.0.1 instead

Note that all traffic destined for 192.168.1.0 will still exit via the eth0 interface

Last updated