IP COMMAND FROM IPROUTE2

IP COMMAND FROM IPROUTE2
ip command in Linux is used to show / manipulate routing, devices, policy routing and tunnels. It is a provided by iproute2 package. ifconfig command which is provided by net-tools package has been around since long and will stay around. ip is more powerful and modern and will eventually replace it. This blog shows some example and powerful use of ip command

IP QUERIES#

DISPLAY IP ADDRESSES AND PROPERTY INFORMATION

Show information for all addresses

root@bcf62d10644f:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.3/16 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:acff:fe11:3/64 scope link 
       valid_lft forever preferred_lft forever

Display information only for device eth0

root@bcf62d10644f:~# ip addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.3/16 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:acff:fe11:3/64 scope link 
       valid_lft forever preferred_lft forever

MANAGE AND DISPLAY THE STATE OF ALL NETWORK INTERFACES

Show information for all interfaces

root@bcf62d10644f:~# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    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 noqueue state UP mode DEFAULT group default 
    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff

Display information only for device eth0

root@bcf62d10644f:~# ip link show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff

Display interface statistics

root@bcf62d10644f:~# ip -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    RX: bytes  packets  errors  dropped overrun mcast   
    0          0        0       0       0       0      
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       0       0       0      
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast   
    648        8        0       0       0       0      
    TX: bytes  packets  errors  dropped carrier collsns 
    648        8        0       0       0       0

DISPLAY AND ALTER THE ROUTING TABLE

List all of the route entries in the kernel

root@bcf62d10644f:~# ip route
default via 172.17.0.1 dev eth0 
172.17.0.0/16 dev eth0  proto kernel  scope link  src 172.17.0.3

MANAGE AND DISPLAY MULTICAST IP ADDRESSES####

Display multicast information for all devices

root@bcf62d10644f:~# ip maddr
1:	lo
	inet  224.0.0.1
	inet6 ff02::1
	inet6 ff01::1
2:	eth0
	link  33:33:00:00:00:01
	link  01:00:5e:00:00:01
	link  33:33:ff:11:00:03
	inet  224.0.0.1
	inet6 ff02::1:ff11:3
	inet6 ff02::1
	inet6 ff01::1

Display multicast information for device eth0

ip maddr show dev eth0

SHOW NEIGHBOUR OBJECTS; ALSO KNOWN AS THE ARP TABLE FOR IPV4####

Display neighbour objects

ip neigh

Show the ARP cache for device em1

ip neigh show dev em1

MODIFYING ADDRESS AND LINK PROPERTIES#

ADD AN ADDRESS####

Add address 192.168.1.1 with netmask 24 to device em1

ip addr add 192.168.1.1/24 dev em1

DELETE AN ADDRESS####

Remove address 192.168.1.1/24 from device em1

ip addr del 192.168.1.1/24 dev em1

ALTER THE STATUS OF THE INTERFACE####

Bring em1 online

ip link set em1 up

Bring em1 of offline

ip link set em1 down

Set the MTU on em1 to 9000

ip link set em1 mtu 9000

Enable promiscuous mode for em1

ip link set em1 promisc on

ADJUSTING AND VIEWING ROUTES#

ADD AN ENTRY TO THE ROUTING TABLE####

Add a default route (for all addresses) via the local gateway 192.168.1.1 that can be reached on device em1

ip route add default via 192.168.1.1 dev em1

Add a route to 192.168.1.0/24 via the gateway at 192.168.1.1

ip route add 192.168.1.0/24 via 192.168.1.1

Add a route to 192.168.1.0/24 that can be reached on device em1

ip route add 192.168.1.0/24 dev em1

DELETE A ROUTING TABLE ENTRY####

Delete the route for 192.168.1.0/24 via the gateway at 192.168.1.1

ip route delete 192.168.1.0/24 via 192.168.1.1

REPLACE, OR ADD IF NOT DEFINED, A ROUTE####

Replace the defined route for 192.168.1.0/24 to use device em1

ip route replace 192.168.1.0/24 dev em1

DISPLAY THE ROUTE AN ADDRESS WILL TAKE####

Display the route taken for IP 192.168.1.5

ip route get 192.168.1.5

MANAGING THE ARP TABLE#

ADD AN ENTRY TO THE ARP TABLE####

Add address 192.168.1.1 with MAC 1:2:3:4:5:6 to em1

ip neigh add 192.168.1.1 lladdr 1:2:3:4:5:6 dev em1

INVALIDATE AN ENTRY####

Invalidate the entry for 192.168.1.1 on em1

ip neigh del 192.168.1.1 dev em1

REPLACE, OR ADDS IF NOT DEFINED, AN ENTRY TO THE ARP TABLE####

Replace the entry for address 192.168.1.1 to use MAC 1:2:3:4:5:6 on em1

ip neigh replace 192.168.1.1 lladdr 1:2:3:4:5:6 dev em1

Like it? Click here to Tweet your feedback