RHEL 7网卡默认命名规则:以太网卡(Ethernet)为enX,无线网卡(WLAN)为wlX,修改网卡命名规则为ethX如下:
1、修改/etc/sysconfig/grub文件,添加net.ifnames=0 biosdevname=0
点击(此处)折叠或打开
- [root@rhel73-std ~]# cat /etc/sysconfig/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 rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet"
- GRUB_DISABLE_RECOVERY="true"
- [root@rhel73-std ~]#
2、备份/boot/grub2/grub.cfg后,重新生层grub.cfg配置文件,使用命令:grub2-mkconfig -o /boot/grub2/grub.cfg
点击(此处)折叠或打开
- [root@rhel73-std ~]# cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.old
- [root@rhel73-std ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
- Generating grub configuration file ...
- Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64
- Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img
- Found linux image: /boot/vmlinuz-0-rescue-59ad3ea4c90948209723894c6c92587b
- Found initrd image: /boot/initramfs-0-rescue-59ad3ea4c90948209723894c6c92587b.img
- done
- [root@rhel73-std ~]#
3、重命名网卡配置文件为ifcfg-ethX,修改配置文件中的name和device值,并删除配置文件中UUID行(重启后ethX的UUID数值不一致),然后重启服务器
点击(此处)折叠或打开
- [root@rhel73-std ~]# mv /etc/sysconfig/network-scripts/ifcfg-en33 /etc/sysconfig/network-scripts/ifcfg-eth0
- [root@rhel73-std ~]# mv /etc/sysconfig/network-scripts/ifcfg-en34 /etc/sysconfig/network-scripts/ifcfg-eth1
- [root@rhel73-std ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
- TYPE=Ethernet
- BOOTPROTO=none
- DEFROUTE=yes
- IPV4_FAILURE_FATAL=no
- IPV6INIT=yes
- IPV6_AUTOCONF=yes
- IPV6_DEFROUTE=yes
- IPV6_FAILURE_FATAL=no
- IPV6_ADDR_GEN_MODE=stable-privacy
- NAME=eth0
- DEVICE=eth0
- ONBOOT=yes
- IPADDR=192.168.254.120
- PREFIX=24
- IPV6_PEERDNS=yes
- IPV6_PEERROUTES=yes
- IPV6_PRIVACY=no
- [root@rhel73-std ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
- TYPE=Ethernet
- BOOTPROTO=dhcp
- DEFROUTE=yes
- PEERDNS=yes
- PEERROUTES=yes
- IPV4_FAILURE_FATAL=no
- IPV6INIT=yes
- IPV6_AUTOCONF=yes
- IPV6_DEFROUTE=yes
- IPV6_PEERDNS=yes
- IPV6_PEERROUTES=yes
- IPV6_FAILURE_FATAL=no
- IPV6_ADDR_GEN_MODE=stable-privacy
- NAME=eth1
- DEVICE=eth1
- ONBOOT=no
- [root@rhel73-std ~]# reboot
4、对比修改前和修改后
点击(此处)折叠或打开
- [root@rhel73-std ~]# ip addr
- 1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1
- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
- inet 127.0.0.1/8 scope host lo
- valid_lft forever preferred_lft forever
- inet6 ::1/128 scope host
- valid_lft forever preferred_lft forever
- 2: ens33: mtu 1500 qdisc pfifo_fast state UP qlen 1000
- link/ether 00:0c:29:43:bd:56 brd ff:ff:ff:ff:ff:ff
- inet 192.168.254.120/24 brd 192.168.254.255 scope global ens33
- valid_lft forever preferred_lft forever
- inet6 fe80::4dda:101e:ccdd:882a/64 scope link
- valid_lft forever preferred_lft forever
- 3: ens34: mtu 1500 qdisc pfifo_fast state UP qlen 1000
- link/ether 00:0c:29:43:bd:60 brd ff:ff:ff:ff:ff:ff
- [root@rhel73-std ~]# ip a
- 1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1
- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
- inet 127.0.0.1/8 scope host lo
- valid_lft forever preferred_lft forever
- inet6 ::1/128 scope host
- valid_lft forever preferred_lft forever
- 2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
- link/ether 00:0c:29:43:bd:56 brd ff:ff:ff:ff:ff:ff
- inet 192.168.254.120/24 brd 192.168.254.255 scope global eth0
- valid_lft forever preferred_lft forever
- inet6 fe80::6d3b:9b3c:81db:9d30/64 scope link
- valid_lft forever preferred_lft forever
- 3: eth1: mtu 1500 qdisc pfifo_fast state UP qlen 1000
- link/ether 00:0c:29:43:bd:60 brd ff:ff:ff:ff:ff:ff
- [root@rhel73-std ~]#