背景
搭建实验环境时,由于实验环境在虚机网络内,配置规划ip和网关后发现,可以ping 通网关,但从外面无法ping通虚机
解决方法
-
初步怀疑:是linux把识别到的第一个网口配置作为优先级最高的配置,即把它的网关设置为默认网关
-
查看当前地址
-
查看当前地址
-
查看网卡配置文件
cd /etc/sysconfig/network-scripts/
发现多出几个配置文件,ifcfg-Wired_connection 这几个就是临时配置文件
而且缺少ens19配置文件, -
通过 nmcli con查看当前网卡连接配置
多出的几个就是临时连接
通过 systemctl restart network重启网络服务,临时连接就会丢失 -
发现重启失败
-
systemctl status network.service查看具体出错原因
-
centos系列一般原因为:
/etc/udev/rules.d/70-persistent-net.rules 文件里的MAC地址和 /etc/sysconfig/network-scripts/ifcfg-xxx的MAC地址不一样
或者
找不到配置文件 -
拷贝ens18配置文件到ens19
cp ifcfg-ens18 ifcfg-ens19
修改18/19配置文件,注意MAC、UUID -
通过nmcli con查看UUID,ip addr 查看MAC地址
-
发现设备ens18/19使用的配置文件均为临时配置文件,删除掉临时配置文件
[root@localhost network-scripts]# rm -f ifcfg-Wired_connection_1
[root@localhost network-scripts]# rm -f ifcfg-Wired_connection_2
[root@localhost network-scripts]# rm -f ifcfg-Wired_connection_3
[root@localhost network-scripts]# rm -f ifcfg-Wired_connection_4
[root@localhost network-scripts]# rm -f ifcfg-Wired_connection_5
[root@localhost network-scripts]# rm -f ifcfg-Wired_connection_6
[root@localhost network-scripts]# rm -f ifcfg-Wired_connection_7
- 重启网络管理组件及网络服务
[root@localhost network-scripts]# systemctl restart NetworkManager
[root@localhost network-scripts]# systemctl restart network
- 重启成功