Change the network card name to the traditional naming rule of CentOS6 in CentOS/RHEL7 environment

Picture

picture

Introduction to CentOS/RHEL7 network card naming rules

Picture

picture

The traditional naming method of Linux server network cards is from eth0, eth1, eth2…. However, this number often does not necessarily correspond to the physical order of the network card interfaces. In regular mode, the server equipment we use may only have One network card. If there are many network cards, there may be a problem of network card disorder.

Starting with CentOS/RHEL7, predictable naming rules become the default, whereby interface names are automatically determined based on firmware, topology, and location information. Even if network devices are added or removed, the interface name can remain fixed without re-enumeration, and replaced hardware can be seamlessly replaced.

There are currently two new naming rules: Biosdevname & amp; net.ifnames.

By default, systemd uses the following strategy to name interfaces using supported naming schemes:

  • Option 1: If the firmware or BIOS information is applicable and available, use the name of the firmware or BIOS that incorporates the index number for the onboard device (for example: eno1), otherwise use Option 2.
  • Option 2: If the firmware or BIOS information is applicable and available, use the firmware or BIOS name that incorporates the index number for the PCI Express Hot Plug slot (for example, ens1), otherwise use Option 3.
  • Option 3: If hardware connector physical location information is available, use a name that incorporates that information (for example: enp2s0), otherwise use Option 5.
  • Option 4: The name of the integrated interface MAC address is not used by default (for example: enx78e7d1ea46da), but the user can choose to use this option.
  • Option 5: Traditional unpredictable kernel naming scheme, used when all else fails (example: eth0).

This policy (described above) is the default policy. This scheme will be used if biosdevname is enabled on the system. Note: To enable biosdevname, you need to add biosdevname=1 as a kernel command line parameter (except for Dell systems). At this time, as long as biosdevname is installed, this scheme will be used by default. If the user has added udev rules that change kernel device names, these rules will take precedence.

Understand the device renaming process

The device naming process is as follows:

1. The rules in the /usr/lib/udev/rules.d/60-net.rules file will make the udev help tool /lib/udev/rename\_device view all /etc/sysconfig/network -scripts/ifcfg-suffix file. If it finds an ifcfg file containing a HWADDR entry that matches the MAC address of an interface, it renames the interface to the name given by the DEVICE directive in the ifcfg file.

2. The rules in /usr/lib/udev/rules.d/71-biosdevname.rules let biosdevname rename the interface according to its naming policy, that is, the interface was not renamed in the previous step, biosdevname has been installed, and in boot Give biosdevname=0 as the kernel command on the command line.

3. The rules in /lib/udev/rules.d/75-net-description.rules allow udev to fill in the internal udev device attribute value ID by checking the network interface device. \_NET\_NAME\_ONBOARD, ID\_NET\_NAME\_SLOT, ID\_NET\_NAME\_PATH. NOTE: Some device properties may be undefined.

4. The rules in /usr/lib/udev/rules.d/80-net-name-slot.rules let udev rename the interface. The priority order is as follows: ID\_NET\_NAME\_ONBOARD, ID\_NET\_NAME\ _SLOT,ID\_NET\_NAME\_PATH. And provide the following information: The interface was not renamed in step 1 or 2, and the kernel parameter net.ifnames=0 was not given. If a parameter is not set, the next one in the order of the list is set. If no parameters are set, the interface will not be renamed.

Steps 3 and 4 use the naming rules 1, 2, and 3, and you can choose option 4.

Use BIOSDVNAME to keep network device naming consistent

Implementing this feature through the biosdevname udev helper will change all embedded network interface names, PCI card network interface names, and virtual function network interface names of existing eth[0123…] to new names specification.

biosdevname naming convention

Picture

picture

System Requirements

The biosdevname program uses information from the system BIOS, specifically contained in SMBIOS. type 9 (system slot) and type 41 (onboard device extension information) fields. If the system’s BIOS does not have SMBIOS version 2.6 or later and this data, the new naming convention will not be used. Most older hardware does not support this feature due to a lack of BIOS and field information with the correct SMBIOS version.

The biosdevname package must be installed to use this feature. To install this package, run the following command as the root user:

yum install biosdevname

Enable and disable this feature

To disable this feature, use the following option on the boot command line during and after installation:

biosdevname=0

To enable this feature, use the following options on the boot command line during and after installation:

biosdevname=1

Unless the system meets the minimum requirements, this option is ignored and the systemd naming scheme is used.

If the biosdevname installation option is specified, it must be used as a boot option during the lifetime of the system.

Control network device name selection

Device naming can be controlled as follows:

Device identification based on network interface

Use the HWADDR directive in the ifcfg file to set the MAC address so it can be recognized by udev. The name is extracted from the string provided by the DEVICE directive and by convention should use the same suffix as ifcfg. For example: ifcfg-eth0.

By turning biosdevname on or off

The name provided by biosdevname can be used if biosdevname can be determined.

By turning systemd-udev’s naming scheme on or off

The name provided by systemd-udev can be used if systemd-udev can determine it.

Disable consistent network device naming:

Please choose one of the following methods to disable consistent network device naming:

1. By blocking the udev rule file in the default policy, it is forbidden to assign fixed names so that unexpected kernel names can be reused. “Shielding” can be accomplished by generating a symbolic link for /dev/null. Please run the following command as root user:

ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules

2. Create your own manual naming scheme. For example: name the interface “internet0”, “dmz0”, or “lan0”. To create your own udev rules file and set the NAME attribute for those devices. Make sure to use the default policy file before using it. For example: name it /etc/udev/rules.d/70-my-net-names.rules.

3. Modify the policy file to select a different naming scheme. For example: By default all interfaces are named based on their MAC address. As root, copy the default policy file as follows:

cp /usr/lib/udev/rules.d/80-net-name-slot.rules /etc/udev/rules.d/80-net-name-slot.rules

4. Edit the file in the /etc/udev/rules.d/ directory and modify it as needed.

Add the following directive to the kernel command line in the GRUB 2 menu

net.ifnames=0

To update all GRUB 2 kernel menu entries, enter the following command as the root user:

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

PS: The above content is quoted from the official Redhat article, with some modifications:

https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/networking_guide/ch-consistent_network_device_naming

What should I do if I want to use the old way to name the network card?

Picture

picture

The above introduces the naming rules of CentOS/RHEL7, but in some application scenarios, customers still need to use the naming rules of CentOS6 under the CentOS/RHEL7 system. However, in this case, CentOS/RHEL7 cannot support it well. There is a high probability that it will not be supported by CentOS/RHEL7. Out-of-order problems will occur;

The general approach is as follows:

We need to manually modify the grub file and add net.ifnames=0 biosdevname=0

GRUB_CMDLINE_LINUX="CRASHKERNEL=auto net.ifnames=0 biosdevname=0 rhgb quiet"

Then execute:

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

Restart the system

Then add udev rules:

Create a network card rule “70-persistent-net.rules” in the “/etc/udev/rules.d” directory and write the following statement:

SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{type}=="1" ,KERNEL=="0000:08:00.1",NAME="eth0 "
SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{type}=="1" ,KERNEL=="0000:08:00.2",NAME="eth1"
SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{type}=="1" ,KERNEL=="0000:58:00.1",NAME="eth2"
SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{type}=="1" ,KERNEL=="0000:58:00.2",NAME="eth3"</ pre>
<p>The method of obtaining busid is (the same applies to other network cards):</p>
<pre>ethtool -i eth0
bus-info:0000:58:00.0

But at this time the network card is still out of order:

Picture

picture

In one of my customer environments, there are 4 network ports (two network cards, one for Intel x722 and one for Broadcom Gigabit network card). The names eth0-eth3 cannot be used in the rules (invalid). The current guess is that it is due to the system There are certain configuration files with a higher priority than 70-persistent-net.rules (any naming after eth4 is not a problem).

Judging from Redhat’s official explanation, CentOS/RHEL7 no longer supports this naming method and does not provide relevant technical support.

We adopt a compromise method and adjust the driver loading sequence according to the different models of the customer’s actual machine network card configuration to solve the customer’s problem;

GRUB_CMDLINE_LINUX="CRASHKERNEL=auto net.ifnames=0 biosdevname=0 rdloaddriver=tg3 rdloaddriver=i40e rhgb quiet"

Picture

picture

In summary: If customers use CentOS/RHEL7 or above systems, we strongly recommend not to use the old method for naming network cards. If this method must be used, it is recommended to use different brands of network cards and adjust the loading order of the network card drivers to avoid problems.

Article reprinted Lenovo TSE technical documents

For more technical documents, please check 365 documentationicon-default.png?t=N7T8https://www.365doc.com.cn