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

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. 问题总结

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

  • 28
    点赞
  • 123
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值