Network configuration tool
ip command is used to display or manipulate the routing, network devices, policy routing and tunnels of the Linux host. It is a new and powerful network configuration tool under Linux.
ip(option)(object)
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename
OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
netns | l2tp | macsec | tcp_metrics | token }
-V: Display command version information;
-s: Output more detailed information;
-f: Force the use of the specified protocol family;
-4: The specified network layer protocol is IPv4 protocol;
-6: The specified network layer protocol is IPv6 protocol;
-0: Output information outputs one line for each record, even if the content is large, it will not be displayed in new lines;
-r: When displaying the host, do not use the IP address, but use the domain name of the host.
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
-h[uman-readable] | -iec |
-f[amily] { inet | inet6 | ipx | dnet | bridge | link } |
-4 | -6 | -I | -D | -B | -0 |
-l[oops] { maximum-addr-flush-attempts } |
-o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
-rc[vbuf] [size] | -n[etns] name | -a[ll] }
Network object: Specify the network object to be managed;
Specific operations: Complete specific operations on the specified network object;
help: Displays help information for the operation commands supported by the network object.
ip link show # Display network interface information
ip link set eth0 up # Turn on the network card
ip link set eth0 down # Turn off the network card
ip link set eth0 promisc on # Turn on the mixed mode of the network card
ip link set eth0 promisc offi # Turn off the mixed mode of the network card
ip link set eth0 txqueuelen 1200 # Set the network card queue length
ip link set eth0 mtu 1400 # Set the maximum transmission unit of the network card
ip addr show # Display network card IP information
ip addr add 192.168.0.1/24 dev eth0 # Add a new IP address 192.168.0.1 to the eth0 network card
ip addr del 192.168.0.1/24 dev eth0 # Delete an IP address 192.168.0.1 for the eth0 network card
ip route show # Display system routing
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 of the 192.168.4.0 network segment to 192.168.0.254, and the data goes 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 of the 192.168.4.0 network segment
ip route del default # Delete the default route
ip route delete 192.168.1.0/24 dev eth0 # Delete route
Use the ip command to display the operating status of network devices
[root@localhost ~]# ip link list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
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 qlen 1000
link/ether 00:16:3e:00:1e:51 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:16:3e:00:1e:52 brd ff:ff:ff:ff:ff:ff
Show more detailed device information
[root@localhost ~]# ip -s link list
1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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
Show core 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
Show 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
Get all network interfaces of the host
ip link | grep -E '^[0-9]' | awk -F: '{print $2}'