使用systemctl restart network无法重启网络和ping不通百度

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lk142500/article/details/82778165

1 问题描述

在使用Centos7时,突然遇到使用systemctl status network发现网络无法正常重启。当时束手无策。虽然看到
状态显示为Failed to start LSB.但没有较好的解决方式。当时同事因为经验比较丰富,操作了一下,把操作记录
留存一下,以后在遇到相同问题时,可以快速解决.

2 操作

2.1 问题描述

[root@localhost Desktop]# 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 Tue 2018-09-18 23:00:03 PDT; 38s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1124 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE)

Sep 18 23:00:03 localhost.localdomain network[1124]: Could not load file '/et...
Sep 18 23:00:03 localhost.localdomain network[1124]: Could not load file '/et...
Sep 18 23:00:03 localhost.localdomain network[1124]: Could not load file '/et...
Sep 18 23:00:03 localhost.localdomain network[1124]: [  OK  ]
Sep 18 23:00:03 localhost.localdomain network[1124]: Bringing up interface en...
Sep 18 23:00:03 localhost.localdomain network[1124]: [FAILED]
Sep 18 23:00:03 localhost.localdomain systemd[1]: network.service: control pr...
Sep 18 23:00:03 localhost.localdomain systemd[1]: Failed to start LSB: Bring ...
Sep 18 23:00:03 localhost.localdomain systemd[1]: Unit network.service entere...
Sep 18 23:00:03 localhost.localdomain systemd[1]: network.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

2.2 解决方式如下

2.2.1 删除网卡UUID

首先删去网卡UUID

[root@localhost Desktop]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vim ifcfg-eno16777736 
[root@localhost network-scripts]# cat ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
DEVICE=eno16777736
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPADDR=192.168.0.125
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS=8.8.8.8

尝试重启网络服务

[root@localhost network-scripts]# 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@localhost network-scripts]# 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.

2.2.2 ifconfig命令

使用ifconfig查询所有网卡的状态和信息。发现仍然没有配置的192.168.0.125网卡信息。

[root@localhost network-scripts]# ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 192  bytes 16704 (16.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 192  bytes 16704 (16.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:aa:ec:2a  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
     
[root@localhost network-scripts]# ifdown ifcfg-eno16777736

2.2.3 ifup启动网卡

使用ifup命令加上网卡配置尝试启动网卡

