When using VMware server/ESXi in production environment, new MAC address is allocated to a new VM being added. Same situation happens on the same VM if it is configured to have new network adaptor. A different MAC address is allocated to that network adaptor and it never duplicates. Debian based Linux will automatically map this new MAC address to a different network interface, i.e., eth? (where ? is always greater than 0) In this case, it will never map back to original network interface, say, eth0.
Now check the file "/etc/network/interfaces", the content should be:
Assuming you always have one network adaptor installed on your system and that one is expected to be eth0:
To make sure new adaptor's MAC address being mapped to eth0 network interface, there is a file that raises such interest:
"70-persistent-net.rules"
I don't know what's 70 means but it always appears when you have network adaptor installed on your system.
Try issue following command to locate this file in your linux environment:
This file is created by udev service at startup where auto detection of network adaptor takes place. New content will be added to the bottom of the file automatically. It determines the output results you could find by issuing ifconfig command.
In this case, eth2 is active, not for eth0.
Basically, the file "70-persistent-net.rules" contains all the detected PCI devices and then do the mapping with them. Here is a typical one:
Well, obviously you will find it useful to have a look at the NAME key paire whereas eth0 is specified. Meanwhile, assigned MAC address (either physical or virtual one) is shown after ATTR{address}.
This kind of settings will be accumulated along the time when new network adaptors are added or MAC address is changed. New string with NAME="eth?" will be added to the end of the file so we can tell from the aforementioned file that the MAC address has been changed twice and finally eth2 becomes the current active network interface.
If you want to force new MAC address being mapped to eth0 network interface, you can
delete this file, namely "70-persistent-net.rules", with the following command:
Then modify the content in "/etc/network/interfaces" to substitute eth2 with eth0:
After system reboot, you will find a brand-new "70-persistent-net.rules" file reappearing in the directory but the content will be:
Now, the network adaptor is mapped to eth0 again.
For the administrative point of view in VMware environment, it is not a good practice to manually reset network interface mapping like this. That would be good if we can automate it. Here is how:
- locate directory "/etc/init.d"
- pick one of networking related script like "/etc/init.d/networking" and edit it
- locate stop) section within script file "/etc/init.d/networking"
- add the following line towards the end of the section (right before double semi-colon ;;):
- save it
- If you find a symbolic link linked to this script file within /etc/rc0.d/ directory, then it means it will run stop) section of "/etc/init.d/networking" during system shutdown process, i.e., deleting "70-persistent-net.rules" automatically. If not, you may need to create a symbolic link yourself within /etc/rc0.d/ directory. The command would be like this:
$ sudo ln -s /etc/init.d/networking /etc/rc0.d/networking
Now, everything is ready. Try reboot the system to let things happen.
Whenever MAC address is going to be changed at next bootup, the problematic "70-persistent-net.rules" file would have been deleted first during shutdown period. Then a new "70-persistent-net.rules" file will be created with the correct mapping of MAC address to eth0 again at next startup. It makes sure new MAC address is always mapped to eth0 adaptor, with the basic assumption that there is only one network interface card installed on the system.