有时已经把ip配置文件写好,还是会有下面的情况

一个网卡会获取多个地址

root:/etc/sysconfig/network-scripts # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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 group default qlen 1000
link/ether 00:0c:29:a8:16:6d brd ff:ff:ff:ff:ff:ff
inet 192.168.64.140/24 brd 192.168.64.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fea8:166d/64 scope link
valid_lft forever preferred_lft forever
3: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:a8:16:77 brd ff:ff:ff:ff:ff:ff
inet 192.168.65.148/24 brd 192.168.65.255 scope global noprefixroute dynamic ens34
valid_lft 1799sec preferred_lft 1799sec
inet 192.168.65.147/24 brd 192.168.65.255 scope global secondary noprefixroute dynamic ens34
valid_lft 1435sec preferred_lft 1435sec
inet 192.168.65.146/24 brd 192.168.65.255 scope global secondary noprefixroute dynamic ens34
valid_lft 1461sec preferred_lft 1461sec
inet6 fe80::20c:29ff:fea8:1677/64 scope link
valid_lft forever preferred_lft forever

或者

root:/etc/sysconfig/network-scripts # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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 group default qlen 1000
link/ether 00:0c:29:a8:16:6d brd ff:ff:ff:ff:ff:ff
inet 192.168.64.140/24 brd 192.168.64.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fea8:166d/64 scope link
valid_lft forever preferred_lft forever
3: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:a8:16:77 brd ff:ff:ff:ff:ff:ff
inet 192.168.65.147/24 brd 192.168.65.255 scope global dynamic ens34
valid_lft 1775sec preferred_lft 1775sec
inet 192.168.65.146/24 brd 192.168.65.255 scope global secondary dynamic ens34
valid_lft 1784sec preferred_lft 1784sec
inet6 fe80::20c:29ff:fea8:1677/64 scope link
valid_lft forever preferred_lft forever

解决方法

原因是network与NetworkManager服务冲突

第一步是禁用NetworkManager服务

# systemctl stop NetworkManager.service
# systemctl disable NetworkManager.service

第二步重启network服务

# service network restart

但在 大多数情况下还是不行,必须要在网卡配置文件里写入一行

root:/etc/sysconfig/network-scripts # cat ifcfg-ens34
BOOTPROTO="dhcp"
DEVICE="ens34"
ONBOOT="yes"
NM_CONTROLLED="no"  #加入此行,网卡就不受NetworkManager所控制