Home >Operation and Maintenance >Linux Operation and Maintenance >Detailed explanation of the usage of IP command
The ip command is a new and powerful network configuration tool under Linux.
1 Function
The ip command is used to display or manipulate the routing, network devices, policy routing and tunnels of the Linux host.
2 Usage
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] - batch filename
-force: Do not terminate on error in batch mode
-b:-batch filenam, read commands from the supplied file or standard input and call them, first time Failure will result in IP termination
3 Parameters and Options
OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
tunnel | tuntap | maddress | mroute | mrule | monitor | { -V[ersion] | -h[uman-readable] | -s[tatistics] | -d[etails] |
-r[esolve] | -iec | -f[amily] { inet | inet6 | ipx | dnet | link }
| -4 | -6 | -I | -D | -B | -0 | -l[oops] { maximum-addr-flush-
attempts } | -o[neline] | -rc[vbuf] [size] | -t[imestamp] |
-ts[hort] | -n[etns] name | -a[ll] }
(1) OPTIONSare some options to modify the IP behavior or change its output. All options start with the - character and are divided into long and short One form:
-V: -Version prints the version of the ip and exits -h: Human readable output
-s: -stats –statistics, output more information, if this option appears twice or more, the output information will be more detailed
d: Output more detailed information
-l: Specify the "IP address refresh" logic to The maximum number of cycles to try, the default is 10 ,
inet6
、
bridge, ipx, dnet or link
-4: It is the abbreviation of -family inet -6: It is the abbreviation of -family inet6 -0: It is the abbreviation of-family link -I: It is the abbreviation of-family ipx -o: -oneline single line output, replace line breaks with "\"
characters
-n
:-netns#IP of the switch to the specified network spacenetns
## -r:-resolve Use system name resolution to print DNS names instead of host addresses -t:Use monitor options Display the current time -a:-all
Execute the specified command on all objects command, depending on whether the command supports this option-rc
:-rcvbuf (size) SettingsNetlinkSocket receive buffer size setting, the default is 1MB
(2) OBJECT
is the object you want to manage or obtain information
OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
tunnel | tuntap | maddress | mroute | mrule | monitor |
link Network device address The protocol (IP or IPV6) address of a device neighbor ARP or NDISC buffer entry route Routing table entry rule Rules in routing policy database maddress Multicast address mroute Multicast routing buffer entry monitor Monitor network messages mrule group Rules in the broadcast routing policy database Tunnel Tunnel over IP l2tp Tunnel Ethernet (L2TPV3)Note: All object names can be abbreviated, for example: address It can be abbreviated as addr, or even a. 4 Modify IP address(1) Add IP address
Format: ip addr add ADDRESS/MASK dev DEVICEroot@centos7 ~]# ip addr add 192.1.1.1/24 dev ens33
(2) Delete IP address
[root@centos7 ~]# ip addr del 192.1.1.1/24 dev ens345 View network information
[root@ centos7 ~]# ip address show[……]
2: ens33:inet 192.1.1.1/24 scope global ens34valid_lft forever preferred_lft foreverinet6 fe80::20c:29ff:fe3a:8c/64 scope link tentative valid_lft forever preferred_lft forever
##6 Adding and deleting routing tables
(1) Add routing table Format: ip rouite add TARGET via GW
TARGET is the target network or host, GW is the gateway or start. [root@centos7 ~]# ip route add 172.16.0.0/16 via 192.168.29.1
(2) Delete routing table[ root@centos7 ~]# ip route del 172.16.0.0/16
(3) Display routing table
Format: ip route show|list
[root@centos7 ~]# ip route listdefault via 192.168.29.1 dev ens33 proto static metric 100
172.16.0.0/16 via 192.168.29.1 dev ens33
192.168.29.0/24 dev ens33 proto kernel scope link src 192.168.29.3 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
[root@centos7 ~ ]# ip route show
default via 192.168.29.1 dev ens33 proto static metric 100
172.16.0.0/16 via 192.168.29.1 dev ens33
192.168.29.0/24 dev ens33 proto kernel scope link src 192.168.29.3 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
(4) Clear routing tableFormat: ip route flush [dev IFACE] [via PREFIX]
[root@centos7 ~]# ip route flush dev ens33
(5) Add gatewayFormat: ip route add default via GW dev IFACE
[root@centos7 ~]# ip route add default via 192.168.29.1
7 Example
(1) Display the running status of the network device[root@centos7 ~]# ip link list
1: lo:
2: ens33:
link/ether 00: 0c:29:3a:00:82 brd ff:ff:ff:ff:ff:ff
(2) Display neighbor table[root@centos7 ~ ]# ip neigh list
192.168.29.1 dev ens33 lladdr 00:50:56:c0:00:01 REACHABLE
(3) View network card information
[root@centos7 ~ ]# ip -s link list ens33
2: ens33:
link/ether 00:0c :29:3a:00:82 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
704554 4943 0 0 0 0
TX: bytes packets errors dropped carrier colsns
470814 3110 0 0 0 0
(4) Change the maximum transmission queue length
[root @centos7 ~]# ip link set dev ens33 txqueuelen 1500
(5) Set MTU
[root@centos7 ~]# ip link set ens33 mtu 1400
Show whether the above settings are effective
[root@centos7 ~]# ip link show ens33
2: ens33:
link/ether 00:0c:29:3a:00:82 brd ff:ff:ff:ff:ff:ff
You can see mtu and qlen All have taken effect
(6) Shut down the network device
[root@centos7 ~]# ip link set ens38 down
[root@centos7 ~ ]# ip link show ens38
4: ens38:
link/ether 00:0c:29:3a:00 :96 brd ff:ff:ff:ff:ff:ff
[root@centos7 ~]
# (7) Turn on the network device
[root@centos7 ~]# ip link set ens38 up
[root@centos7 ~]# ip link show ens38
4: ens38:
link/ether 00:0c:29:3a:00:96 brd ff:ff:ff:ff:ff:ff
The above is the detailed content of Detailed explanation of the usage of IP command. For more information, please follow other related articles on the PHP Chinese website!