Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux ip command

Linux ip command

Linux Command Reference Linux Command Reference

The Linux ip command is similar to the ifconfig command, but more powerful than ifconfig; its main function is to display or configure network devices.

The ip command is an enhanced network configuration tool for Linux, used to replace the ifconfig command.

Syntax



ip [ OPTIONS ] OBJECT { COMMAND | help }

OBJECT denotes common objects; its values can be the following:

 

OBJECT={ link | addr | addrlabel | route | rule | neigh | ntable | tunnel | maddr | mroute | mrule | monitor | xfrm | token }

The meanings of the common object values are as follows:

OPTIONS denotes common options; its values can be the following:

OPTIONS={ -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] | -h[uman-readable] | -iec | -f[amily] { inet | inet6 | ipx | dnet | link } | -o[neline] | -t[imestamp] | -b[atch] [filename] | -rc[vbuf] [size] }

The meanings of the common option values are as follows:

ip link show # show network interface information ip link set eth0 up # enable the network card ip link set eth0 down # disable the network card ip link set eth0 promisc on # enable promiscuous mode on the network card ip link set eth0 promisc offi # disable promiscuous mode on the network card ip link set eth0 txqueuelen 1200 # set the network card queue length ip link set eth0 mtu 1400 # set the network card maximum transmission unit ip addr show # show network card IP information ip addr add 192.168.0.1/24 dev eth0 # set eth0's IP address to 192.168.0.1 ip addr del 192.168.0.1/24 dev eth0 # delete eth0's IP address 192.168.0.1

ip route show # show system routes ip route add default via 192.168.1.254 # set the system default route ip route list # view routing information ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # set the gateway for network 192.168.4.0 to 192.168.0.254, with traffic going through the eth0 interface ip route add default via 192.168.0.254 dev eth0 # set the default gateway to 192.168.0.254 ip route del 192.168.4.0/24 # delete the gateway for network 192.168.4.0 ip route del default # delete the default route ip route delete 192.168.1.0/24 dev eth0 # delete a route

Use the ip command to display the running status of network devices:

[root@localhost ~]# ip link list

1: lo:  mtu 16436 qdisc noqueue

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: eth0:  mtu 1500 qdisc pfifo_fast qlen 1000

link/ether 00:16:3e:00:1e:51 brd ff:ff:ff:ff:ff:ff

3: eth1:  mtu 1500 qdisc pfifo_fast qlen 1000

link/ether 00:16:3e:00:1e:52 brd ff:ff:ff:ff:ff:ff

Display more detailed device information:

[root@localhost ~]# ip -s link list

1: lo:  mtu 16436 qdisc noqueue

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

RX: bytes  packets  errors  dropped overrun mcast
5082831 56145 0 0 0 0
TX: bytes packets errors dropped carrier collsns 5082831 56145 0 0 0 0
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:16:3e:00:1e:51 brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped overrun mcast
3641655380 62027099 0 0 0 0
TX: bytes packets errors dropped carrier collsns 6155236 89160 0 0 0 0
3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:16:3e:00:1e:52 brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped overrun mcast
2562136822 488237847 0 0 0 0
TX: bytes packets errors dropped carrier collsns 3486617396 9691081 0 0 0 0

Display the main routing table:

[root@localhost ~]# ip route list

112.124.12.0/22 dev eth1  proto kernel  scope link  src 112.124.15.130

10.160.0.0/20 dev eth0  proto kernel  scope link  src 10.160.7.81

192.168.0.0/16 via 10.160.15.247 dev eth0

172.16.0.0/12 via 10.160.15.247 dev eth0

10.0.0.0/8 via 10.160.15.247 dev eth0

default via 112.124.15.247 dev eth1

Display the neighbor table:

[root@localhost ~]# ip neigh list

112.124.15.247 dev eth1 lladdr 00:00:0c:9f:f3:88 REACHABLE

10.160.15.247 dev eth0 lladdr 00:00:0c:9f:f2:c0 STALE

Obtain all network interfaces of the host:

ip link | grep -E '^[0-9]' | awk -F: '{print $2}'

Linux Command Reference Linux Command Reference