centos7重启网卡提示错误的解决方法
今天在centOS 7下更改完静态ip后发现network服务重启不了,翻遍了网络,尝试了各种方法,终于解决了。
现把各种解决方法归纳整理,希望能让后面的同学少走点歪路。。。
首先看问题:执行service network restart命令后出现下面的错误:
Restarting network (via systemctl): 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 五 2017-07-14 19:01:47 CST; 1min 16s ago
Docs: man:systemd-sysv-generator(8)
Process: 4681 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE)
CGroup: /system.slice/network.service
└─1192 /sbin/dhclient -H mini1 -1 -q -lf /var/lib/dhclient/dhclient--ens33.lease -pf /v...
7月 14 19:01:47 mini1 network[4681]: RTNETLINK answers: File exists
7月 14 19:01:47 mini1 network[4681]: RTNETLINK answers: File exists
7月 14 19:01:47 mini1 network[4681]: RTNETLINK answers: File exists
7月 14 19:01:47 mini1 network[4681]: RTNETLINK answers: File exists
7月 14 19:01:47 mini1 network[4681]: RTNETLINK answers: File exists
7月 14 19:01:47 mini1 network[4681]: RTNETLINK answers: File exists
7月 14 19:01:47 mini1 systemd[1]: network.service: control process exited, code=exited status=1
7月 14 19:01:47 mini1 systemd[1]: Failed to start LSB: Bring up/down networking.
7月 14 19:01:47 mini1 systemd[1]: Unit network.service entered failed state.
7月 14 19:01:47 mini1 systemd[1]: network.service failed.
network服务启动不了首先保证/etc/sysconfig/network-scripts目录下的ifcfg-xxx(每台机器不一定相同)没有错误(如果你改动过的话),这里的错误指的在更改过程中因为手误敲错字母之类的。
网上最常见的几种做法如下:
1.和 NetworkManager 服务有冲突,这个好解决,直接关闭 NetworkManger 服务就好了, service NetworkManager stop,并且禁止开机启动 chkconfig NetworkManager off 。之后重启就好了。
2和配置文件的MAC地址不匹配,这个也好解决,使用ip addr(或ifconfig)查看mac地址
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
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:b8:e7:21 brd ff:ff:ff:ff:ff:ff
inet 192.168.65.141/24 brd 192.168.65.255 scope global dynamic ens33
valid_lft 1193sec preferred_lft 1193sec
inet6 fe80::cca2:d835:f93:e637/64 scope link
valid_lft forever preferred_lft forever
00:0c:29:b8:e7:21这个就是MAC地址了,将/etc/sysconfig/network-scripts/ifcfg-xxx中的HWADDR(如果没有就添加上)改成这个MAC地址
3.设定开机启动一个名为NetworkManager-wait-online服务,命令为:
systemctl enable NetworkManager-wait-online.service
=========================================================================================================
上面两个是我看到最多的解决方法,但是很遗憾,我的并没有解决。
有查看资料,发现了以下一些方法:
4.查看/etc/sysconfig/network-scripts下,将其余无关的网卡位置文件全删掉,避免不必要的影响,即只留一个以ifcfg开头的文件,
留的那一个应和使用ip addr命令查看ip第二条开头的名称一致(我的是ens33,参见上面我贴出的ip addr命令执行结果),所以我只留了一个ifcfg-ens33。(我的其中两台机器就是这么弄好的,因为我在修改前留了备份,把备份删掉就好了。。。)
5.将ifcfg-xxx文件中的DEVICE一行注释掉。
6.将ifcfg-xxx中的NAME改为和文件名一致。
7.在VMWare的编辑-虚拟网络编辑器中将网络模式改为桥接。
8.看VMWare右下角的网络适配器是否连接,如果没有连接则连接上。
(补充:点击网络适配器-设置,将NAT模式改为桥接试试,我的改为桥接后可以重启network服务了但是上不了网,可以重启后
再将桥接模式改为NAT模式,发现既可以上网又可以重启network服务了)
9.查看下你电脑有没有禁用了VMware DHCP service和VMware NAT service 这几个vm服务,如果禁用则开启。
10 .如果你改成了静态ip别忘了将BOOTPROTO改为static。
11.如果以上都没有解决,还有最后一招-- 重启 看一看有没有奇迹发生!!(我的另外一台重启后莫名就好了)
上面这些方法,我基本都试过了,对我的机器有的有用有的没用,但是有人也用这些方法解决了,所以一并记录下来。希望能给予你一点帮助
背景描述:prometheus服务器总是出现两个小时内断开外部连接,导致prometheus和grafana提供的web服务无法访问,ssh工具连不上机器,故选择了重启实例,可是在重启实例后再次出现此般状况,
故对服务器系统进行排查,经排查后定位到实例的网卡出现了以下问题:
[root@prometheus /var/log]# systemctl status network ● 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 二 2021-08-17 18:02:07 CST; 7h left Docs: man:systemd-sysv-generator(8) Process: 1172 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE) CGroup: /system.slice/network.service └─1359 /sbin/dhclient -1 -q -lf /var/lib/dhclient/dhclient--ens5.lease -pf /var/run/dhclient-ens5.pid -H prometheus ens5 8月 17 18:02:05 prometheus dhclient[1301]: DHCPACK from 172.31.32.1 (xid=0x41460a8e) 8月 17 18:02:07 prometheus dhclient[1301]: bound to 172.31.44.100 -- renewal in 1762 seconds. 8月 17 18:02:07 prometheus network[1172]: Determining IP information for ens5... done. 8月 17 18:02:07 prometheus network[1172]: [ OK ] 8月 17 18:02:07 prometheus network[1172]: Bringing up interface eth0: ERROR : [/etc/sysconfig/network-scripts/ifup-eth] Device eth0 does not seem to be present, delaying initialization. 8月 17 18:02:07 prometheus network[1172]: [FAILED] 8月 17 18:02:07 prometheus systemd[1]: network.service: control process exited, code=exited status=1 8月 17 18:02:07 prometheus systemd[1]: Failed to start LSB: Bring up/down networking. 8月 17 18:02:07 prometheus systemd[1]: Unit network.service entered failed state. 8月 17 18:02:07 prometheus systemd[1]: network.service failed. 第一次发现问题后经过重启网络发现如下: [root@prometheus /var/log]# 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. [root@prometheus /var/log]# systemctl status network ● 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 二 2021-08-17 10:13:20 CST; 9s ago Docs: man:systemd-sysv-generator(8) Process: 11979 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE) CGroup: /system.slice/network.service └─1359 /sbin/dhclient -1 -q -lf /var/lib/dhclient/dhclient--ens5.lease -pf /var/run/dhclient-ens5.pid -H prometheus ens5 8月 17 10:13:20 prometheus network[11979]: RTNETLINK answers: File exists 8月 17 10:13:20 prometheus network[11979]: RTNETLINK answers: File exists 8月 17 10:13:20 prometheus network[11979]: RTNETLINK answers: File exists 8月 17 10:13:20 prometheus network[11979]: RTNETLINK answers: File exists 8月 17 10:13:20 prometheus network[11979]: RTNETLINK answers: File exists 8月 17 10:13:20 prometheus network[11979]: RTNETLINK answers: File exists 8月 17 10:13:20 prometheus systemd[1]: network.service: control process exited, code=exited status=1 8月 17 10:13:20 prometheus systemd[1]: Failed to start LSB: Bring up/down networking. 8月 17 10:13:20 prometheus systemd[1]: Unit network.service entered failed state. 8月 17 10:13:20 prometheus systemd[1]: network.service failed.
故在网上寻找了有关"Device eth0 does not seem to be present, delaying initialization","RTNETLINK answers: File exists"两个问题的解决;
故在网上寻找了有关"Device eth0 does not seem to be present, delaying initialization","RTNETLINK answers: File exists"两个问题的解决; 网上的方法大致如下: 第一种:和 NetworkManager 服务有冲突,直接关闭 NetworkManger 服务, service NetworkManager stop,并且禁止开机启动 chkconfig NetworkManager off 。之后重启。(我尝试了,发现机器里并没有NetworkManager服务,故不可) 第二种:和配置文件的MAC地址不匹配,修改 /etc/udev/rules.d/70-persistent-net.rules文件的MAC地址和 /etc/sysconfig/network-scripts/ifcfg-eth5一样。(我尝试了,aws实例中并没有网卡配置并没有MAC地址,故不可) 第三种:ip addr flush dev eth5(尝试后,未能解决)。
问题解决:
在发现主机ip绑定的是ens5这张网卡,而报错中出现"Device eth0 does not seem to be present" 推测可能是aws中eth0这张网卡影响了eth5网卡的启动,后经操作重启网卡成功;操作如下: [root@prometheus /etc/sysconfig/network-scripts]# mv ifcfg-eth0 /root [root@prometheus /etc/sysconfig/network-scripts]# kill -9 1359 [root@prometheus /etc/sysconfig/network-scripts]# rm -rf /var/lib/dhclient/dhclient--ens5.lease /var/run/dhclient-ens5.pid /etc/udev/rules.d/70-persistent-net.rules [root@prometheus /etc/sysconfig/network-scripts]# systemctl restart network(这里已经重启成功) [root@prometheus /etc/sysconfig/network-scripts]# systemctl status network ● network.service - LSB: Bring up/down networking Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled) Active: active (running) since 二 2021-08-17 11:34:47 CST; 8min ago Docs: man:systemd-sysv-generator(8) Process: 25605 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS) Process: 25782 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS) CGroup: /system.slice/network.service └─25966 /sbin/dhclient -1 -q -lf /var/lib/dhclient/dhclient--ens5.lease -pf /var/run/dhclient-ens5.pid -H prometheus ens5 8月 17 11:34:45 prometheus systemd[1]: Starting LSB: Bring up/down networking... 8月 17 11:34:45 prometheus network[25782]: Bringing up loopback interface: [ OK ] 8月 17 11:34:45 prometheus network[25782]: Bringing up interface ens5: 8月 17 11:34:45 prometheus dhclient[25911]: DHCPREQUEST on ens5 to 255.255.255.255 port 67 (xid=0x3567fc41) 8月 17 11:34:45 prometheus dhclient[25911]: DHCPACK from 172.31.32.1 (xid=0x3567fc41) 8月 17 11:34:47 prometheus dhclient[25911]: bound to 172.31.44.100 -- renewal in 1363 seconds. 8月 17 11:34:47 prometheus network[25782]: Determining IP information for ens5... done. 8月 17 11:34:47 prometheus network[25782]: [ OK ] 8月 17 11:34:47 prometheus systemd[1]: Started LSB: Bring up/down networking.
看到running 这个单词,就说明网络是启动状态,接下来我们使用命令修改ip
使用命令修改IP
打开网卡配置文件 vim /etc/sysconfig/network-scripts/ifcfg-ens32
这里之所以加了DNS2=192.168.1.1 是因为有些路由器自带DNS转发功能
问题1: 如果设置了之后,还是无法ping通百度,是什么原因?
如果DNS,网络都没有问题,还有一种可能就是360卫士开启了局域网隐身功能, 只要进入360卫士-流量防火墙-局域网防护问题, 只要关掉局域网隐身即可。
2. 关闭防火墙并设置开机自动关闭
[root@localhost ~]# Systemctl status firewalld #查看服务运行状态
[root@localhost ~]# systemctl stop firewalld 关闭当前防护墙
[root@localhost ~]# systemctl disable firewalld 开机自动关闭
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
1.
2.
3.
4.
5.
6.
3. 设置selinux开机自动关闭
1) 临时关闭
[root@centos7-test1 ~]# setenforce 0
1.
2) 开机自动关闭
vim /etc/sysconfig/selinux
4. 设置光盘开机自动挂载
[root@localhost ~]# echo “/dev/sr0 /mnt iso9660 defaults 0 0” >> /etc/fstab
mount -a 全部挂载
5. 配置好本地yum源
yum的一切配置信息都储存在一个叫yum.repos.d的配置文件中,通常位于/etc目 录下,这是整个yum系统的重中之重
删除原有的文件
rm -rf /etc/yum.repo.d/*
[root@centos7-test1 yum.repos.d]# pwd
/etc/yum.repos.d
1.
2.
登录后复制
[root@centos7-test1 yum.repos.d]# cat rhel7.repo
[rhel7]
name=rhel7
baseurl=file:///mnt
enabled=1
gpgcheck=0
[root@centos7-test1 yum.repos.d]#
解释:
[rhel7-source] 名称
name=rhel-server 描述信息
baseurl=file:///mnt (系统盘)文件路径
enabled=1 启用
gpgcheck=0 取消验证
总结
1、 固定的可以联网IP地址
2、 关闭防火墙
3、 关闭selinux
4、 光盘自动挂载
5、 配置好本地yum源
接下来创建个快照,方便使用