Linux IP Command

Overview

The ip command is used to assign an address to a network interface. It can be use to and/or configure network interface parameters on a Linux operating systems.

Syntax

ip OBJECT COMMAND
ip [options] OBJECT COMMAND
ip OBJECT help

Understanding ip command OBJECTS syntax

OBJECTS can be any one of the following and may be written in full or abbreviated form:

Object Abbreviated form Purpose
link l Network device.
address a
addr
Protocol (IP or IPv6) address on a device.
addrlabel addrl Label configuration for protocol address selection.
neighbour n
neigh
ARP or NDISC cache entry.
route r Routing table entry.
rule ru Rule in routing policy database.
maddress m
maddr
Multicast address.
mroute mr Multicast routing cache entry.
tunnel t Tunnel over IP.
xfrm x Framework for IPsec protocol.

To get information about each object use help command as follows:

ip OBJECT help
ip OBJECT h
ip a help
ip r help

ip Command Examples

Displays info about all network interfaces

burnz@server1:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    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 pfifo_fast state UP group default qlen 1000
    link/ether fa:16:3e:d5:f4:91 brd ff:ff:ff:ff:ff:ff
    inet 10.10.10.195/24 brd 10.10.10.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fed5:f491/64 scope link
       valid_lft forever preferred_lft forever

You can select between IPv4 and IPv6 using the following syntax:

burnz@server1:~$ ip -4 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 10.10.10.195/24 brd 10.10.10.255 scope global eth0
       valid_lft forever preferred_lft forever
 
 
 
 
burnz@server1:~$ ip -6 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
    inet6 fe80::f816:3eff:fed5:f491/64 scope link
       valid_lft forever preferred_lft forever

Assigns the IP address to the interface

The syntax is as follows to add an IPv4/IPv6 address:

ip a add {ip_addr/mask} dev {interface}

To assign 192.168.1.200/255.255.255.0 to eth0, enter:

ip a add 192.168.1.200/255.255.255.0 dev eth0

OR

ip a add 192.168.1.200/24 dev eth0

 

Remove / Delete the IP Address from the interface

The syntax is as follows to remove an IPv4/IPv6 address:

ip a del {ipv6_addr_OR_ipv4_addr} dev {interface}

To delete 192.168.1.200/24 from eth0, enter:

ip a del 192.168.1.200/24 dev eth0

Display neighbor/arp cache

The syntax is:

ip n show
ip neigh show

Sample outputs (note: I masked out some data with alphabets):

