Linux网卡没有eth0显示ens33原因以及解决办法

原因

首先说明一下eth0 与 ens33的关系:

目前的主流网卡为使用以太网络协定所开发出来的以太网卡(Ethernet),因此我们Linux就称呼这种网络接口为ethN(N为数字)。

举个栗子:就是说主机上面有一张以太网卡,因此主机的网络接口就是eth0(第一张为0号开始)。而从新的CentOS 7开始对于网卡的编号有另一套规则,网卡的界面代号于网卡的来源有关,网卡名称会是这样分类的:

eno1: 代表由主板BIOS内置的网卡

ens1: 代表由主板BIOS内置夫人PCI-E界面网卡

enp2s0: 代表PCI-E界面独立网卡,可能会由多个插孔,因此会有s0,s1...的编号

eth0: 如果上述的名称都不适用,就回到原本的默认网卡编号。

所以才会有ens33这种的网卡表现形式。

解决办法

1、编辑网卡的配置文件
vi /etc/sysconfig/network-scripts/ifcfg-ens33 

将里面的NAME和DEVICE项修改为eth0,ONBOOT需修改为yes

具体操作如下:

bash 复制代码
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33

NAME=eth0 # 修改ens33为eth0
DEVICE=eth0 # 修改ens33为eth0
ONBOOT=yes  # 修改no为yes
2、重命名网卡配置
bash 复制代码
cd /etc/sysconfig/network-scripts/ 
bash 复制代码
mv ifcfg-ens33 ifcfg-eth0  
3、编辑 /etc/default/grub

加入"net.ifnames=0 biosdevname=0"到GRUBCMALINELINUX变量中

你可以直接复制粘贴下面的内容

bash 复制代码
[root@localhost network-scripts]# vi /etc/default/grub  

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto net.ifnames=0 biosdevname=0 spectre_v2=retpoline
 rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"GRUB_DISABLE_RECOVERY="true"
4、重新生成GRUB配置并更新内核参数

运行命令 grub2-mkconfig -o /boot/grub2/grub.cfg 来重新生成GRUB配置并更新内核参数。

bash 复制代码
[root@localhost network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfg  
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1127.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1127.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-ece52f273aa045ad8822b6197e4910d0
Found initrd image: /boot/initramfs-0-rescue-ece52f273aa045ad8822b6197e4910d0.img
done
5、重启系统
bash 复制代码
[root@localhost network-scripts]# reboot
6、检查配置
bash 复制代码
[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.182.130  netmask 255.255.255.0  broadcast 192.168.182.255
        inet6 fe80::4347:403c:4dc4:2f0c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:18:b9:3f  txqueuelen 1000  (Ethernet)
        RX packets 60  bytes 6530 (6.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 76  bytes 11742 (11.4 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 1000  (Local Loopback)
        RX packets 48  bytes 4080 (3.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 48  bytes 4080 (3.9 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:41:2d:f8  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
相关推荐
saynaihe35 分钟前
2025吐槽季第一弹---腾讯云EO边缘安全加速平台服务
运维·安全·云计算·腾讯云
@#---42 分钟前
删除驱动精灵的详细过程
运维·服务器
boy快快长大1 小时前
【Elasticsearch】同一台服务器部署集群
服务器·elasticsearch·jenkins
likeyou~coucou1 小时前
自动化之ansible(二)
运维·自动化·ansible
小红帽2.01 小时前
客服系统自动化方案:揭秘全渠道智能服务解决方案 vx: haotsh
运维·自动化
reset20212 小时前
ubuntu离线安装ollama
linux·ubuntu·ollama
放氮气的蜗牛2 小时前
Linux命令终极指南:从入门到精通掌握150+核心指令
linux·运维·服务器
网络安全King2 小时前
devops 工具 网络安全
运维·web安全·devops
梁萌2 小时前
04-DevOps-安装并初始化Jenkins
运维·jenkins·devops
DC_BLOG2 小时前
Linux-Ansible模块进阶
linux·运维·服务器·ansible