linux CentOS 7网卡ens33修改为eth0

r囧r小猫 2023-10-05 17:58 37阅读 0赞

linux CentOS7的网卡ens33修改为eth0

  • Linux 操作系统的网卡设备的传统命名方式是 eth0、eth1、eth2等,而 CentOS7 提供了不同的命名规则,默认是基于固件、拓扑、位置信息来分配。这样做的优点是命名全自动的、可预知的,缺点是比 eth0、wlan0 更难读,比如 ens33 。
  • 如果不习惯使用新的命名规则,可以恢复使用传统的方式命名

1、先编辑网卡的配置文件将里面的NAME, DEVICE项修改为eth0

  1. vim /etc/sysconfig/network-scripts/ifcfg-ens33
  2. NAME=eth0 //修改为eth0
  3. ...
  4. DEVICE=eth0 //修改为eth0
  1. 把网卡配置文件改为 ifcfg-eth0

    [root@localhost ~]# cd /etc/sysconfig/network-scripts/
    [root@localhost network-scripts]# mv ifcfg-ens33 ifcfg-eth0

  2. 禁用该可预测命名规则。

    • 你可以在启动时传递“net.ifnames=0 biosdevname=0 ”的内核参数。
    • 这是通过编辑/etc/default/grub并加入“net.ifnames=0 biosdevname=0 ”到GRUBCMDLINELINUX变量来实现。

编辑 grub 配置文件

  1. [root@mysql ~]# 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 rd.lvm.lv=centos/root rd.lvm.lv=centos/swap net.ifnames=0 biosdevname=0 rhgb quiet"
  8. ' /在上面添加 "net.ifnames=0 biosdevname=0" '
  9. GRUB_DISABLE_RECOVERY="true"
  1. 运行命令grub2-mkconfig -o /boot/grub2/grub.cfg 来重新生成GRUB配置并更新内核参数。

    [root@mysql ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

  2. 重启网络服务会报错,重启linux系统就好了

    systemctl restart network

  3. 重新启动linux系统,重启后通过ipaddr 或者ifconfig命令验证

    reboot

可以看到网卡改为eth0

  1. [root@client1 ~]# ifconfig
  2. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  3. inet 20.0.0.13 netmask 255.255.255.0 broadcast 20.0.0.255
  4. inet6 fe80::6d44:3c07:4465:144f prefixlen 64 scopeid 0x20<link>
  5. ether 00:0c:29:6a:e9:5c txqueuelen 1000 (Ethernet)
  6. RX packets 163 bytes 220240 (215.0 KiB)
  7. RX errors 0 dropped 0 overruns 0 frame 0
  8. TX packets 146 bytes 12383 (12.0 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 1 (Local Loopback)
  14. RX packets 12 bytes 1404 (1.3 KiB)
  15. RX errors 0 dropped 0 overruns 0 frame 0
  16. TX packets 12 bytes 1404 (1.3 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:14:ad:d1 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

ping www.baidu.com

  1. [root@client1 ~]# ping www.baidu.com
  2. PING www.wshifen.com (103.235.46.39) 56(84) bytes of data.
  3. 64 bytes from 103.235.46.39 (103.235.46.39): icmp_seq=1 ttl=128 time=412 ms
  4. 64 bytes from 103.235.46.39 (103.235.46.39): icmp_seq=3 ttl=128 time=330 ms
  5. 64 bytes from 103.235.46.39 (103.235.46.39): icmp_seq=4 ttl=128 time=349 ms

发表评论

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

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

相关阅读