我很长时间不配置网络的东西,今天我在网上搜了一个配置ip页面,配置的时候出现了错误,我是这么一步步错的
首先,我的系统是centos7
1.我先复制了配置IP的文件了
# cp /etc/sysconfig/network-scripts/ifcfg-ens160 /etc/sysconfig/network-scripts/ifcfg-ens161
# cp /etc/sysconfig/network-scripts/ifcfg-ens160 /etc/sysconfig/network-scripts/ifcfg-ens162
修改配置文件(162文件,161相似):
# vim /etc/sysconfig/network-scripts/ifcfg-ens162
NAME=ens162
DEVICE=ens162
IPADDR=192.168.1.162
2.重新启动网络
# systemctl restart network
然后就出现了这个:
Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.
查看一下网络状态
# systemctl status network.service
● network.service - LSB: Bring up/down networking
Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2017-03-13 23:24:37 CST; 16s ago
Docs: man:systemd-sysv-generator(8)
Process: 2878 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE)
Mar 13 23:24:37 centos7 network[2878]: RTNETLINK answers: File exists
Mar 13 23:24:37 centos7 network[2878]: RTNETLINK answers: File exists
Mar 13 23:24:37 centos7 network[2878]: RTNETLINK answers: File exists
Mar 13 23:24:37 centos7 network[2878]: RTNETLINK answers: File exists
Mar 13 23:24:37 centos7 network[2878]: RTNETLINK answers: File exists
Mar 13 23:24:37 centos7 network[2878]: RTNETLINK answers: File exists
Mar 13 23:24:37 centos7 systemd[1]: network.service: control process exited, code=exited status=1
Mar 13 23:24:37 centos7 systemd[1]: Failed to start LSB: Bring up/down networking.
Mar 13 23:24:37 centos7 systemd[1]: Unit network.service entered failed state.
Mar 13 23:24:37 centos7 systemd[1]: network.service failed.
3.百度问题,都说是禁止使用下面这两个
(别冲动!!!会被骂)
# systemctl stop NetworkManager
# systemctl disable NetworkManager
再次重启,还是没有用
4.一看不对劲删除ens161和ens162文件,再重新启动
# rm ifcfg-ens161 (最好用mv ifcfg-ens161 /tmp/ )
# rm ifcfg-ens162 (我脑子坏了用删除)
# systemctl restart network
还是没用,网络重启还是失败
5.查看错误日志(我的内网环境,无法复制,只能用 别人的日志了,不过错误很像)
# grep network /var/log/messages
Mar 13 23:51:35 centos7 systemd: Starting LSB: Bring up/down networking...
Mar 13 23:51:35 centos7 network: Bringing up loopback interface: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
Mar 13 23:51:35 centos7 network: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
Mar 13 23:51:35 centos7 network: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
Mar 13 23:51:35 centos7 network: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
Mar 13 23:51:35 centos7 network: [ OK ]
Mar 13 23:51:36 centos7 network: Bringing up interface eth0: Error: Connection activation failed: No suitable device found for this connection.
Mar 13 23:51:36 centos7 network: [FAILED]
Mar 13 23:51:36 centos7 network: RTNETLINK answers: File exists
Mar 13 23:51:36 centos7 network: RTNETLINK answers: File exists
Mar 13 23:51:36 centos7 network: RTNETLINK answers: File exists
Mar 13 23:51:36 centos7 network: RTNETLINK answers: File exists
Mar 13 23:51:36 centos7 network: RTNETLINK answers: File exists
Mar 13 23:51:36 centos7 network: RTNETLINK answers: File exists
Mar 13 23:51:36 centos7 network: RTNETLINK answers: File exists
Mar 13 23:51:36 centos7 network: RTNETLINK answers: File exists
Mar 13 23:51:36 centos7 network: RTNETLINK answers: File exists
Mar 13 23:51:36 centos7 systemd: network.service: control process exited, code=exited status=1
Mar 13 23:51:36 centos7 systemd: Failed to start LSB: Bring up/down networking.
Mar 13 23:51:36 centos7 systemd: Unit network.service entered failed state.
Mar 13 23:51:36 centos7 systemd: network.service failed.
6.这里我已经把复制的文件删除了
又去找方法,说是加上Mac地址
# ip addr 查看Mac地址,在ens160后加
HWADDR=00:0c:29:0c:15:49
重启,又失败了啊,还是之前的错误
我弄的是生产环境,赶紧关机了
但是在我们组大佬的带领下,让我测试环境复现了这个错误
解决方法(这个仅限于是我这样的错误,仅供参考):
# ifdown ifcfg-ens160
# systemctl restart network
原因:
复制配置多个网卡,重启发生了冲突,以及其他配置的错误,之后再重启UUID也会有问题
总结:
- 配置多个ip时,UUID一样会有冲突,可以去掉这个
- DEVICE查看下有没有别的网卡,没有就别改任何值
- 单up/down一个ip,不用全部都重启!!!
我还有一个很大的错误:
1.没有备份第一个网卡文件
其实我这添加Mac,还有新的ip,我忘记了备份,虽然没有更改多少,但是想想挺后怕,如果没有记住其的更改
2.没有搜索添加的IP是不是空IP
没有ping一下,如果冲突了,直接就是生产事故