# keeping eth0 and eth1 always assigned to the same NIC

## javeree

I have several computers with multiple NIC. Normally, these should start up and always get the same name eth0, eth1, etc...

However, every now and then upon a fresh boot, the naming is differen, and the NIC that normally is eth0 is now called eth1. How can I make sure that always the same names are assigned?

I may be wrong, but I believe this is something that is done by udev ? The question is then: how to change it ?

----------

## richfish

If you are using udev-103, run "/lib/udev/write_net_rules all_interfaces".  If you then want to change the order of eth0 and eth1, you can edit /etc/udev/rules.d/70-persistent-net.rules.

----------

## javeree

Thanks, 

I upgraded to that version and now have rules to fix the networks.

I also see that there is a setof rules  75-cd-aliases-generator.rules, which seem to call

/lib/udev/write-cd-rules

However, there doesn't seem to be an equivalent to 'all_interfaces', so I guess it needs to be called from 75-cd-aliases-generator.rules somehow, but I can't see any new rules generated after a reboot.

----------

## richfish

Yeah, the write-cd-rules can be slightly more of a pain.  The problem on a lot of systems is that the root filesystem initially mounts as read-only, so udev is initially started on a read-only system, and cannot generate the rules files.

If you do not use any initrd/initramfs, you could add the "rw" option to your kernel options in grub to mount the root filesystem as read-write initially.  That should solve the generation of the rules files.

If you do use an initrd/initramfs, you'll have to convince it to mount root as read-write.  For genkernel this means adding "real_rootflags=rw" to the kernel options in grub.

----------

## javeree

Returning to the eth0 eth1 problem, which has not yet disappearedmy wireless and wired cards still continue toswitch eth0 and eth1 every now and then. However, I have a lto more insight in the problem now.

I remarked that when things went wrong, I had a /sys/class/net/eth1_rename instead of eth1. Fromother posts, I learned this means that some interface is eth1, and that the udev rules cannot overwrite this and therefore give the eth1_remane name instead. To avoid this naming conflict (whatever the cause) I changed the udev rule to name my fixed ethernet interface 'lan', and my wireless 'wlan'. After reboot, it seemed that it still did not worked. 'lan' was created correctly, but wlan was not created. Instead it was now called eth0. A few reboots later, it was called eth1.

I remarked however, that the MAC address was not constant: it is "00:60:b3:94:1a:dd" on one occasion and "00:30:b4:00:00:00" on another. 

At this moment my theory is that the cause of my problem is that my wireless card is a prism54 card. This is a card for which the firmware has to be uploaded. I guess it means that the device onlyu gets a mac address after this upload, and that there is some kind of race condition between the assigning of a mac address and the rules using that mac address to give the interface a name. 

I probably need to find an alternative rule to give the wireless card its name. Any suggestions ?

----------

## richfish

I don't have a prism54 wireless card anymore, so I can't really test this, but my first option would be to key off the driver name.  So in 70-persistent-net.rules, rather than DRIVERS="?*", use the actual driver name (DRIVERS=="prism54" for example).  You should be able to get the driver name with "udevinfo -a -p /class/net/eth0" and then again with eth1.

[edit] oh, and don't key off the address for the wireless.

The second option is to look at the output of that udevinfo command, and see if there is some sysfs entry that indicates whether the firmware is loaded or not.  If you can find one, you can add a WAIT_FOR_SYSFS= rule to delay processing until that particular attribute is created.  I'd guess in yoru 10-local.rules file, something like:

ACTION=="add", SUBSYSTEM=="net", DRIVERS=="prism54", WAIT_FOR_SYSFS="firmware_whatever"

----------

## javeree_work

Thanks for the rule.

I didn't need to use the WAIT_FOR_SYSFS attribute. I also gave up trying to assigne interfaces to eth0/eth1, but gave new names lan and wlan. Which resolved my problem completely (after changing the names in in /etc/conf.d/net and /etc/conf.d/wireless

----------

