Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I changed out a NIC card that was the exact same make and model. The setup process for Ubuntu 11.04 was very seemless and easy so I figured it would be smart enough to setup up the replacement card. However, it gave the replacement card a new name of eth1 where all my scripts make reference to eth0, not to mention everywhere else in the OS eth0 may exist. Am I forced to track down every eth0 reference and change it to eth1 or is there a way to rename the replacement card back to eth0?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

Check udev config files.

A file like this: /etc/udev/rules.d/70-persistent-net.rules

ties the NAME (ethX) to the Mac address.

You probably have the old cards MAC tied to eth0. Remove its line and change the new card to eth0.

share|improve this answer
1  
Thanks! I did see in another post about the 70-persisten-net.rules file, but was in reference to fedora. The file was just in a different location, but good know it is the same file. –  hydroparadise Nov 18 '11 at 20:00
    
To think I was using ifrename(8) and scratching my head! This solution is much more elegant. –  amphetamachine Nov 18 '11 at 21:59

You can set the name of network interfaces either through udev (on any modern Linux system) or through /etc/network/interfaces on Debian, Ubuntu and other distributions using ifupdown. Not Now's answer covers udev; I'll discuss ifupdown.

In /etc/network/interfaces, you can use the mapping directive to give a nicknames to an interface based on the result of running a shell script. Typical uses for this feature are to give interfaces different names based on the network surroundings (e.g. eth0-home and eth0-work) or to set the name of an interface based on its characteristics such as the MAC address. There is an example script called get-mac-address.sh that you can use to set the name of an interface based on its MAC.

auto eth0 eth1
mapping eth0 eth1
    script /usr/share/doc/ifupdown/examples/get-mac-address.sh
    map 11:22:33:44:55:66 lan
    map AA:BB:CC:DD:EE:FF internet
iface lan inet static
    address 192.168.42.1
    netmask 255.255.255.0
iface internet inet dhcp

Now your two network interfaces are called lan and internet. If you ever replace one of them, you only need to update the MAC address in that one place in /etc/network/interfaces.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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