linux修改ip( 二 )


其实,还可以通过执行 ping 192.168.1.10 命令来测试网络接口上IP是否分配成功,如果能 ping 通IP的话,表示分配成功,否则表示失败
说明:192.168.1.10/20 中 20 是 CIDR 表示法的网络掩码,想详细了解的可以自行查阅网络掩码的资料

  • 移除IP
网络接口上添加了IP之后,可使用 ip a del ip地址 dev 接口名字 命令从指定的接口移除指定的IP,移除的时候IP后面需要携带网络掩码
[root@ecs-centos-7 ~]# ip a del 192.168.1.10/20 dev eth0[root@ecs-centos-7 ~]# ip a show eth02: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000link/ether fa:16:3e:e0:4f:b8 brd ff:ff:ff:ff:ff:ffinet 192.168.0.9/24 brd 192.168.0.255 scope global noprefixroute dynamic eth0valid_lft 71414sec preferred_lft 71414secinet6 fe80::f816:3eff:fee0:4fb8/64 scope linkvalid_lft forever preferred_lft forever
修改网络接口状态要关闭或者开启网络接口,可以使用 ip link set dev 接口名字 up/down 命令
例如:有 lo 和 eth0 两个网络接口, 具体接口信息如下
[root@ecs-centos-7 ~]# ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000link/ether fa:16:3e:e0:4f:b8 brd ff:ff:ff:ff:ff:ffinet 192.168.0.9/24 brd 192.168.0.255 scope global noprefixroute dynamic eth0valid_lft 59216sec preferred_lft 59216secinet6 fe80::f816:3eff:fee0:4fb8/64 scope linkvalid_lft forever preferred_lft forever
通过 ping -w 3 127.0.0.1 命令测试,结果表明 lo 接口目前是开启状态,具体的测试输出如下所示
[root@ecs-centos-7 ~]# ping -w 3 127.0.0.1PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.014 ms64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.026 ms64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.022 ms64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.023 ms--- 127.0.0.1 ping statistics ---4 packets transmitted, 4 received, 0% packet loss, time 2999msrtt min/avg/max/mdev = 0.014/0.021/0.026/0.005 ms
现在关闭 lo 网络接口,并再次测试该接口的状态,具体命令如下:
[root@ecs-centos-7 ~]# ip link set dev lo down[root@ecs-centos-7 ~]# ip link show lo1: lo: <LOOPBACK> mtu 65536 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00[root@ecs-centos-7 ~]# ping -w 3 127.0.0.1PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.--- 127.0.0.1 ping statistics ---4 packets transmitted, 0 received, 100% packet loss, time 2999ms
执行 ip link set dev lo down 命令之后,关闭了网络接口lo,通过 ip link show lo 命令查看该接口的信息,结果表明接口是关闭状态,再次通过 ping -w 3 127.0.0.1测试接口的状态,再一次确认了接口是关闭状态
修改网络接口传输队列长度通过 p l set txqueuelen 长度 dev 接口名字 命令可以设置网络接口的传输队列长度
[root@ecs-centos-7 ~]# ip l show eth02: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1200link/ether fa:16:3e:e0:4f:b8 brd ff:ff:ff:ff:ff:ff[root@ecs-centos-7 ~]# ip l set txqueuelen 1000 dev eth0[root@ecs-centos-7 ~]# ip l show eth02: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000link/ether fa:16:3e:e0:4f:b8 brd ff:ff:ff:ff:ff:ff
上面的例子中,字符串 qlen 1200 表示传输队列长度是 1200
从例子中可以看出,修改传输队列长度之前,传输队列长度是 1200

推荐阅读