Reclaiming the Network on an Ubuntu Clone
- January 29th, 2012
Lately I’ve been building lab environments using Linux virtual machines. I start by installing a model system to use as my source. In this case I’m using a custom install of Ubuntu Server 11.04. The usual process is to copy the vm file to create the clones then make basic network adjustments such as changing the host name, IP address and MAC address. Some vm environments will detect that you’re operating from a copy and dynamically assign a new MAC address for you. If not, you’ll need to generate a new address in the NIC properties.
One obstacle you’re likely to encounter is that your networking fails to work after changing the MAC address. The likely cause is that your system detected this new address and assumed it to be a new ethernet connection but your IP settings are still assigned to your original ethernet interface, probably eth0.
The solution is to make your original network configuration aware of your new MAC address.
Locate the udev rules file for network devices:
/etc/udev/rules.d/70-persistent-net.rules
This rules file should contain a single entry for every ethernet interface in your system. My original vm just had eth0, but after booting my clone, the new MAC address of 00:1c:42:ab:fe:96 was detected and added as eth1.
# PCI device 0x8086:0x100f (e1000)SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?", ATTR{address}=="00:1c:42:de:60:fb", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth", NAME="eth0"
# PCI device 0x8086:0x100f (e1000)SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?", ATTR{address}=="00:1c:42:ab:fe:96", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth", NAME="eth1"
Since the original ssytem was setup with eth0, ifconfig doesn’t know about eth1 so it simply needs to be removed and the new MAC address needs to be assigned to eth0. Edit 70-persistent-net.rules and remove the first entry containing the original MAC address and change the second entry to eth0.
# PCI device 0x8086:0x100f (e1000)SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?", ATTR{address}=="00:1c:42:ab:fe:96", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth", NAME="eth0"
So, there you have it. Reboot the system to affect the change.
