The name of the CentOS 7 network card was changed to eth0

  • 2020-05-24 06:45:18
  • OfStack

Traditional naming methods for network card devices in Linux are eth0, eth1, eth2, etc., while CentOS7 provides different naming rules, which are assigned by default based on firmware, topology, and location information. This has the advantage of fully automatic and predictable naming, and the disadvantage of being harder to read than eth0 or wlan0, such as ens33.

1. Naming policy

Rule 1:

For onboard device naming merges the firmware or index number provided by BIOS, it is common to name if the information from the firmware or BIOS is readable, such as eno1, otherwise use rule 2.

Rule 2:

Name the merge firmware or PCI-E hotplug index number provided by BIOS, such as ens1, if the information is readable, otherwise use rule 3.

Rule 3:

Name the physical location of the merged hardware interface, such as enp2s0, which can be named, and the failure goes directly to scheme 5.

Rule 4:

Named merge MAC address of the interface, such as enx78e7d1ea46da, by default, do not use unless users choose to use this solution.

Rule 5:

Use a traditional scheme, and if all schemes fail, use a style like eth0.

2. Network card name character meaning

1. The meaning of the first two characters

en Ethernet Ethernet wl wireless LAN WLAN ww wireless wide area network WWAN

2. The third character is selected according to the device type


o<index>      on-board device index number
s<slot>      hotplug slot index number
x<MAC>       MAC address
p<bus>s<slot>   PCI geographical location
p<bus>s<slot>   USB port number chain
 

3. Change the name style of network card to ethx

If you are not used to using the new naming rules, you can revert to the traditional naming method, edit the grub file, add two variables, and then regenerate the grub configuration file using grub2-mkconfig.

1. Edit the grub configuration file


vim /etc/sysconfig/grub  #  Is actually /etc/default/grub The soft connection 
#  for GRUB_CMDLINE_LINUX Variable increase 2 The details are as follows ( bold ) : 
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap net.ifnames=0 biosdevname=0 rhgb quiet"

2. Regenerate the grub configuration file


grub2-mkconfig -o /boot/grub2/grub.cfg

Then restart the Linux operating system, and you can see that the network card name has changed to eth0 through ip addr.

3, modify the network card configuration file

The original network card configuration file name is ifcfg-ens33, which needs to be modified to ethx and the network card configuration file should be adjusted appropriately.


mv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0
#  Modify the ifcfg-eth0 The file is as follows ( Everything else is the same )
NAME=eth0
DEVICE=eth0
[root@localhost ~]# systemctl restart network.service  #  Restart the network service 

Note: the ifcfg-ens33 file had better be deleted, otherwise an error will be reported when restarting the network service.


Related articles: