Linux ip command
The ip command from the iproute2 tool collection is used under Linux to configure network addresses. It replaces the ifconfig command from the obsolete net-tools. This article shows the most important parameters of the ip command using a few examples.
Comparison table ip versus ifconfig
The table shows important commands for network configuration and compares the syntax of the ip and ifconfig commands:
Purpose | iproute2 command | iproute2 command (short version) | net-tools command |
---|---|---|---|
Show link status | ip link show
|
ip l
|
ifconfig
|
Show link status including statistics (RX/TX bytes, errors, ...) |
ip -statistics link show
|
ip -s l
|
ifconfig
|
Show IP address | ip addr show
|
ip a
|
ifconfig -a
|
Set IP address | ip addr add IP/NETMASK dev DEVICE
|
ip a a IP/NETMASK dev DEVICE
|
ifconfig DEVICE IP/NETMASK
|
Delete IP address | ip addr del IP/NETMASK dev DEVICE
|
ip a d IP/NETMASK dev DEVICE
|
|
Delete all IP addresses of a device | ip addr flush dev DEVICE
|
ip a f dev DEVICE
|
|
Show routing table | ip route show
|
ip r
|
route -n
|
Set standard gateway | ip route add default via IP
|
ip r a default via IP
|
route add default gw IP DEVICE
|
Show ARP cache | ip neigh show
|
ip n
|
arp -na
|
Show connections | ss --tcp --all --processes --extended --numeric
|
ss -tapen
|
netstat -tapen
|
Examples
The following outputs show some examples of iproute2 commands.
ip help
$ ip help Usage: ip [ OPTIONS ] OBJECT { COMMAND | help } ip [ -force ] -batch filename where OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable | tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm | netns } OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] | -f[amily] { inet | inet6 | ipx | dnet | link } | -l[oops] { maximum-addr-flush-attempts } | -o[neline] | -t[imestamp] | -b[atch] [filename] | -rc[vbuf] [size]}
ip link show
$ ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 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 qlen 1000 link/ether 08:00:27:66:72:e1 brd ff:ff:ff:ff:ff:ff
ip -statistics link show
$ ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 RX: bytes packets errors dropped overrun mcast 2073916 4895 0 0 0 0 TX: bytes packets errors dropped carrier collsns 2073916 4895 0 0 0 0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:66:72:e1 brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped overrun mcast 1716782262 1369751 0 0 0 0 TX: bytes packets errors dropped carrier collsns 308636400 1172428 0 0 0 0
ip addr show
$ ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 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 qlen 1000 link/ether 08:00:27:66:72:e1 brd ff:ff:ff:ff:ff:ff inet 10.1.102.59/24 brd 10.1.102.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe66:72e1/64 scope link valid_lft forever preferred_lft forever
ip addr add IP/NETMASK dev DEVICE
$ sudo ip addr add 10.1.102.60/24 dev eth0 $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 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 qlen 1000 link/ether 08:00:27:66:72:e1 brd ff:ff:ff:ff:ff:ff inet 10.1.102.59/24 brd 10.1.102.255 scope global eth0 valid_lft forever preferred_lft forever inet 10.1.102.60/24 scope global secondary eth0 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe66:72e1/64 scope link valid_lft forever preferred_lft forever
ip addr del IP/NETMASK dev DEVICE
$ sudo ip addr del 10.1.102.60/24 dev eth0 $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 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 qlen 1000 link/ether 08:00:27:15:17:5e brd ff:ff:ff:ff:ff:ff inet 10.1.102.54/24 brd 10.1.102.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe15:175e/64 scope link valid_lft forever preferred_lft forever
ip addr flush dev DEVICE
$ sudo ip addr flush dev eth0 $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 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 qlen 1000 link/ether 08:00:27:15:17:5e brd ff:ff:ff:ff:ff:ff
ip route show
$ ip route show default via 10.1.102.1 dev eth0 metric 100 10.1.102.0/24 dev eth0 proto kernel scope link src 10.1.102.59
ip route add default via IP
$ sudo ip route add d via 10.1.102.1
ip neigh show
$ ip neigh show 10.1.102.101 dev eth0 lladdr f0:de:f1:f3:17:88 REACHABLE 10.1.102.1 dev eth0 lladdr 00:0c:42:97:79:63 REACHABLE
Further information
- Start Practising Linux ip command and Avoid the Habit of Using ifconfig (linoxide.com, 02.05.2014)
Author: Werner Fischer Werner Fischer, working in the Knowledge Transfer team at Thomas-Krenn, completed his studies of Computer and Media Security at FH Hagenberg in Austria. He is a regular speaker at many conferences like LinuxTag, OSMC, OSDC, LinuxCon, and author for various IT magazines. In his spare time he enjoys playing the piano and training for a good result at the annual Linz marathon relay.
|