What do I do if NIC drifts occur on a Linux instance that has multiple NICs?

Updated at: 2024-07-30 10:37

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.

In this example, a NIC drift occurs on the Linux ECS instance that has the eth1 NIC whose MAC address is 00:16:3e:10:bd:1b and the eth2 NIC whose MAC address is 00:16:3e:0c:92:df. When you run the 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

Important
  • 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.

  1. Connect to the Linux ECS instance.
    For more information, see Connection method overview.
  2. Run the following command to go to the /etc/udev/rules.d directory:
    cd /etc/udev/rules.d
  3. Run the following command to open the /etc/udev/rules.d/70-persistent-net.rules file:
    vi 70-persistent-net.rules
  4. 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"
  5. 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.绑定网卡名称与网卡MAC地址

    The command output indicates that the MAC address of the eth1 NIC is 00:16:3e:10:bd:1b and no NIC drift occurs.

  • On this page (1, T)
  • Problem description
  • Cause
  • Solution
Feedback