经常会遇到虚拟机重启后,无法建立服务器远程连接的问题,经排查网络不通;
#重启网络:注意CentOS6需要使用service network restart命令
[root@hu ~]# systemctl restart network
Restarting network (via systemctl): Job for network.service failed. See 'systemctl status network.service' and 'journalctl -xn' for details.
#执行'systemctl status network.service'进一步排查
[root@localhost ~]# systemctl status network.service
network.service - LSB: Bring up/down networking
Loaded: loaded (/etc/rc.d/init.d/network)
Active: failed (Result: exit-code) since三 2021-12-29 09:30:10 CST; 1min 5s ago
12月 29 09:30:10 localhost.localdomain network[2920]: RTNETLINK answers: File exists
...
...
12月 29 09:30:10 localhost.localdomain systemd[1]: network.service: control process exited, code=exited status=1
12月 29 09:30:10 localhost.localdomain systemd[1]: Failed to start LSB: Bring up/down networking.
12月 29 09:30:10 localhost.localdomain systemd[1]: Unit network.service entered failed state.
#关闭NetworkManager服务,重启机器后会失效
[root@hu ~]# systemctl stop NetworkManager
#永久关闭NetworkManager服务,重启机器后不会失效
[root@hu ~]# systemctl disable NetworkManager
# 查看防火墙状态
[root@hu ~]# firewall-cmd --state
running ---运行中,即开启状态
# 关闭防火墙
[root@hu ~]# systemctl stop firewalld
# 查看是否关闭成功
[root@hu ~]# firewall-cmd --state
not running ---不在运行中,即关闭状态
#查看selinux状态
[root@hu ~]# getenforce
Enforcing ---表示开启状态
# 临时关闭
[root@hu ~]# setenforce 0 ---立即生效,重启后失效
# 永久关闭,修改selinux配置文件。 ---重启后生效
[root@hu ~]# vim /etc/selinux/config
...
# 将SELINUX的值修改为disabled
SELINUX=disabled
...
# 关闭后再次查看是否关闭成功
[root@hu ~]# getenforce
Disabled ---表示关闭状态
#重启机器
[root@hu ~]# reboot
...
...
# 再次重启网络,无报错
[root@hu ~]# systemctl restart network
# 查看网络是否重启成功
[root@hu ~]# ip a
...
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:0e:b4:0d brd ff:ff:ff:ff:ff:ff
inet 192.168.139.128/24 brd 192.168.63.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe0e:b40d/64 scope link
valid_lft forever preferred_lft forever
...
ens33网卡已重启成功
至此,已解决网络重启不了的问题。