Question:
I would like to find a way to have the HWADDR line in the ifcfg-eth0 script verify/update itself on-boot in case it changes when a clone or copy of the VM occurs. Is there a way to do so? In CentOS 6, removing the HWADDR line from the ifcfg-eth0 script made it much more dynamic, but I have yet to find a way to keep ifcfg-eth0 from changing back to ifcfg-eno1677776 without the HWADDR line in CentOS 7. Thanks in advance for the help!
Background:
I am running a CentOS 7.2.1511 virtual machine via VMware Workstation. By default CentOS 7 got rid of the eth0 naming convention of its network scripts and is now configured to use network scripts named ifcfg-eno1677776 or something similar. I have software that heavily relies on the eth0 naming scheme. So I have re-configured my ifcfg-eno1677776 script by:
- Renaming
/etc/sysconfig/network-scripts/ifcfg-eno1677776
to/etc/sysconfig/network-scripts/ifcfg-eth0
-
Modifying ifcfg-eth0 to be (got HWADDR from
/sys/class/net/eno1677776/address
):BOOTPROTO=dhcp
NAME=eth0
DEVICE=eth0
ONBOOT=yes
NM_CONTROLLED=no
HWADDR=00:0c:29:d6:d2:65 -
Added net.ifnames=0 to the end of the GRUB_CMDLINE_LINUX line in the
/etc/sysconfig/grub
file. -
Reboot and run ifconfig (and celebrate!):
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.176.15.148 netmask 255.255.252.0 broadcast 10.176.15.255
inet6 fe80::20c:29ff:fed6:d265 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d6:d2:65 txqueuelen 1000 (Ethernet)
RX packets 2141073 bytes 749959853 (715.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 65237 bytes 35352127 (33.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Each time I boot, this eth0 interface remains. However, this VM is to be distributed between team members and eventually delivered to customers. This is where the problem arises. VMware is great in that you can clone a snapshot of a VM for distribution, but this changes the MAC address of the VM.
EDIT:
You must run grub2-mkconfig -o /boot/grub2/grub.cfg
after making the change @larsks recommended below for it to work. Worked for me!
Best Answer
The easiest solution is probably to disable the "predictable device naming" behavior by setting the following options on your kernel command line:
With this in place, the first ethernet interface on your system will be named
eth0
, the second will beeth1
, etc. This is documented here.With this in place, just remove the
HWADDR
line from your configuration file and everything should work as you expect.