Because of the new network card name naming method used in RHEL7, it is difficult to understand and remember the network card name. This paper introduces how to modify the network card name to the traditional eth0 naming method to define any network card as eth0.
Introducing the process of network card renaming
To modify the name of the network card, first we need to know the process of renaming the device of the linux network card. According to the official documents of Red Hat, the process of renaming the device is as follows:
A rule in /usr/lib/udev/rules.d/60-net.rules instructs the udev helper utility,/lib/udev/rename_device,to look into all /etc/sysconfig/networkscripts/ifcfg-suffix files.If it finds an ifcfg file with a HWADDR entry matching the MAC address of an interface it renames the interface to the name given in the ifcfg file by the DEVICE directive.
A rule in /usr/lib/udev/rules.d/71-biosdevname. rules instructs biosdevname to rename the interface according to its naming policy, provided that it was not renamed in a previous step, biosdevname is installed, and biosdevname=0 was not given as a kernel command on the boot command line.
A rule in /lib/udev/rules.d/75-net-description.rules instructs udev to fill in the internal udev device property values ID_NET_NAME_ONBOARD, ID_NET_NAME_SLOT, ID_NET_NAME_PATH, ID_NET_NAME_MAC by examining the network interface device.Note,that some device properties might be undefined.
A rule in /usr/lib/udev/rules.d/80-net-name-slot.rules instructs udev to rename the interface, provided that it was not renamed in step 1 or 2, and the kernel parameter net.ifnames=0 was not given, according to the following priority: ID_NET_NAME_ONBOARD,ID_NET_NAME_SLOT,ID _NET_NAME_PATH. It falls through to the next in the list, if one is unset. If none of these are set, then the interface will not be renamed.
Simple translation is as follows:
Rules in the /usr/lib/udev/rules.d/60-net.rules file cause the udev help tool/lib/udev/renamedevice to view all/etc/sysconfig/networkscripts/ifcfg-suffix files.If an ifcfg file containing an HWADDR entry is found to match the MAC address of an interface, it will rename the interface to the name given by the DEVICE directive in the ifcfg file.
The rules in /usr/lib/udev/rules.d/71-biosdevname.rules allow biosdevname to rename the interface according to its naming policy, provided that the interface was not renamed in the previous step, but biosdevname is installed and biosdevname=0 is given as a kernel command on the boot command line.
The rules in /lib/udev/rules.d/75-net-description.rules let udev fill in the internal udev device attribute values ID_NET_NAME_ONBOARD, ID_NET_NAME_SLOT, ID_NET_NAME_PATH by checking the network interface device.Note: Some device properties may be undefined.
The rules in /usr/lib/udev/rules.d/80-net-name-slot.rules cause udev to rename the interface in the following order of priority: ID_NET_NAME_ONBOARD, ID_NET_NAME_SLOT, ID_NET_NAME_PATH.That is, if the interface is not renamed in step 1 or 2 and the kernel parameter net.ifnames=0 is not given, the rename will follow this rule.When renamed according to this rule, if one parameter is not set, the next parameter is set in the order of the list.If no parameters are set, the interface will not be renamed.
Network Card Renaming Method
Based on the above description, you can rename the network card as described in step 1:
ifconfig command to view each network card's MAC address
[root@test01 ~]# ifconfig enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether 08:00:27:43:c1:1d txqueuelen 1000 (Ethernet) RX packets 233 bytes 43354 (42.3 KiB) 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 enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.56.102 netmask 255.255.255.0 broadcast 192.168.56.255 inet6 fe80::a00:27ff:fe56:9530 prefixlen 64 scopeid 0x20<link> ether 08:00:27:56:95:30 txqueuelen 1000 (Ethernet) RX packets 259 bytes 48117 (46.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 50 bytes 8735 (8.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 enp0s9: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.56.101 netmask 255.255.255.0 broadcast 192.168.56.255 inet6 fe80::a00:27ff:fea5:4fd prefixlen 64 scopeid 0x20<link> ether 08:00:27:a5:04:fd txqueuelen 1000 (Ethernet) RX packets 1213 bytes 131145 (128.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 771 bytes 86683 (84.6 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 0 (Local Loopback) RX packets 1220 bytes 105112 (102.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1220 bytes 105112 (102.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Thus, the MAC addresses of the network card are:
enp0s3: 08:00:27:43:c1:1d enp0s8: 08:00:27:56:95:30 enp0s9: 08:00:27:a5:04:fd
Here you will modify the corresponding relationship of the network card name as follows:
enp0s3: 08:00:27:43:c1:1d --eth0 enp0s8: 08:00:27:56:95:30 --eth1 enp0s9: 08:00:27:a5:04:fd --eth2 # Note: You can customize the relationship between each network card name, such as modifying enp0s8 to eth2 and enp0s9 to eth2.
Rename Network Card Profile
[root@test01 ~]# cd /etc/sysconfig/network-scripts/ [root@test01 network-scripts]# ls ifcfg-* ifcfg-enp0s3 ifcfg-lo [root@test01 network-scripts]# # If you do not have a network card profile, you can add it using the following commands [root@test01 network-scripts]# nmcli connection add type ethernet ifname enp0s8 con-name enp0s8 autoconnect yes //Successfully added connection'enp0s8'(71306055-0869-4125-955a-4b7959cc9226). [root@test01 network-scripts]# nmcli connection add type ethernet ifname enp0s9 con-name enp0s9 autoconnect yes //Successfully added connection'enp0s9'(9d5a3033-b478-4076-95b0-83e62aa62cbe). [root@test01 network-scripts]# ls ifcfg-* ifcfg-enp0s3 ifcfg-enp0s8 ifcfg-enp0s9 ifcfg-lo [root@test01 network-scripts]# mv ifcfg-enp0s3 ifcfg-eth0 [root@test01 network-scripts]# mv ifcfg-enp0s8 ifcfg-eth1 [root@test01 network-scripts]# mv ifcfg-enp0s9 ifcfg-eth2 [root@test01 network-scripts]# [root@test01 network-scripts]# ls ifcfg-* ifcfg-eth0 ifcfg-eth1 ifcfg-eth2 ifcfg-lo
Modify Network Card Profile
After modifying the configuration file name, modify or add HWADDR, DEVICE,NAME parameters to the configuration file.
[root@test01 network-scripts]# cat ifcfg-eth0 TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=eth0 --Modify here NAME=eth0 UUID=77c7f1b8-ddef-4d96-bf74-68ecedc99a1a DEVICE=eth0 --Modify here DEVICE=eth0 ONBOOT=yes IPADDR=192.168.56.10 PREFIX=24 HWADDR=08:00:27:43:c1:1d --Add here HWADDR
Modify all network card profiles as described above.
Copy configuration file 60-net.rules
[root@test01 network-scripts]# cp /usr/lib/udev/rules.d/60-net.rules /etc/udev/rules.d/
Restart the system to see the network card name
shutdown -r 0
With the above modifications, you can freely define the corresponding network card names for network cards with different MAC addresses. With HWADDR added to the configuration file, you only need to modify the configuration file name ifcfg-ethx and DEVICE=ethx,NAME=ethx.
[root@test01 ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether 08:00:27:43:c1:1d txqueuelen 1000 (Ethernet) RX packets 9 bytes 3788 (3.6 KiB) 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 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.56.102 netmask 255.255.255.0 broadcast 192.168.56.255 inet6 fe80::a00:27ff:fe56:9530 prefixlen 64 scopeid 0x20<link> ether 08:00:27:56:95:30 txqueuelen 1000 (Ethernet) RX packets 16 bytes 5825 (5.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 21 bytes 4149 (4.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.56.101 netmask 255.255.255.0 broadcast 192.168.56.255 inet6 fe80::a00:27ff:fea5:4fd prefixlen 64 scopeid 0x20<link> ether 08:00:27:a5:04:fd txqueuelen 1000 (Ethernet) RX packets 66 bytes 11712 (11.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 63 bytes 10460 (10.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0