Tuesday, August 7, 2012

Force CentOS 6 to Re-Detect Network Devices

SkyHi @ Tuesday, August 07, 2012

Recently, I began transitioning from VMware ESXi to Proxmox VE and ran into an unexpected issue. After imaging the VM’s running on top of ESXi and redeploying them into blank KVM VM’s, I noticed that even though the new VM’s had network interfaces they had no connectivity. After some investigation, I discovered that CentOS 6 uses udev to deal with all hardware devices; so restoring connectivity was as a quick, two-step process. Before we discuss the solution, though, let’s examine the root cause of the issue.
udev manages hardware, including network interfaces, via .rules files which contain various attributes of a given piece of hardware that are used to match the device against a single device node each time it is connected to the system. When cloning a drive with Clonezilla a bit-for-bit copy of the drive is made, which includes the /etc/udev/rules.d directory and all the .rules files contained within it. The 70-persistnet-net.rules file controls network devices in a system and isn’t updated when a Clonezilla image is deployed onto new hardware. Causing the system to continue trying to use the old MAC address, resulting in non-functional network interfaces.
To force CentOS 6 to re-detect network interfaces and assign them the correct MAC address:
1. Open the configuration file for the network interface you wish to work with in your text editor of choice.
vi /etc/sysconfig/network-scripts/ifcfg-eth0
2. Remove the existing HWADDR line in this file so that it won’t conflict with the new value written to the 70-persistent-net.rules file when the system is rebooted in the final step of this tutorial. When done your file should look similar to the example below:









3. Remove the old 70-persistnet-net.rules file with the following command. Removing this file will force udev to probe for network interfaces at boot and create a new 70-persistent-net.rules with the appropriate MAC address (or addresses if your system has multiple network interfaces).
rm -f /etc/udev/rules.d/70-persistent-net.rules
4. Restart the machine and check that your network interface is listed in the newly created 70-persistent-net.rules file along with the correct MAC address.
There you have it, a quick and easy way to restore network connectivity on a Centos/RHEL system after migrating to new hardware.