Fix NIC-to-MAC-address mismatches after adding or removing NICs on a multi-NIC Linux ECS instance.
Symptom
Adding or removing a NIC on a multi-NIC Linux ECS instance may cause a mismatch between NIC device names and their media access control (MAC) addresses. This mismatch is called a NIC drift.
ip addr shows eth1 with the MAC address of eth2, indicating a NIC drift.
Cause
NIC information is stored in /etc/udev/rules.d/70-persistent-net.rules. A NIC drift occurs when this file is missing or contains incorrect entries.
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.
Edit /etc/udev/rules.d/70-persistent-net.rules to bind each NIC device name to its correct MAC address.
- Connect to the Linux ECS instance.
-
Go to the /etc/udev/rules.d directory:
cd /etc/udev/rules.d -
Open the /etc/udev/rules.d/70-persistent-net.rules file:
vi 70-persistent-net.rules -
Bind each NIC device name to its 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 bind eth1 to MAC address 00:16:3e:10:bd:1b:SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:3e:10:bd:1b", KERNEL=="eth*", NAME="eth1" -
Verify the NIC configurations in /etc/udev/rules.d/70-persistent-net.rules:
cat 70-persistent-net.rulesExpected output:
The output confirms that eth1 maps to MAC address 00:16:3e:10:bd:1b. No NIC drift occurs.