VMware Cloud Community
tsrini
Contributor
Contributor

Interface MAC swapping issue in CentOS

Hi Team,

We are using ESXi 6.5 host machine with 4 physical NICs (4 VMNetworks with 4 vSwitch). On this host, we are launching a CentOS 7.6 VM with 4 NICs with 1 - 1 mapping.

Say as below,

During VM creation (created with manual MACs)

Network Adapter vNIC1 (MAC M1) -> Physical NIC1

Network Adapter vNIC2 (MAC M2) -> Physical NIC2

Network Adapter vNIC3 (MAC M3) -> Physical NIC3

Network Adapter vNIC4 (MAC M4) -> Physical NIC4

After VM creation before Power On, it gets swapped as below,

Network Adapter vNIC1 (MAC M4) -> Physical NIC4

Network Adapter vNIC2 (MAC M3) -> Physical NIC3

Network Adapter vNIC3 (MAC M2) -> Physical NIC2

Network Adapter vNIC4 (MAC M1) -> Physical NIC1

We would need to use ethX naming and hence we will convert the ensX/enpX interface naming to tradition ethX.

To do this, inside VM, we will ask (from a script) user to configure the MAC address for eth0, eth1, eth2 and eth3 (say M1, M2, M3 & M4 is configured respectively by the user). We need to persist the MAC & interface mapping consistent across reboots. The /etc/sysconfig/network-scripts/ifcfg-* files are updated appropriately with the name & MAC address.

To do this, we tried the below options,

Using udev rules

1. Configured udev rules (/etc/udev/rules.d/70-persistent-ipoib.rules) based on the user input,

SUBSYSTEM=="net", ACTION=="remove", DRIVERS=="?*", ATTR{type}=="1", KERNEL=="eth*"

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="<M1>", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="<M2>", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="<M3>", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="<M4>", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"

2. Reboot the VM

3. Interfaces failed to rename with the error,

...error changing net interface name eth0 to eth1: File exists...

Even tried with ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules

These steps was working in hardware & VM based on KVM. Issue was noticed in Vmware VMs.

Tried even renaming the interfaces to a temporary names using udev rules, say like, ens01 -> net0 and then from net0 -> eth0. In this, ens01 -> net0 worked but net0 -> eth0 didn't work and end up with the same error (error changing net interface.. file exists).

Using systemd.links

1. Removed the above udev rules

2. Configured [1-4].link files in /etc/systemd/network with below mapping,

[Match]

MACAddress=M1

[Link]

Name=eth0

3. Rebooted the VM.

4. Interfaces failed to rename.

We tried all above options with & without kernel parameters net.ifnames=0 biosdevname=0. Nothing worked out.

Can someone help us on this to persistent the MAC -> interface name mapping and consistent across all reboots.

Regards,

Srini

Tags (1)
Reply
0 Kudos
0 Replies