Ensuring network interfaces remain named consistently
Posted by Anonymous on Thu 16 Nov 2006 at 11:08
I was answering a recent weblog post and I figured the reply was sufficiently interesting to be a short and sweet article, plus the feedback from you guys is always great. So, here it is: Making sure that network interface ordering remains constant.
A NIC card trickCards::Shuffle
If you have more than one network card, there is no guarantee that eth0 when you first boot up remains eth0 in the next boot. It could swap with eth1. This can happen especially if the cards are the same chipset, I reckon. If you change kernels or switch to using something like hotplug or udev you can also find the same problem.Cards::Deal
A simple way to fix this is to use the nameif command which is contained in the net-tools package.
For example add the following contents to /etc/mactab file like this, (this example is for three cards):
want_eth0 00:23:B7:89:39:E2 want_eth1 00:08:A3:20:F8:29 want_eth2 00:50:BA:29:B7:32
The things to the right are the MAC addresses (which you can find by running "ifconfig | grep HWaddr", or "ip | grep ether").
Then create a script under pre-up:
$cat /etc/network/if-pre-up.d/nameif #!/bin/sh PATH=/sbin nameif #above tries to set want_ethX names in /etc/mactab nameif eth0 00:23:B7:89:39:E2 nameif eth1 00:08:A3:20:F8:29 nameif eth2 00:50:BA:29:B7:32
Now "/etc/init.d/networking restart" will assign the interfaces in the order you want. The pre-up script is quite dirty (it whines while doing the job), but it will do what you intend.