bernardbarbosa@p1hkdcla01:~$ ip neigh show
10.10.10.161 dev eth0  FAILED
10.10.10.160 dev eth0 lladdr fa:16:3e:bf:87:80 STALE
10.10.10.162 dev eth0 lladdr fa:16:3e:91:fa:a6 STALE
10.10.10.163 dev eth0 lladdr fa:16:3e:9c:17:ec STALE
10.10.10.165 dev eth0 lladdr fa:16:3e:ec:1c:8f STALE
10.10.10.164 dev eth0 lladdr fa:16:3e:34:89:3b STALE
10.10.10.166 dev eth0 lladdr fa:16:3e:02:6a:86 STALE
10.10.10.167 dev eth0 lladdr fa:16:3e:92:e6:f3 STALE
10.10.10.168 dev eth0 lladdr fa:16:3e:e0:f4:7d STALE
10.10.10.169 dev eth0 lladdr fa:16:3e:ca:65:67 STALE
10.10.10.171 dev eth0  FAILED
10.10.10.170 dev eth0 lladdr fa:16:3e:81:37:01 STALE
10.10.10.173 dev eth0 lladdr fa:16:3e:2c:ae:eb STALE
10.10.10.172 dev eth0 lladdr fa:16:3e:45:a7:cf STALE
10.10.10.177 dev eth0 lladdr fa:16:3e:3f:8d:d3 STALE
10.10.10.179 dev eth0 lladdr fa:16:3e:f5:6b:36 STALE
10.10.10.178 dev eth0 lladdr fa:16:3e:75:4b:80 STALE
10.10.10.181 dev eth0 lladdr fa:16:3e:98:0a:db STALE
10.10.10.180 dev eth0 lladdr fa:16:3e:79:eb:0f STALE
10.10.10.182 dev eth0 lladdr fa:16:3e:eb:c4:da STALE
10.10.10.183 dev eth0 lladdr fa:16:3e:0b:a8:27 STALE
10.10.10.184 dev eth0 lladdr fa:16:3e:d8:21:a2 STALE
10.10.10.185 dev eth0 lladdr fa:16:3e:49:8f:3f STALE
10.10.10.187 dev eth0 lladdr fa:16:3e:70:fb:08 STALE
10.10.10.186 dev eth0 lladdr fa:16:3e:2b:42:fa STALE
10.10.10.188 dev eth0 lladdr fa:16:3e:b0:8d:ca STALE
10.10.10.189 dev eth0 lladdr fa:16:3e:09:53:2c STALE
10.10.10.191 dev eth0 lladdr fa:16:3e:bc:ab:65 STALE
10.10.10.190 dev eth0 lladdr fa:16:3e:4a:84:83 STALE
10.10.10.192 dev eth0 lladdr fa:16:3e:71:6e:c0 STALE
10.10.10.193 dev eth0 lladdr fa:16:3e:df:85:4d STALE
10.10.10.194 dev eth0 lladdr fa:16:3e:aa:27:8a STALE
10.10.10.196 dev eth0 lladdr fa:16:3e:c4:a6:10 STALE
10.10.10.197 dev eth0 lladdr fa:16:3e:12:cb:e1 STALE
10.10.10.198 dev eth0 lladdr fa:16:3e:2b:c8:39 STALE
10.10.10.199 dev eth0 lladdr fa:16:3e:01:cb:34 STALE
10.10.10.200 dev eth0 lladdr fa:16:3e:1d:eb:06 STALE
10.10.10.252 dev eth0 lladdr cc:ef:48:0e:50:43 STALE
10.10.10.253 dev eth0 lladdr cc:ef:48:02:a9:42 STALE
10.10.10.254 dev eth0 lladdr 00:00:0c:07:ac:0a REACHABLE
10.10.10.1 dev eth0  FAILED
10.10.10.20 dev eth0 lladdr d4:be:d9:b7:18:f1 STALE
10.10.10.21 dev eth0 lladdr d4:be:d9:ed:10:07 STALE
10.10.10.22 dev eth0  FAILED
10.10.10.26 dev eth0 lladdr 00:50:56:b4:09:65 STALE
10.10.10.27 dev eth0 lladdr fa:16:3e:7a:60:03 STALE
10.10.10.29 dev eth0 lladdr 00:50:56:b4:09:90 STALE
10.10.10.31 dev eth0 lladdr 00:50:56:b4:09:93 STALE
10.10.10.30 dev eth0 lladdr 00:50:56:b4:09:93 STALE
10.10.10.32 dev eth0 lladdr fa:16:3e:21:c2:1b STALE
10.10.10.33 dev eth0  FAILED
10.10.10.34 dev eth0  FAILED
10.10.10.35 dev eth0 lladdr 00:50:56:b4:09:9d STALE
10.10.10.36 dev eth0  FAILED
10.10.10.37 dev eth0 lladdr 00:50:56:b4:09:ab STALE
10.10.10.38 dev eth0 lladdr 00:50:56:b4:09:a9 STALE
10.10.10.39 dev eth0 lladdr 00:50:56:b4:09:ac STALE
10.10.10.41 dev eth0 lladdr 00:50:56:b4:09:b1 STALE
10.10.10.40 dev eth0 lladdr 00:50:56:b4:09:ae STALE
10.10.10.42 dev eth0 lladdr 00:50:56:b4:09:ad STALE
10.10.10.44 dev eth0 lladdr 00:50:56:b4:56:b9 STALE
10.10.10.45 dev eth0 lladdr 00:50:56:b5:1b:82 STALE
10.10.10.46 dev eth0  FAILED
10.10.10.48 dev eth0 lladdr 00:50:56:b4:09:b8 STALE
10.10.10.56 dev eth0 lladdr 00:50:56:b4:70:48 STALE
10.10.10.59 dev eth0 lladdr 00:50:56:b4:70:44 STALE
10.10.10.60 dev eth0 lladdr 00:50:56:b4:70:4c STALE
10.10.10.64 dev eth0  FAILED
10.10.10.66 dev eth0 lladdr fa:16:3e:bc:ab:65 STALE
10.10.10.67 dev eth0 lladdr fa:16:3e:bc:ab:65 STALE
10.10.10.68 dev eth0 lladdr 00:50:56:b4:41:72 STALE

The last field show the the state of the “neighbor unreachability detection” machine for this entry:

  1. STALE – The neighbor is valid, but is probably already unreachable, so the kernel will try to check it at the first transmission.
  2. DELAY – A packet has been sent to the stale neighbor and the kernel is waiting for confirmation.
  3. REACHABLE – The neighbor is valid and apparently reachable.

 

Add a new route

The syntax is:

ip route add {NETWORK/MASK} via {GATEWAYIP}
ip route add {NETWORK/MASK} dev {DEVICE}
ip route add default {NETWORK/MASK} dev {DEVICE}
ip route add default {NETWORK/MASK} via {GATEWAYIP}

Add a plain route to network 192.168.1.0/24 via gateway 192.168.1.254:

ip route add 192.168.1.0/24 via 192.168.1.254

To route all traffic via 192.168.1.254 gateway connected via eth0 network interface:

ip route add 192.168.1.0/24 dev eth0

Delete a route

The syntax is as follows to delete default gateway:

ip route del default

In this example, delete the route created 

ip route del 192.168.1.0/24 dev eth0

Old vs. New tool

Deprecated Linux command and their replacement cheat sheet:

ifconfig -a ip a
ifconfig enp6s0 down ip link set enp6s0 down
ifconfig enp6s0 up ip link set enp6s0 up
ifconfig enp6s0 192.168.2.24 ip addr add 192.168.2.24/24 dev enp6s0
ifconfig enp6s0 netmask 255.255.255.0 ip addr add 192.168.1.1/24 dev enp6s0
ifconfig enp6s0 mtu 9000 ip link set enp6s0 mtu 9000
ifconfig enp6s0:0 192.168.2.25 ip addr add 192.168.2.25/24 dev enp6s0
netstat ss
netstat -tulpn ss -tulpn
netstat -neopa ss -neopa
netstat -g ip maddr
route ip r
route add -net 192.168.2.0 netmask 255.255.255.0 dev enp6s0 ip route add 192.168.2.0/24 dev enp6s0
route add default gw 192.168.2.254 ip route add default via 192.168.2.254
arp -a ip neigh
arp -v ip -s neigh
arp -s 192.168.2.33 1:2:3:4:5:6 ip neigh add 192.168.3.33 lladdr 1:2:3:4:5:6 dev enp6s0
arp -i enp6s0 -d 192.168.2.254 ip neigh del 192.168.2.254 dev wlp7s0
Spread the love

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.