This topic describes how to resolve the network interface controller (NIC) drift issue that occurs on Linux Elastic Compute Service (ECS) instances that have multiple NICs.
Problem description
When you add a NIC to or remove a NIC from a Linux ECS instance that has multiple NICs during O&M, a mismatch may occur between the device names of the NICs in the Linux operating system and the corresponding media access control (MAC) addresses. This issue is referred to as a NIC drift.
ip addr
command to query NIC information, the MAC address of the eth2 NIC is displayed as the MAC address of the eth1 NIC, as shown in the following figure.
Cause
NIC information in the Linux operating system is stored in the /etc/udev/rules.d/70-persistent-net.rules file. If the file does not exist or the file contains incorrect information, a NIC drift may occur.
Solution
Before you perform high-risk operations, such as modifying the configurations or data of an Alibaba Cloud instance, check the disaster recovery and fault tolerance capabilities of the instance to ensure data security. We recommend that you create snapshots in advance. For information about snapshots, see Overview.
If you granted specific users the permissions on sensitive information, such as usernames and passwords, or submitted sensitive information in the Alibaba Cloud Management Console, we recommend that you modify the sensitive information at the earliest opportunity.
Modify the /etc/udev/rules.d/70-persistent-net.rules file in the Linux operating system to associate the device name of each NIC with the corresponding MAC address.
- Connect to the Linux ECS instance. For more information, see Connection method overview.
- Run the following command to go to the /etc/udev/rules.d directory:
cd /etc/udev/rules.d
- Run the following command to open the /etc/udev/rules.d/70-persistent-net.rules file:
vi 70-persistent-net.rules
- Run the following command to associate the device name of each NIC with the corresponding MAC address:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="<MAC address of the NIC>", KERNEL=="eth*", NAME="<Device name of the NIC>"
For example, to associate the eth1 NIC with MAC address 00:16:3e:10:bd:1b, run the following command:SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:3e:10:bd:1b", KERNEL=="eth*", NAME="eth1"
- Run the following command to query NIC configurations in the /etc/udev/rules.d/70-persistent-net.rules file:
cat 70-persistent-net.rules
The command output shown in the following figure is displayed.The command output indicates that the MAC address of the eth1 NIC is 00:16:3e:10:bd:1b and no NIC drift occurs.