Page 1 of 2

MAC Address changes between interfaces during each reboot in centos 7.6

Posted: 2019/05/07 10:44:17
by tsrini
We have tried to rename the interfaces from default naming to traditional ethX style using the following approaches.

Approach 1
1) Added net.ifnames=0 biosdevname=0 in /etc/default/grub and ran grub2-mkconfig
2) renamed /etc/sysconfig/network-scripts/ifcfg-en* files to /etc/sysconfig/network-scripts/ifcfg-eth*
3) changed the NAME and DEVICE to eth0 /etc/sysconfig/network-scripts/ifcfg-eth0, NAME and DEVICE to eth1 /etc/sysconfig/network-scripts/ifcfg-eth1 - etc

Approach 2
1) Added net.ifnames=0 in /etc/default/grub and ran grub2-mkconfig
2) Added HWADDR in /etc/sysconfig/network-scripts/ifcfg-eth* files
3) Instead of HWADDR, tried by setting MACADDR in ifcfg-eth* files

Approach 3
1) Added net.ifnames=0 in /etc/default/grub and ran grub2-mkconfig
2) Added the following udev rules in /etc/udev/rules.d/60-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="mac1", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="mac2", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="mac3", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="mac4", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"

In this approach we could see the following erros in systemd-udev.service status.
Apr 20 05:32:38 HOSTNAME systemd-udevd: error changing net interface name eth0 to eth1: File exists
Apr 20 05:32:38 HOSTNAME systemd-udevd: error changing net interface name eth1 to eth0: File exists

The MAC addresses are getting swapped between interfaces during each reboot. Couldn't get any solution from Internet.

Is there any approach available to have permanent MAC Addr & interface name mapping across reboots.

Re: MAC Address changes between interfaces during each reboot in centos 7.6

Posted: 2019/05/07 10:53:45
by tunk
I had to change the name of one interface, and I did it in /etc/udev/rules.d/70-persistent-ipoib.rules:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="01:12:23:34:45:56", ATTR {type}=="1", KERNEL=="eth*", NAME="public"

Link: https://www.schrodinger.com/kb/1649

Re: MAC Address changes between interfaces during each reboot in centos 7.6

Posted: 2019/05/07 11:52:21
by tsrini
tunk wrote:
2019/05/07 10:53:45
I had to change the name of one interface, and I did it in /etc/udev/rules.d/70-persistent-ipoib.rules:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="01:12:23:34:45:56", ATTR {type}=="1", KERNEL=="eth*", NAME="public"

Link: https://www.schrodinger.com/kb/1649
This apporach only works in Centos 6 .

Re: MAC Address changes between interfaces during each reboot in centos 7.6

Posted: 2019/05/07 12:08:51
by tunk
Forgot to say it's on a 7.6 system.

Re: MAC Address changes between interfaces during each reboot in centos 7.6

Posted: 2019/05/07 12:16:49
by tsrini
This approach may work for system with single interface.But in our case system contains 4 interfaces.Have you tested with multiple interfaces?

Re: MAC Address changes between interfaces during each reboot in centos 7.6

Posted: 2019/05/07 13:21:14
by tunk
I've only changed one NIC (eth0), and HWADDR was added to the config file.
The other NIC (em4) was left unchanged (again with HWADDR).
networkmanager is disabled.

Re: MAC Address changes between interfaces during each reboot in centos 7.6

Posted: 2019/05/07 13:30:26
by tsrini
tunk wrote:
2019/05/07 13:21:14
I've only changed one NIC (eth0), and HWADDR was added to the config file.
The other NIC (em4) was left unchanged (again with HWADDR).
networkmanager is disabled.
In my case I want to change all the 4 interfaces.

Re: MAC Address changes between interfaces during each reboot in centos 7.6

Posted: 2019/05/07 13:34:24
by tunk
I don't know if it will work, but here's what I would try:
- disable networkmanager (if not already done)
- update /etc/udev/rules.d/70-persistent-ipoib.rules with the four NICs
- add HWADDR to the four config files

Re: MAC Address changes between interfaces during each reboot in centos 7.6

Posted: 2019/05/07 17:49:05
by aks
First remove all interfaces, then add.

Re: MAC Address changes between interfaces during each reboot in centos 7.6

Posted: 2019/05/08 11:12:55
by tsrini
Now it is working fine.

But there is a problem.These changes has to be done during installation process .We thought to rename the interfaces from ifcfg-en* to ifcfg-eth* based ip addr command or ifindex attribute.But it seems we can't rely on these methods.Is there any unique attribute that can be considered for correct order during the renaming process?