Linux网卡配置问题

Linux网卡配置问题

背景

搭建实验环境时,由于实验环境在虚机网络内,配置规划ip和网关后发现,可以ping 通网关,但从外面无法ping通虚机

解决方法

  1. 初步怀疑:是linux把识别到的第一个网口配置作为优先级最高的配置,即把它的网关设置为默认网关

  2. 查看当前地址

  3. 查看当前地址
    在这里插入图片描述

  4. 查看网卡配置文件
    cd /etc/sysconfig/network-scripts/
    在这里插入图片描述
    发现多出几个配置文件,ifcfg-Wired_connection 这几个就是临时配置文件
    而且缺少ens19配置文件,

  5. 通过 nmcli con查看当前网卡连接配置
    在这里插入图片描述
    多出的几个就是临时连接
    通过 systemctl restart network重启网络服务,临时连接就会丢失

  6. 发现重启失败
    在这里插入图片描述

  7. systemctl status network.service查看具体出错原因
    在这里插入图片描述

  8. centos系列一般原因为:
    /etc/udev/rules.d/70-persistent-net.rules 文件里的MAC地址和 /etc/sysconfig/network-scripts/ifcfg-xxx的MAC地址不一样
    或者
    找不到配置文件

  9. 拷贝ens18配置文件到ens19
    cp ifcfg-ens18 ifcfg-ens19
    修改18/19配置文件,注意MAC、UUID

  10. 通过nmcli con查看UUID,ip addr 查看MAC地址
    在这里插入图片描述

  11. 发现设备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
  1. 重启网络管理组件及网络服务
[root@localhost network-scripts]# systemctl restart NetworkManager
[root@localhost network-scripts]# systemctl restart network
  1. 重启成功
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章