RHEL 7网卡默认命名规则:以太网卡(Ethernet)为enX,无线网卡(WLAN)为wlX,修改网卡命名规则为ethX如下:

1、修改/etc/sysconfig/grub文件,添加net.ifnames=0 biosdevname=0

点击(此处)折叠或打开

  1. [root@rhel73-std ~]# cat /etc/sysconfig/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 rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet"
  8. GRUB_DISABLE_RECOVERY="true"
  9. [root@rhel73-std ~]#

2、备份/boot/grub2/grub.cfg后,重新生层grub.cfg配置文件,使用命令:grub2-mkconfig -o /boot/grub2/grub.cfg

点击(此处)折叠或打开

  1. [root@rhel73-std ~]# cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.old 
  2. [root@rhel73-std ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
  3. Generating grub configuration file ...
  4. Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64
  5. Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img
  6. Found linux image: /boot/vmlinuz-0-rescue-59ad3ea4c90948209723894c6c92587b
  7. Found initrd image: /boot/initramfs-0-rescue-59ad3ea4c90948209723894c6c92587b.img
  8. done
  9. [root@rhel73-std ~]#

3、重命名网卡配置文件为ifcfg-ethX,修改配置文件中的name和device值,并删除配置文件中UUID行(重启后ethX的UUID数值不一致),然后重启服务器

点击(此处)折叠或打开

  1. [root@rhel73-std ~]# mv /etc/sysconfig/network-scripts/ifcfg-en33 /etc/sysconfig/network-scripts/ifcfg-eth0
  2. [root@rhel73-std ~]# mv /etc/sysconfig/network-scripts/ifcfg-en34 /etc/sysconfig/network-scripts/ifcfg-eth1
  3. [root@rhel73-std ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
  4. TYPE=Ethernet
  5. BOOTPROTO=none
  6. DEFROUTE=yes
  7. IPV4_FAILURE_FATAL=no
  8. IPV6INIT=yes
  9. IPV6_AUTOCONF=yes
  10. IPV6_DEFROUTE=yes
  11. IPV6_FAILURE_FATAL=no
  12. IPV6_ADDR_GEN_MODE=stable-privacy
  13. NAME=eth0
  14. DEVICE=eth0
  15. ONBOOT=yes
  16. IPADDR=192.168.254.120
  17. PREFIX=24
  18. IPV6_PEERDNS=yes
  19. IPV6_PEERROUTES=yes
  20. IPV6_PRIVACY=no
  21. [root@rhel73-std ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
  22. TYPE=Ethernet
  23. BOOTPROTO=dhcp
  24. DEFROUTE=yes
  25. PEERDNS=yes
  26. PEERROUTES=yes
  27. IPV4_FAILURE_FATAL=no
  28. IPV6INIT=yes
  29. IPV6_AUTOCONF=yes
  30. IPV6_DEFROUTE=yes
  31. IPV6_PEERDNS=yes
  32. IPV6_PEERROUTES=yes
  33. IPV6_FAILURE_FATAL=no
  34. IPV6_ADDR_GEN_MODE=stable-privacy
  35. NAME=eth1
  36. DEVICE=eth1
  37. ONBOOT=no
  38. [root@rhel73-std ~]# reboot

4、对比修改前和修改后

点击(此处)折叠或打开

  1. [root@rhel73-std ~]# ip addr
  2. 1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1
  3. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  4. inet 127.0.0.1/8 scope host lo
  5. valid_lft forever preferred_lft forever
  6. inet6 ::1/128 scope host
  7. valid_lft forever preferred_lft forever
  8. 2: ens33: mtu 1500 qdisc pfifo_fast state UP qlen 1000
  9. link/ether 00:0c:29:43:bd:56 brd ff:ff:ff:ff:ff:ff
  10. inet 192.168.254.120/24 brd 192.168.254.255 scope global ens33
  11. valid_lft forever preferred_lft forever
  12. inet6 fe80::4dda:101e:ccdd:882a/64 scope link
  13. valid_lft forever preferred_lft forever
  14. 3: ens34: mtu 1500 qdisc pfifo_fast state UP qlen 1000
  15. link/ether 00:0c:29:43:bd:60 brd ff:ff:ff:ff:ff:ff
  16. [root@rhel73-std ~]# ip a
  17. 1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1
  18. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  19. inet 127.0.0.1/8 scope host lo
  20. valid_lft forever preferred_lft forever
  21. inet6 ::1/128 scope host
  22. valid_lft forever preferred_lft forever
  23. 2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
  24. link/ether 00:0c:29:43:bd:56 brd ff:ff:ff:ff:ff:ff
  25. inet 192.168.254.120/24 brd 192.168.254.255 scope global eth0
  26. valid_lft forever preferred_lft forever
  27. inet6 fe80::6d3b:9b3c:81db:9d30/64 scope link
  28. valid_lft forever preferred_lft forever
  29. 3: eth1: mtu 1500 qdisc pfifo_fast state UP qlen 1000
  30. link/ether 00:0c:29:43:bd:60 brd ff:ff:ff:ff:ff:ff
  31. [root@rhel73-std ~]#
posted on 2017-06-27 16:58  John Liang  阅读(2198)  评论(0编辑  收藏  举报