Fix missing eth0 after changing network cards

After changing hard drives out of one server machine into another and booting, the network interface didn’t come up correctly. eth0 didn’t exist and gave an error when I tried to start it manually using ifup eth0. At first I suspected that the correct driver module wasn’t installed because the OS had been installed on another system with a different NIC; so I verified that the correct module was installed.

What in fact had happened is that udev has a feature where it remembers NICs by their MAC address and remembers which device name they’ve been assigned. So the hard drive (and the OS it contains) were running in a machine with another NIC that had been assigned to eth0, so when booted inside the new machine it assigned the new NIC to eth1. Unexpected!

This would often be pretty fantastic. Many years ago when I upgraded from a 2.4 to a 2.6 kernel I had an issue where the order of network devices changed - eth0 and eth1 had swapped. This caused some frustration when remote administering the upgrade from another country on Christmas day.

So you can either take what you’ve been given and change your network interface configuration to use eth1. Which wouldn’t be stupid. Or you can modify the udev rules to forget the original NIC and therefore assign eth0 to your new NIC on reboot…

Edit the /etc/udev/rules.d/70-persistent-net.rules file. At or near the bottom will be lines beginning SUBSYSTEM, which declares the MAC address and the assigned device name. Comment out or delete lines for NICs you no longer have. Then either comment out or delete your current NIC (otherwise it will stay with eth1 after reboot) or simply change the device name it has been assigned to eth0. Then reboot.

I had to discover this in a time critical situation - thank goodness for Google and for this post.

This was posted 1 month ago. It has 12 notes.
  1. karlvr posted this