3

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:

  1. Renaming /etc/sysconfig/network-scripts/ifcfg-eno1677776 to /etc/sysconfig/network-scripts/ifcfg-eth0
  2. 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

  3. Added net.ifnames=0 to the end of the GRUB_CMDLINE_LINUX line in the /etc/sysconfig/grub file.

  4. 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!

migrated from stackoverflow.com Nov 4 '16 at 13:24

This question came from our site for professional and enthusiast programmers.

4

The easiest solution is probably to disable the "predictable device naming" behavior by setting the following options on your kernel command line:

biosdevname=0 net.ifnames=0

With this in place, the first ethernet interface on your system will be named eth0, the second will be eth1, 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.

  • Thanks for the advice @larsks although this doesn't seem to work for me. Removing the HWADDR line from my eth0 network interface file brings back the "eno" named network interface when I reboot and run ifconfig regardless of the "biosdevname" change. I will continue to look at the link you sent me and see if I can get anything from there, but in the meantime, are there any other suggestions you have? – msteppe91 Nov 7 '16 at 15:28
  • 1
    Turns out it actually worked, but only after running grub2-mkconfig -o /boot/grub2/grub.cfg...I totally forgot to run this after modifying the kernel command line. Thanks again @larsks! I will make an edit in my question above to reiterate this finding as these comments are over-looked occasionally. – msteppe91 Nov 7 '16 at 16:03
  • Thanks a lot for these kernel arguments. Was struggling a lot with HWADDR mismatch – harshavmb Apr 24 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.