1、ip:show/manipulate routing, devices, policy routing and tunnels
1)说明:ifconfig命令已经废弃。其功能可通过下文介绍的ip addr、ip link和ip -s link等命令代替。
2)常用语法:ip [ OPTIONS ] OBJECT { COMMAND | help }
常用的OPTIONS:-s:打印更多信息(如统计信息RX/RX errors)。该选项可多次使用;-f:指定协议族(inet/inet6/bridge/ipx/dnet/link)。link表示不涉及任何网络协议;-r:使用系统的名字解析功能打印出DNS名字,而不是主机地址。
常用的OBJECT:address:设备上的协议(IP/IPv6)地址;link:网络设备;maddress:多播地址;route:路由表项;rule:路由规则。
常用的COMMAND:指定在OBJECT上执行的动作(如add/delete/show/list/help)。
3)示例(当OBJECT为link时):
(1)显示网络设备的信息
[[email protected] ~]# ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link/ether 00:0c:29:d5:71:cd brd ff:ff:ff:ff:ff:ff
(2)关闭一个网络设备
[[email protected] ~]# ip link set dev ens33 down # 等同于ifconfig ens33 down
(3)修改网络设备的MTU
[[email protected] ~]# ip link set dev ens33 mtu 1500
4)示例(当OBJECT为address时):
(1)显示协议地址
[[email protected] ~]# 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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:d5:71:cd brd ff:ff:ff:ff:ff:ff inet 192.168.19.129/24 brd 192.168.19.255 scope global dynamic ens33 valid_lft 1735sec preferred_lft 1735sec inet6 fe80::20c:29ff:fed5:71cd/64 scope link valid_lft forever preferred_lft forever
(2)为网络设备添加地址
[[email protected] ~]# ip address add 192.168.19.130/24 brd + label ens33:1 dev ens33 # 相当于ifconfig ens33:1 192.168.19.130/24
此时再查看ip addr show的输出:
[[email protected] ~]# ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN ... ... 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:d5:71:cd brd ff:ff:ff:ff:ff:ff inet 192.168.19.129/24 brd 192.168.19.255 scope global dynamic ens33 valid_lft 1254sec preferred_lft 1254sec inet 192.168.19.130/24 brd 192.168.19.255 scope global secondary ens33:1 valid_lft forever preferred_lft forever ... ...
(3)删除网络设备的一个地址
[[email protected] ~]# ip addr delete 192.168.19.130/24 dev ens33
不断学习中。。。
时间: 2024-10-11 16:48:51