Purpose: Sometimes if you are experimenting with Linux on different machines, there are chances that upon switching to a different machine your Ethernet card won’t be activated by default i.e. upon giving the command ‘ifconfig’ your Ethernet card will disappear even if your driver is loaded properly.
Linux O.S.: Debian 4.0
Kernel: 2.6.22 – 2.6.24
Update: Debian Lenny users click here.
For example, you install your Linux system on one machine and then you take your hard disk and attach it to an another machine which has possibly the same configuration. On booting you find that you cannot see your eth0 or eth1 upon giving ‘ifconfig’. For example, you see this:
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:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:560 (560.0 b) TX bytes:560 (560.0 b)
instead of this
eth0 Link encap:Ethernet HWaddr 00:01:02:03:04:05
inet addr:192.168.0.101 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe81::202:244:fe68:3172/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:78108 errors:0 dropped:0 overruns:44 frame:0
TX packets:50313 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:103308543 (98.5 MiB) TX bytes:3763441 (3.5 MiB)
Interrupt:169 Base address:0xe000
However, you can activate your Ethernet card by giving commands like:
# dhclient eth2
# dhclient eth3 (If you have Dual Ethernet card)
Suppose now you can attach your same hard drive to another identical machine and now you again cannot activate your Ethernet card even by giving the above commands i.e. ‘dhclient eth2’ or ‘dhclient eth3’. But you can activate it now by giving commands like:
# dhclient eth4
# dhclient eth5 (If you have Dual Ethernet card)
This cycle can go on and on i.e. upon switching machines every time you have to keep incrementing the eth<number> by one or by two (if you have dual Ethernet card).
If you observe something like this on your machines then read the solution below.
Note: Before you proceed to the solution make sure that your Ethernet card driver is loaded. If your driver is compiled as a module in your kernel, you can load it by giving the following command:
# modprobe <name-of-drive>
# modprobe e100
If it is built into the kernel then you don’t need to give the command as it should have got loaded automatically. Steps to configure and compile your Ethernet driver is out of the scope of this post.
Update for Debian Lenny (5.0) users: The files that needs to be deleted have been changed since Debian Lenny. To learn how to solve this issue in Debian Lenny click here.
Remove the following two files from the udev directory:
# cd /etc/udev/rules.d
# rm z25_persistent-net.rules z45_persistent-net-generator.rules
This happens because of the above two configuration files that udev creates by default. The file ‘z25_persistent-net.rules’ creates rules for the Network devices and remembers them upon every boot. Removing this files forces the udev to create names from start i.e. eth0 upon every reboot. I don’t claim that I understand this issue completely but if you want to go to the depth of it then I recommend reading the udev documentation under the directory ‘/usr/share/doc/udev’. It has vast source of information. Also you can read more about udev in the Kernel Documentation directory under ‘/usr/src/linux/Documentation’.
I noticed this behavior in Debian 4.0 (Stable/Etch). This issue was not there in Debian 3.1 (Stable/Sarge). This means that something changed in udev package between 3.1 and 4.0. Go figure!
I was able to figure out this solution by reading the documentation mentioned above. Also this lead me to create a post which explains what steps one should take in general to (re)solve problems under Linux.
As usual, please leave a comment/feedback, if you have any.