Linux system operating system network card drift solution and problem causes

1. Problem description

The company has 100-150 servers to install RHEL7.4&Kirin 7.4 system. In order to facilitate editing and configuration of the network card, use the script method to configure biosname=0, ifname=0, the purpose is to standardize the name of the long character network card such as en1o2p to the traditional eth*, using the traditional network card identification method, but after the installation is complete, configure the IP, the BOND dual network card has a network drift phenomenon, the phenomenon is that after restarting the network card, all network ports have changed and the network is blocked

2. Principle description

  • There is a rule in /usr/lib/udev/rules.d/60-net.rules instructing the udev assistant utility /lib/udev/rename_device to view all /etc/sysconfig/network-scripts/ifcfg suffix files. If it finds that an ifcfg file with an HWADDR entry matches the MAC address of an interface, it renames the interface to the name given by the DEVICE instruction in the ifcfg file.
  • Instruct biosdevname in /usr/lib/udev/rules.d/71-biosdevname.rules to rename the interface according to its naming strategy, provided that the interface is not renamed in the previous steps, biosdevname is installed, and on the boot command line No biosdevname=0 is given as a kernel command.
  • The rules in /lib/udev/rules.d/75-net-description.rules instruct udev to fill in the internal udev device attribute values ​​id_net_name_board, ID_NET_NAME_SLOT, ID_NET_NAME_PATH, ID_NET_NAME_MAC by checking the network interface device. Note that some device attributes may be undefined.
  • There is a rule in /usr/lib/udev/rules.d/80-net-name-slot.rules instructing udev to rename the interface (provided that the interface is not renamed in step 1 or 2) and kernel parameters net. According to the following priority: id_net_name_board, ID_NET_NAME _SLOT, ID_NET_NAME_PATH, ifnames=0 is not specified. If one of them is not set, it will go to the next one in the list. If these parameters are not set, the interface will not be renamed.
    Step 2 actually executes the policy of biosdevname Steps 3 and 4 actually execute Scheme 1, 2, 3

3. Processing steps

Since in the actual scenario, the configuration of biosdevname=0 ifname=0 is used, the actual affected file is the /usr/lib/udev/rules.d/60-net.rules file, which is then used in the configuration file The following settings:
Linux system operating system network card drift solution and problem causes

After using this setting, the RHEL7.4 system problem is completely solved. After nearly 20 tests, the network port will not drift. However, in the bid-winning Kylin 7.4 system, after using the secondary configuration, there will be no drift when the network port status remains unchanged, but if one of the network ports is randomly unplugged, all the network ports will be changed and
then use the udevadm test command. Test, this command can backtrack which strategy is effective according to the name of the network card. From the output result, the RHEL7.4&Successful Kylin 7.4 system all show that the 60-rules rule has taken effect, but there is still a drift problem in the winning Kylin. After document query and further replacement test, it is basically determined that this problem is caused by system differences

Four. Solution

When using systemd naming rules, the network card name is similar to en1o2p3. This command can accurately indicate which PCI slot and bus on the motherboard the network card comes from, and the specific port. Although the systemd naming method is not readable, it is a change made to solve this problem. It is recommended to use the long format network card name in the same systemd method.
The restore script is as follows:

#! /bin/bash
#  redhat还原脚本
cd /etc/sysconfig/network-scripts/
mv ifcfg- bak/
mv ifcfg-eth* bak/
mv ifcfg-bond0 bak/
cd /etc/sysconfig
cp grub  /home/grub.bak
sed -i "s/ net.ifnames=0/ /g" grub
sed -i "s/ biosdevname=0/ /g" grub
grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
cd /boot/efi/EFI/redhat/
cp grub.cfg /home/grub.cfg.bak
sed -i "s/ net.ifnames=0/ /g" grub.cfg
sed -i "s/ biosdevname=0/ /g" grub.cfg
sleep 5
sync
sync
sync
reboot
#! /bin/bash
# 中标麒麟还原脚本
cd /etc/sysconfig/network-scripts/
mv ifcfg- bak/
mv ifcfg-eth* bak/
mv ifcfg-bond0 bak/
cd /etc/sysconfig
cp grub  /home/grub.bak
sed -i "s/net.ifnames=0/ /g" grub
sed -i "s/biosdevname=0/ /g" grub
grub2-mkconfig -o /boot/efi/EFI/neokylin/grub.cfg
cd /boot/efi/EFI/neokylin/
cp grub.cfg /home/grub.cfg.bak
sed -i "s/ net.ifnames=0/ /g" grub.cfg
sed -i "s/ biosdevname=0/ /g" grub.cfg
sleep 5
sync
sync
sync
reboot

Please indicate the source of reprinting:
1. The copyright of the original article marked in the blog belongs to the original author heardic;
2. The content of this article may not be reprinted without the permission of the original author, otherwise it will be regarded as an infringement;
3. The source of the reprint or quotation of this article should be indicated And the original author;
4. I reserve the right to pursue investigations for those who do not comply with this statement or use the content of this article illegally.

Guess you like

Origin blog.51cto.com/13906754/2595685