8

I have a simple problem. I have a computer running Ubuntu server 8.04 LTS with 2 NICs. One on the motherboard going to the internet and one PCI card going to an internal network. During the install it detected the NIC on the motherboard as eth1 and the PCI card as eth0. I would like them the other way around. Especially because the PCI NIC will not be being used by the host server, only for some virtual machines that will be running on it.

So, currently the machine boots up activates eth1 (motherboard NIC) gets an IP with dhcp while leaving eth0 (PCI NIC) alone. This is exactly what I want except for eth0 and eth1 to switch.

Thanks.

2 Answers 2

15

As mentioned by tzafrir.net without much more explanation, on Debian based systems which include Ubuntu you need to check the /etc/udev/rules.d/70-persistent-net.rules file and you will find a line similar to:

# PCI device 0x14e4:0x170c (b44)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:15:c5:6d:b1:9e", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

You will obviously find one for with NAME="eth0" and another with "NAME=eth1" but will each have the respective MAC addresses. You can simply swap the NAME values and restart your computer and the system will rename them. You could even name them something different like wan or lan it doesn't matter so long as your routes and other configurations use the same names.

On RedHat based systems, including Fedora and CentOS, this would be accomplished by changing the HWADDR line found in the appropriate /etc/sysconfig/network-scripts/ifcfg-ethX file.

The point of it is to maintain the same NIC upon reboots as the kernel has been known in the past to change the order that PCI cards are addressed which can swap the NIC order.

2
  • 1
    Thanks. I also needed to edit /etc/network/interfaces and change eth1 to eth0.
    – lanrat
    Aug 1, 2009 at 23:18
  • if all you were wanting to change is which NIC was eth0 you should have only needed to change the 70-persistent-net.rules file. That file is actually created by udev if it doesn't exist when the system is booted up. Now if you had configured the interfaces file to get around it using the right NIC then you would need to change it as well. Aug 2, 2009 at 18:06
6

You can painlessly change the names of the two devices in /etc/udev/rules.d/70-persistent-net.rules

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.