Debian – changing the names of network interfaces, debian wheezy

debianethernetlinuxnetwork-interfacenetworking

I'm trying to set a name for an interface, "ethLan" instead of eth0. Doing so also ensures that the if's name will remain consistent at every reboot and kernel.

I did find some articles in the subject, but they are all a couple of years old:
http://www.debian-administration.org/articles/463
http://www.linuxfromscratch.org/hints/downloads/files/nameif.txt

I did as they said and added the ethLan mac to /etc/mactabs/.
At this point I have two problems:
1) The if [...] && /sbin/nameif script I put at /etc/network/if-pre-up.d/ does not run. I solved this by adding this to the /etc/init.d/networking, but why doesn't if-pre-up.d work?
2) The interface won't load unless I manually do ifconfig ethLan up, in spite of adding it to /etc/network/interfaces. What am I doing wrong?

Best Answer

The articles you found are somewhat outdated. There is now an easy method to assign names to network interfaces, through Udev.

On Debian and derivatives (including Ubuntu), look out for a file called /etc/udev/rules.d/70-persistent-net.rules. This file is created by /lib/udev/rules.d/75-persistent-net-generator.rules with the help of the script /lib/udev/write_net_rules. Each time udev sees a new network device, it will assign it a new number and append that number to /etc/udev/rules.d/70-persistent-net.rules. That way, interface numbers are persistent across reboots, and will persist after a reinstallation if you restore /etc.

(If your distribution doesn't ship these files, look for them in the Debian package.)

If you want to give a meaningful name to an interface and you have /etc/udev/rules.d/70-persistent-net.rules, all you need to do is to edit that file and change "eth0" to "ethLan". Run udevadm trigger --sysname eth0 to rename the existing device after you've edited the file (I think this requires shutting down the interface). If you don't have that file, you can write the one-line matching yourself (the complicated scripts that Debian adds are only to do this automatically):

SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="01:23:45:67:89:ab", NAME="ethLan"
Related Question