[root@localhost network-scripts]# ifup ifcfg-eno16777736 
Error: Connection activation failed: No suitable device found for this connection.
[root@localhost network-scripts]# ifconfig -a
eno16777736: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:0c:29:49:b7:e5  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 192  bytes 16704 (16.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 192  bytes 16704 (16.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:aa:ec:2a  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0-nic: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 52:54:00:aa:ec:2a  txqueuelen 500  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2.2.4 停止NetworkManager.service

停止网络管理服务

[root@localhost Desktop]# systemctl stop NetworkManager.service 
[root@localhost Desktop]# systemctl disable NetworkManager.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.

2.2.5 重启network服务

[root@localhost network-scripts]# service network restart
Restarting network (via systemctl):                        [  OK  ]
[root@localhost network-scripts]# 
[root@localhost network-scripts]# 
[root@localhost network-scripts]# 

2.3 问题解决

[root@localhost network-scripts]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.125  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe49:b7e5  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:49:b7:e5  txqueuelen 1000  (Ethernet)
        RX packets 5  bytes 582 (582.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 19  bytes 2913 (2.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 260  bytes 22616 (22.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 260  bytes 22616 (22.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:aa:ec:2a  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2.4 新的问题 无法ping通百度

[root@localhost network-scripts]# ping www.baidu.com
ping: unknown host www.baidu.com

[root@localhost network-scripts]# 

2.5 使用命令dhclient解决

[root@localhost network-scripts]# dhclient
[root@localhost network-scripts]# ping www.baidu.com
PING www.a.shifen.com (115.239.211.112) 56(84) bytes of data.
64 bytes from 115.239.211.112: icmp_seq=1 ttl=53 time=11.4 ms
64 bytes from 115.239.211.112: icmp_seq=2 ttl=53 time=8.78 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 8.789/10.117/11.446/1.332 ms

[root@localhost network-scripts]# 
[root@localhost network-scripts]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.125  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe49:b7e5  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:49:b7:e5  txqueuelen 1000  (Ethernet)
        RX packets 46  bytes 5476 (5.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 36  bytes 5680 (5.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 268  bytes 23248 (22.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 268  bytes 23248 (22.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:aa:ec:2a  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0-nic: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 52:54:00:aa:ec:2a  txqueuelen 500  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2.5 修改DNS域名解析服务

上述的2.5是错误,这是因为配置文件的本意是要使用static ip,就是固定ip,但如果使用命令dhclient,则默认启动了一个DHCP服务,这样会动态修改IP,因此在本意情况下应该停止该服务。

2.5.1 杀死dhclient进程

[root@localhost network-scripts]# ps -ef
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 Sep27 ?        00:00:04 /usr/lib/systemd/systemd --swi
root          2      0  0 Sep27 ?        00:00:00 [kthreadd]
root          3      2  0 Sep27 ?        00:00:00 [ksoftirqd/0]
root          7      2  0 Sep27 ?        00:00:00 [migration/0]
root          8      2  0 Sep27 ?        00:00:00 [rcu_bh]
root          9      2  0 Sep27 ?        00:00:00 [rcuob/0]
root         10      2  0 Sep27 ?        00:00:00 [rcuob/1]
root         11      2  0 Sep27 ?        00:00:00 [rcuob/2]

[root@localhost network-scripts]# ps -ef | grep dh
nobody     2639      1  0 Sep27 ?        00:00:00 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root       2640   2639  0 Sep27 ?        00:00:00 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root       4500      1  0 Sep27 ?        00:00:00 dhclient
root      59112  58502  0 02:41 pts/0    00:00:00 grep --color=auto dh
[root@localhost network-scripts]# kill -9 4500
[root@localhost network-scripts]# 
[root@localhost network-scripts]# 
[root@localhost network-scripts]# 
[root@localhost network-scripts]# ps -ef | grep dh
nobody     2639      1  0 Sep27 ?        00:00:00 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root       2640   2639  0 Sep27 ?        00:00:00 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root      59129  58502  0 02:41 pts/0    00:00:00 grep --color=auto dh

2.5.2 重启网络

[root@localhost network-scripts]# service network restart
Restarting network (via systemctl):                        [  OK  ]
[root@localhost network-scripts]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet **192.168.0.125**  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe49:b7e5  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:49:b7:e5  txqueuelen 1000  (Ethernet)
        RX packets 284767  bytes 20513194 (19.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 357297  bytes 969250205 (924.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 22  bytes 2130 (2.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 22  bytes 2130 (2.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:aa:ec:2a  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0-nic: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 52:54:00:aa:ec:2a  txqueuelen 500  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2.5.3 ping不通百度

[root@localhost network-scripts]# ping www.baidu.com
ping: unknown host www.baidu.com

2.5.4 解决方式

  1. 使用vim命令修改配置文件ifcfg-eno16777736,删除其中DNS信息。

  2. 修改配置文件/etc/resolv.conf

    [root@localhost cetc52]# cat /etc/resolv.conf
    ; generated by /usr/sbin/dhclient-script
    nameserver 192.168.0.1

/etc/resolv.conf配置文件中192.168.0.1为虚拟机所在主机的默认网关。添加nameserver为默认网关即可,同时如果仍然无法ping通百度,也可以再添加一项

namserver 8.8.8.8

2.5.5 验证

[root@localhost network-scripts]# ping www.baidu.com
PING www.a.shifen.com (58.217.200.15) 56(84) bytes of data.
64 bytes from 58.217.200.15: icmp_seq=1 ttl=52 time=481 ms
64 bytes from 58.217.200.15: icmp_seq=2 ttl=52 time=22.4 ms
64 bytes from 58.217.200.15: icmp_seq=3 ttl=52 time=22.0 ms

3. 问题总结

工作中第一次遇到问题,问题是问题没有什么的,但如果第二次遇到相同的问题,仍然是问题,这就是很大的问题了。多总结,多思考,多学习这才是正常的职场态度。加油

猜你喜欢

转载自blog.csdn.net/lk142500/article/details/82778165