(2)关闭和激活网络设备
[root@Mr_chen ~]# ip link show eth1 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 00:0c:29:a8:ca:5a brd ff:ff:ff:ff:ff:ff [root@Mr_chen ~]# ip link set eth1 up #激活eth1网卡 [root@Mr_chen ~]# ip link show dev eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a8:ca:5a brd ff:ff:ff:ff:ff:ff [root@Mr_chen ~]# ip link set eth1 down #关闭eth1网卡 [root@Mr_chen ~]# ip link show eth1 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether 00:0c:29:a8:ca:5a brd ff:ff:ff:ff:ff:ff(3)修改网卡MAC地址
[root@Mr_chen ~]# ip link show eth1 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether 00:0c:29:a8:ca:5a brd ff:ff:ff:ff:ff:ff [root@Mr_chen ~]# ip link set eth1 address 0:0c:29:a8:ca:5f #修改MAC地址 [root@Mr_chen ~]# ip link show eth1 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether 00:0c:29:a8:ca:5f brd ff:ff:ff:ff:ff:ff(4)查看网卡信息
[root@Mr_chen ~]# ip a #效果与ip address一样,显示的结果包括激活和未激活的网卡 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a8:ca:50 brd ff:ff:ff:ff:ff:ff inet 192.168.0.100/24 brd 192.168.0.255 scope global eth0 inet6 fe80::20c:29ff:fea8:ca50/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether 00:0c:29:a8:ca:5f brd ff:ff:ff:ff:ff:ff [root@Mr_chen ~]# ip link #和ip a对比,少了具体的IP地址信息 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 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 state UP qlen 1000 link/ether 00:0c:29:a8:ca:50 brd ff:ff:ff:ff:ff:ff 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether 00:0c:29:a8:ca:5f brd ff:ff:ff:ff:ff:ff(5)添加或删除IP地址
root@Mr_chen ~]# ip a show eth1 #显示eth1的IP地址,没有配置 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether 00:0c:29:a8:ca:5f brd ff:ff:ff:ff:ff:ff [root@Mr_chen ~]# ip a add 192.168.0.222/24 dev eth1 #添加一个IP地址 [root@Mr_chen ~]# ip a show eth1 #虽然显示出了IP地址,但是网卡状态还是down 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000 link/ether 00:0c:29:a8:ca:5f brd ff:ff:ff:ff:ff:ff inet 192.168.0.222/24 scope global eth1 [root@Mr_chen ~]# ip link set eth1 up #激活网卡 [root@Mr_chen ~]# ip a show eth1 #现在eth1网卡正常运行 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a8:ca:5f brd ff:ff:ff:ff:ff:ff inet 192.168.0.222/24 scope global eth1 inet6 fe80::20c:29ff:fea8:ca5f/64 scope link valid_lft forever preferred_lft forever [root@Mr_chen ~]# ip a add 192.168.0.223/24 dev eth1 #可添加多个IP,这种IP称为辅助IP [root@Mr_chen ~]# ip a show eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a8:ca:5f brd ff:ff:ff:ff:ff:ff inet 192.168.0.222/24 scope global eth1 inet 192.168.0.223/24 scope global secondary eth1 inet6 fe80::20c:29ff:fea8:ca5f/64 scope link valid_lft forever preferred_lft forever [root@Mr_chen ~]# ip a del 192.168.0.222/24 dev eth1 #删除主IP也就是第一个IP地址 [root@Mr_chen ~]# ip a show eth1 #所有IP都没有了 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a8:ca:5f brd ff:ff:ff:ff:ff:ff inet6 fe80::20c:29ff:fea8:ca5f/64 scope link valid_lft forever preferred_lft forever [root@Mr_chen ~]# ip a add 192.168.0.222/24 dev eth1 #添加两个IP地址 [root@Mr_chen ~]# ip a add 192.168.0.223/24 dev eth1 [root@Mr_chen ~]# ip a del 192.168.0.223/24 dev eth1 #删除辅助IP [root@Mr_chen ~]# ip a show eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a8:ca:5f brd ff:ff:ff:ff:ff:ff inet 192.168.0.222/24 scope global eth1 #主IP仍旧被保留了 inet6 fe80::20c:29ff:fea8:ca5f/64 scope link valid_lft forever preferred_lft forever小结:
[x] :删除网卡的主IP地址,同时会删除该网卡的所有IP地址
[x] :删除网卡的辅助IP地址,不会影响该网卡的其他IP地址。