Friday, July 20, 2007

Renaming Interfaces in Ubuntu (eth1 to eth0, eth2->eth1)

If you've moved your hard disk to a new machine or swapped out the Ethernet cards you'll find that your interfaces are no longer named what you expect. Instead you will find that your eth0 no longer shows up and that you now have an eth1, eth2, eth3 and so on. To fix this you need to do a few little things:

First thing is to make sure that Ubuntu "sees" your ethernet adapters by listing PCI devices with lspci:

$ sudo lspci

This should give you a listing sorta like this:

0000:00:00.0 Host bridge: Intel Corporation 82845G/GL[Brookdale-G]/GE/PE DRAM Controller/Host-Hub Interface (rev 01)
0000:00:02.0 VGA compatible controller: Intel Corporation 82845G/GL[Brookdale-G]/GE Chipset Integrated Graphics Device (rev 01)
0000:00:1d.0 USB Controller: Intel Corporation 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) USB UHCI Controller #1 (rev 01)
0000:00:1d.1 USB Controller: Intel Corporation 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) USB UHCI Controller #2 (rev 01)
0000:00:1d.7 USB Controller: Intel Corporation 82801DB/DBM (ICH4/ICH4-M) USB2 EHCI Controller (rev 01)
0000:00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev 81)
0000:00:1f.0 ISA bridge: Intel Corporation 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge (rev 01)
0000:00:1f.1 IDE interface: Intel Corporation 82801DB (ICH4) IDE Controller (rev 01)
0000:00:1f.5 Multimedia audio controller: Intel Corporation 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) AC'97 Audio Controller (rev 01)
0000:05:04.0 Ethernet controller: 3Com Corporation 3c905C-TX/TX-M [Tornado] (rev 30)
0000:05:08.0 Ethernet controller: Intel Corporation 82801DB PRO/100 VM (LOM) Ethernet Controller (rev 81)


...as you can see I have multiple Ethernet cards, I want the 3Com ethernet card to be eth1 and the Intel on-board NIC to be eth0. Now that I know Ubuntu knows that these cards are there I need to see what ifconfig sees them as:

$ sudo ifconfig -a

eth1 Link encap:Ethernet HWaddr 00:0B:CD:97:A1:13
inet addr:xxx.xxx.200.80 Bcast:xxx.xxx.200.127 Mask:255.255.255.0
inet6 addr: fe80::20b:cdff:fe97:a113/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2771 errors:0 dropped:0 overruns:0 frame:0
TX packets:356 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:282405 (275.7 KiB) TX bytes:49995 (48.8 KiB)

eth2 Link encap:Ethernet HWaddr 00:01:02:C1:46:5B
inet6 addr: fe80::201:2ff:fec1:465b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:81395 errors:0 dropped:0 overruns:1 frame:0
TX packets:55 errors:0 dropped:0 overruns:0 carrier:49
collisions:0 txqueuelen:1000
RX bytes:5994745 (5.7 MiB) TX bytes:17226 (16.8 KiB)
Interrupt:177 Base address:0x6000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)


Okay it sees them both and has even reconfigured my network IPs on the wrong cards, we need to re-alias these cards so that they are detected properly and assigned the right names, this is done in the /etc/iftab (NOTE: if you do not seem to have an iftab file check below this section) file:

$ sudo vi /etc/iftab

# This file assigns persistent names to network interfaces.
# See iftab(5) for syntax.

eth0 mac 00:08:02:3a:da:bc arp 1
NOTE: If you don't have an /etc/iftab file then it's most likely you have anotehr file called /etc/udev/rules.d/70-persistent-net.rules. Inside it will look similar but more verbose. It will have your old network interfaces in place as well as your new ones with the eth2 and eth3 monikers. delete you old ones and replace the "eth2" and "eth3" with "eth0" and "eth1".


...ok, I see here that it has the MAC addres of my old ethernet card, so we are going to change it: Note in the previous step we listed the devices with ifconfig and it would show the "HWaddr" which is the MAC. We are going to add some new lines to /etc/iftab:

# This file assigns persistent names to network interfaces.
# See iftab(5) for syntax.

#eth0 mac 00:08:02:3a:da:bc arp 1
eth0 mac 00:0B:CD:97:A1:13 arp 1
eth1 mac 00:01:02:C1:46:5B arp 1


...now save the file. For good measure we are also going to add some aliases to the /etc/modprobe.d/aliases file, but first we need to know the module name that the kernel is using to access these ethernet cards:

$ sudo ethtool -i eth1

driver: e100
version: 3.4.14-k4-NAPI
firmware-version: N/A
bus-info: 0000:05:08.0


...note the driver name

$ sudo ethtool -i eth2

driver: 3c59x
version: LK1.1.19
firmware-version:
bus-info: 0000:05:04.0



...ok now that we know what the driver is, we are going to add the following lines to /etc/modprobe.d/aliases, these will be named based on what we expect the eth# to be once we reboot:

$ sudo vi /etc/modprob.d/aliases

alias eth0 e100
alias eth1 3c59x


That's done, next we need to modify the /etc/interfaces to add/modify the current, incorrect interfaces:

$ sudo vi /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet dhcp


... Save the file and then REBOOT. Yes, I said reboot. Yes, I know this is not windows, just reboot like I said.

Once it comes back up you should be able to log in andrun ifconfig again, this time it should show your interfaces in the correct order!

No comments: