At work I have been making more and more use of virtualization.   To make life simple, I have a virtual machine image that I use as a template and clone it when I need a new virtual machine.   This works great, except that as part of the cloning process, the clone receives a new MAC address (which is expected).  The problem is,  udev has already linked eth0 to the templates MAC address, so the clone’s network card is configured as eth1, not eth0.  Not a big deal, but annoying (to me anyways).
Here is the workaround I found that tells udev to ignore KVM/Xen/Vmware issued MAC addresses.
In the file /lib/udev/rules.d/75-persistent-net-generator.rules, find the line:
ENV{MATCHADDR}="$attr{address}"
Below that line add the following lines:
# Ignore KVM virtual interfaces
ENV{MATCHADDR}=="52:54:00:*", GOTO="persistent_net_generator_end"
ENV{MATCHADDR}=="54:52:00:*", GOTO="persistent_net_generator_end"
# This eems to be the range used by Xen, but also by virt-clone
ENV{MATCHADDR}=="00:16:36:*", GOTO="persistent_net_generator_end"
# Ignore VMware network interfaces identified by vendor part of MAC addr
ENV{MATCHADDR}=="00:0c:29:*", GOTO="persistent_net_generator_end"

Now that I’ve added these rules to my master image, all the copies I make have their NIC assigned to eth0.
Notes:

  • Tested on Ubuntu Server 10.04 LTS, though it should work on any distro that uses udev in the same manner.
  • I’ve only used this trick on VMs with a single NIC.  I’m not sure what will happen on multihomed installs.