How to change persistent-net-generator.rules to be PCI bus dependent and not MAC based?

6,566

Solution 1

This should be enough for what you want:

DRIVERS=="?*", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Solution 2

Identify the device by PCI address instead. Something like:

SUBSYSTEM=="net", BUS=="PCI", ID=="0000:04:00.0", ...

Solution 3

Running CentOS 6.5 on Virtualbox I achieved nirvana like this:

1) Inhibit /lib/udev/rules.d/75-persistent-net-generator.rules from overwriting /etc/udev/rules.d/70-persistent-net.rules - simply create an empty /etc/udev/rules.d/75-persistent-net-generator.rules

2) Edit /etc/udev/rules.d/70-persistent-net.rules:

# Map ethernet devices according to kernel enumeration
# this should match the adaptor numbering in the virtualbox console 
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{type}=="1", KERNEL=="eth0*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{type}=="1", KERNEL=="eth1*", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{type}=="1", KERNEL=="eth2*", NAME="eth2"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{type}=="1", KERNEL=="eth3*", NAME="eth3"

3) Edit /etc/sysconfig/network-scripts/ifcfg-eth[0-3] as appropriate, removing any HWADDR or MACADDRESS nonesense.

It's not perfect as the kernel enumeration order CAN and probably WILL change if you make other device changes to the VirtualBox settings prior to performing the clone - and the kernel detection doesn't exactly follow the Virtualbox adapter ordering (on mine it seems to be in reverse). But it otherwise does seem to behave consistently which should be at least "good enough".

More explanation and wisdom here:

Solution 4

I rarely clone Linux systems with VMWare. It's easy enough to rebuild (kickstart + Puppet/CFEngine), that it almost faster to reprovision a system than to clone.

But how are you cloning? Are you doing it from a VM template? Typically, if cloning from a template, I haven't had any NIC-related issues.

Share:
6,566

Related videos on Youtube

xsaero00
Author by

xsaero00

Software Developer in a small company. Here to pick others' brains.

Updated on September 18, 2022

Comments

  • xsaero00
    xsaero00 almost 2 years

    I am using CentOS 6.2 with VMware. I often have to clone my systems. Every time I clone it is adds a new rule to 70-persistent-net.rules file like so.

    SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:0c:f1:5e", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
    

    I never have more than one interface in my systems so this gets really annoying. I know there is way to change the rule to be PCI bus dependent and not MAC dependent, because I have done that already once but I cannot find anywhere on how to do it.

    I understand the reasons behind this implementation of udev rules. It makes perfect sense on physical systems but on VMs it becomes an annoyance. Please help.

  • xsaero00
    xsaero00 about 12 years
    Yeas I am using VM template. When cloning CentOS 5 I had no problems. CentOS 6 is different.
  • xsaero00
    xsaero00 about 12 years
    This worked. I tried to match it on PCI bus ID but that did not help. Hovewer I do not think this solution will work if I add second network interface.
  • xsaero00
    xsaero00 about 12 years
    I ended up deleting all other rules in 70-persistent-net.rules file and having just one like so ACTION=="add", SUBSYSTEM=="net", BUS=="pci", KERNELS=="0000:02:00.0", NAME="eth0"
  • Tom
    Tom over 9 years
    This deserves more upvotes - complete solution, and the rules file won't be regenerated later