Make Ethernet cards remember names between reboots

Q How do you get Ethernet NIC cards to remember their names between reboots on a SUSE distro? I'm running SUSE Enterprise 9 on my Linux router/firewall, which has three NICs installed; one for the external internet port, one for our internal network and one for our DMZ which carries all of our externally accessible resources such as web, mail and FTP servers. In most respects this installation operates beautifully. The problem is that the Ethernet device names seem to a) get randomly allocated on reboot (so hat was 'eth0' last time the system rebooted often becomes 'eth1' on the next reboot), and b) any persistent names assigned to these devices such as 'nic1' or 'nic2' are frequently ignored (even though PERSISTENT_NAME="nic1/2/3" is defined in the device files in /etc/sysconfig/ network/ifcfg-eth-*).

The upshot of this is that I almost always have to run ifconfig when I restart the router and patch the device IDs in the iptables definitions to suit the current (pretty much random) device configuration. This is a problem because the router rarely recovers from any outage condition without intervention. I have attached the config file of the DMZ NIC in /etc/sysconfig/network/ifcfg-eth-id-00:02:96:00:3f:8e. This card usually comes up as 'eth2' and has (theoretically) been assigned the persistent name 'nic2' for the purpose of our iptables firewall definitions. When the system boots, it occasionally notices that the device should be called 'nic2' but, more often than not, it ignores the PERSISTENT_NAME definition. Unfortunately, I don't have enough LAN cards to try this in another box (with a different distro) and I can't afford to take the server down for the time I may need to resolve the issue.

A This is odd - your config file looks correct, and works with SUSE here. The fact that it works occasionally indicates that some fundamental piece of software is not missing. Have you upgraded this system so it now uses udev? That could be forcing the names in spite of your settings in /etc/sysconfig/network. If so, the easiest and cleanest way to fix this is to use udev naming rules. Create the file /etc/udev/rules.d/10-network.rules, as root, and add these:

SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:02:96:00:3f:aa", NAME:="nic0"
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:02:96:00:3f:bb", NAME:="nic1"
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:02:96:00:3f:8e", NAME:="nic2"

replacing the strings after ATTRS{address} with the MAC addresses of the three cards. While the SUSE system had a problem with re-using the standard names, udev does not as this renaming is done before any names are applied, so you could use eth0/1/2 here if you wished. You may find you already have a file in /etc/udev/rules.d containing net persistent naming rules, in which case you should edit this file to add the above assignments. An alternative approach is to use the nameif command to rename the interfaces. This must be done before the interfaces are brought up. Create the file /etc/mactab with its contents a list of interface names and MAC addresses, like this:

nic0 aa:bb:cc:dd:ee:ff #internal
nic1 00:11:22:33:44:55 #external
nic2 66:77:88:99:00:aa #dmz

The nameif command will read this file and rename the interfaces accordingly. This should be considered only if you're not using udev, as udev rules provide the best way to handle persistent naming of network interfaces, and just about anything else.

Follow us on or Twitter

Username:   Password: