ip link 可以设定与设备(device)有关的相关设定,包括MTU以及该网络设备的MAC等,当然也可以启动(up)或关闭(down)某个网络设备。
1 2 3 4 5 6 7 8 9
% sudo ip link 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: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 4c:d9:8f:27:e7:d4 brd ff:ff:ff:ff:ff:ff 3: em2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 20:04:0f:e6:45:9b brd ff:ff:ff:ff:ff:ff 4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN link/ether 72:df:05:18:76:51 brd ff:ff:ff:ff:ff:ff
使用ip link show可以显示出整个设备的硬件相关信息,如上所示,包括MAC地址、MTU等。lo是主机内部自行设定的,如果加上-s的参数后,则这个网卡的相关统计信息就会被列出来,包括接收(RX)及传送(TX)的封包数量等,详细的内容与ifconfig所输出的结果相同。
ip address
如果说ip link是与OSI七层模型的第二层数据链路层有关的话,那么ip address/addr就是与第三层网络层有关的了。主要是在设定与 IP 有关的各项参数,包括 netmask, broadcast 等。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
% sudo ip addr 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 inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 4c:d9:8f:27:e7:d4 brd ff:ff:ff:ff:ff:ff inet 172.16.10.88/24 brd 172.16.10.255 scope global em1 inet6 fe80::4ed9:8fff:fe27:e7d4/64 scope link valid_lft forever preferred_lft forever 3: em2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 20:04:0f:e6:45:9b brd ff:ff:ff:ff:ff:ff 4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN link/ether 72:df:05:18:76:51 brd ff:ff:ff:ff:ff:ff inet 172.17.42.1/16 scope global docker0 inet6 fe80::70df:5ff:fe18:7651/64 scope link valid_lft forever preferred_lft forever
% sudo ip route 172.16.10.0/24 dev em1 proto kernel scope link src 172.16.10.88 metric 1 172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.42.1 default via 172.16.10.1 dev em1 proto static
% sudo ip route add 192.168.12.0/24 dev eth1 #添加路由 % sudo ip route add 192.168.10.0/24 via 192.168.12.1 dev eth0 #添加通往外部路由 % sudo ip route del 192.168.10.0/24 dev eth0 #删除路由