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

阳光穿透心脏的1/2处 2024-02-17 10:23 96阅读 0赞

原因

首先说明一下eth0 与 ens33的关系:
目前的主流网卡为使用以太网络协定所开发出来的以太网卡(Ethernet),因此我们Linux就称呼这种网络接口为ethN(N为数字)。

举个栗子:就是说主机上面有一张以太网卡,因此主机的网络接口就是eth0(第一张为0号开始)。而从新的CentOS 7开始对于网卡的编号有另一套规则,网卡的界面代号于网卡的来源有关,网卡名称会是这样分类的:
eno1: 代表由主板BIOS内置的网卡
ens1: 代表由主板BIOS内置夫人PCI-E界面网卡
enp2s0: 代表PCI-E界面独立网卡,可能会由多个插孔,因此会有s0,s1…的编号
eth0: 如果上述的名称都不适用,就回到原本的默认网卡编号。
所以才会有ens33这种的网卡表现形式。

解决办法

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

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

具体操作如下:

  1. [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
  2. NAME=eth0 # 修改ens33为eth0
  3. DEVICE=eth0 # 修改ens33为eth0
  4. ONBOOT=yes # 修改no为yes
2、重命名网卡配置
  1. cd /etc/sysconfig/network-scripts/
  2. mv ifcfg-ens33 ifcfg-eth0
3、编辑 /etc/default/grub

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

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

  1. [root@localhost network-scripts]# vi /etc/default/grub
  2. GRUB_TIMEOUT=5
  3. GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
  4. GRUB_DEFAULT=saved
  5. GRUB_DISABLE_SUBMENU=true
  6. GRUB_TERMINAL_OUTPUT="console"
  7. GRUB_CMDLINE_LINUX="crashkernel=auto net.ifnames=0 biosdevname=0 spectre_v2=retpoline
  8. 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配置并更新内核参数。

  1. [root@localhost network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfg
  2. Generating grub configuration file ...
  3. Found linux image: /boot/vmlinuz-3.10.0-1127.el7.x86_64
  4. Found initrd image: /boot/initramfs-3.10.0-1127.el7.x86_64.img
  5. Found linux image: /boot/vmlinuz-0-rescue-ece52f273aa045ad8822b6197e4910d0
  6. Found initrd image: /boot/initramfs-0-rescue-ece52f273aa045ad8822b6197e4910d0.img
  7. done
5、重启系统
  1. [root@localhost network-scripts]# reboot
6、检查配置
  1. [root@localhost ~]# ifconfig
  2. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  3. inet 192.168.182.130 netmask 255.255.255.0 broadcast 192.168.182.255
  4. inet6 fe80::4347:403c:4dc4:2f0c prefixlen 64 scopeid 0x20<link>
  5. ether 00:0c:29:18:b9:3f txqueuelen 1000 (Ethernet)
  6. RX packets 60 bytes 6530 (6.3 KiB)
  7. RX errors 0 dropped 0 overruns 0 frame 0
  8. TX packets 76 bytes 11742 (11.4 KiB)
  9. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  10. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  11. inet 127.0.0.1 netmask 255.0.0.0
  12. inet6 ::1 prefixlen 128 scopeid 0x10<host>
  13. loop txqueuelen 1000 (Local Loopback)
  14. RX packets 48 bytes 4080 (3.9 KiB)
  15. RX errors 0 dropped 0 overruns 0 frame 0
  16. TX packets 48 bytes 4080 (3.9 KiB)
  17. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  18. virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
  19. inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
  20. ether 52:54:00:41:2d:f8 txqueuelen 1000 (Ethernet)
  21. RX packets 0 bytes 0 (0.0 B)
  22. RX errors 0 dropped 0 overruns 0 frame 0
  23. TX packets 0 bytes 0 (0.0 B)
  24. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

发表评论

表情:
评论列表 (有 0 条评论,96人围观)

还没有评论,来说两句吧...

相关阅读