解决克隆RHEL7后网络无法启动问题

时间:2021-06-25 18:35:30

1、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 查看具体报错信息,也可查看cat /var/log/messages|grep network

Jun 23 22:46:32 localhost systemd: Starting LSB: Bring up/down networking...
Jun 23 22:46:32 localhost NetworkManager[1006]:   ifcfg-rh: parsing /etc/sysconfig/network-scripts/ifcfg-lo ...
Jun 23 22:46:32 localhost network: Bringing up loopback interface:  [  OK  ]
Jun 23 22:46:32 localhost network: Bringing up interface eno16777736:  Error: Connection activation failed: Connection 'eno16777736' is not available on the device eno16777736 at this time.
Jun 23 22:46:32 localhost network: [FAILED]
Jun 23 22:46:32 localhost network: RTNETLINK answers: File exists
Jun 23 22:46:32 localhost network: RTNETLINK answers: File exists
Jun 23 22:46:32 localhost network: RTNETLINK answers: File exists
Jun 23 22:46:32 localhost network: RTNETLINK answers: File exists
Jun 23 22:46:32 localhost network: RTNETLINK answers: File exists
Jun 23 22:46:32 localhost network: RTNETLINK answers: File exists
Jun 23 22:46:32 localhost network: RTNETLINK answers: File exists
Jun 23 22:46:32 localhost network: RTNETLINK answers: File exists
Jun 23 22:46:32 localhost network: RTNETLINK answers: File exists
Jun 23 22:46:32 localhost systemd: network.service: control process exited, code=exited status=1
Jun 23 22:46:32 localhost systemd: Failed to start LSB: Bring up/down networking.
Jun 23 22:46:32 localhost systemd: Unit network.service entered failed state.
Jun 23 22:46:32 localhost systemd: network.service failed.

解决办法:

大意是跟系统自带的NetworkManager这个管理套件有关系,关掉就可以解决。

试一下:

systemctl stop NetworkManager

systemctl disable NetworkManager

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.

重新启动网络:

systemctl start network.service

执行ifconfig查看,还是无法识别网卡信息:eno16777736

[root@localhost network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::250:56ff:fe3b:1be3  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:3b:1b:e3  txqueuelen 1000  (Ethernet)
        RX packets 1  bytes 86 (86.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 628 (628.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 770  bytes 65420 (63.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 770  bytes 65420 (63.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

继续查看cat /var/log/messages|grep network,发现是因为netmask错误导致

Jun 23 22:53:33 localhost systemd: Starting LSB: Bring up/down networking...
Jun 23 22:53:33 localhost network: Bringing up loopback interface:  [  OK  ]
Jun 23 22:53:33 localhost network: Bringing up interface eno16777736:  ipcalc: bad netmask: 225.225.225.0
Jun 23 22:53:33 localhost network: ipcalc: bad netmask: 225.225.225.0
Jun 23 22:53:33 localhost network: ipcalc: bad netmask: 225.225.225.0
Jun 23 22:53:35 localhost network: Error: an inet prefix is expected rather than "192.168.137.15/".
Jun 23 22:53:35 localhost network: ERROR    : [/etc/sysconfig/network-scripts/ifup-eth] Error adding address 192.168.137.15 for eno16777736.
Jun 23 22:53:35 localhost /etc/sysconfig/network-scripts/ifup-eth: Error adding address 192.168.137.15 for eno16777736.
Jun 23 22:53:35 localhost network: bind: Cannot assign requested address
Jun 23 22:53:35 localhost network: Error: an inet prefix is expected rather than "192.168.137.15/".
Jun 23 22:53:35 localhost NET[3750]: /etc/sysconfig/network-scripts/ifup-post : updated /etc/resolv.conf
Jun 23 22:53:35 localhost network: [  OK  ]
Jun 23 22:53:35 localhost network: RTNETLINK answers: File exists
Jun 23 22:53:35 localhost network: RTNETLINK answers: File exists
Jun 23 22:53:35 localhost network: RTNETLINK answers: File exists
Jun 23 22:53:35 localhost network: RTNETLINK answers: File exists
Jun 23 22:53:35 localhost network: RTNETLINK answers: File exists
Jun 23 22:53:35 localhost network: RTNETLINK answers: File exists
Jun 23 22:53:35 localhost network: RTNETLINK answers: File exists
Jun 23 22:53:35 localhost network: RTNETLINK answers: File exists
Jun 23 22:53:35 localhost network: RTNETLINK answers: File exists
Jun 23 22:53:35 localhost systemd: Started LSB: Bring up/down networking.

修改/etc/sysconfig/network-scripts/

[root@localhost network-scripts]# cat ifcfg-eno16777736
HWADDR=00:0C:29:0D:ED:88
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=52e0ff70-7e89-46ae-8f7a-699099c36f5e
ONBOOT=yes
IPADDR=192.168.137.15
GATEWAY=192.168.137.2
NETMASK=255.255.255.0
DNS1=192.168.1.1

然后重启服务:service network restart 问题解决。

[root@localhost network-scripts]# ping www.baidu.com
PING www.a.shifen.com (220.181.112.244) 56(84) bytes of data.
64 bytes from 220.181.112.244: icmp_seq=1 ttl=128 time=26.7 ms
64 bytes from 220.181.112.244: icmp_seq=2 ttl=128 time=25.0 ms
64 bytes from 220.181.112.244: icmp_seq=3 ttl=128 time=24.8 ms
64 bytes from 220.181.112.244: icmp_seq=4 ttl=128 time=24.6 ms
64 bytes from 220.181.112.244: icmp_seq=5 ttl=128 time=27.0 ms
64 bytes from 220.181.112.244: icmp_seq=6 ttl=128 time=25.1 ms
64 bytes from 220.181.112.244: icmp_seq=7 ttl=128 time=27.8 ms
64 bytes from 220.181.112.244: icmp_seq=8 ttl=128 time=30.4 ms
^C
--- www.a.shifen.com ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 7014ms
rtt min/avg/max/mdev = 24.662/26.459/30.403/1.848 ms