You’ve probably noticed that the recent trend in some Linux distributions is to name network cards not by ethX, but by their chipset. So we end up with em0, em1 or whatever…
This idea probably came from Solaris, but personally, I don’t see the benefit, especially since it’s more of a hindrance when you want to standardize an IT infrastructure. The purpose of this article is to show how to return to the good old ethX interfaces. I recommend reading the article on Udev before starting this one, to better understand certain aspects.
We’re going to add this argument (biosdevname=0) to the classic grub line to indicate at boot that we don’t want the interface renaming to take effect. Here’s an example:
1
2
3
4
5
6
[...]title Red Hat Enterprise Linux (2.6.32-220.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-220.el6.x86_64 ro root=/dev/mapper/vgos-root rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=fr LANG=en_US.UTF-8 rd_LVM_LV=vgos/root rd_NO_MD rd_LVM_LV=vgos/swap SYSFONT=latarcyrheb-sun16 crashkernel=128M biosdevname=0 rd_NO_DM intel_idle.max_cstate=0 initrd /initramfs-2.6.32-220.el6.x86_64.img
[...]
You either have the choice to redo a clean configuration by changing the interface names in the udev network rules (NAME=“xxxx”):
1
2
3
4
5
6
7
# This file was automatically generated by the /lib/udev/write_net_rules# program, run by the persistent-net-generator.rules rules file.## You can modify it, as long as you keep each rule on a single# line, and change only the value of the NAME= key.SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="d4:ae:52:9b:5a:85", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
Or simply delete the file (I’ve encountered cases where this didn’t work).
On Red Hat, you’ll need to rename the /etc/sysconfig/network-scripts/ifcfg-* interfaces and enter each of them to set the associated devices. For this Red Hat part, I find it so tedious that I made a script that will automatically modify udev and interfaces. Here it is:
#!/bin/bash
# Made by Pierre Mavro / Deimos# This script rename interfaces to get ethX instead of chipset name# Backup existing fileif[ -e /etc/udev/rules.d/70-persistent-net.rules ] ; then cp /etc/udev/rules.d/70-persistent-net.rules{,.bak}fi# Generate 70-persistent-net.rules fileecho"# Generated by Kickstart/Puppet
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
" > /etc/udev/rules.d/70-persistent-net.rules
i=0for m in `ip link show | grep "^\s*link" | grep -v loopback | uniq | sort | awk '{ print $2 }'` ; do# Change sysconfig filemyifname=$(grep -li "$m" /etc/sysconfig/network-scripts/ifcfg-* | awk -F'ifcfg-''{ print $2 }' | grep -v bond) perl -pi -e "s/^DEVICE=.*/DEVICE=\"eth$i\"/" /etc/sysconfig/network-scripts/ifcfg-$myifname mv /etc/sysconfig/network-scripts/ifcfg-{$myifname,eth$i}# Change udev ruleecho'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'$m'", ATTR{type}=="1", KERNEL=="eth*", NAME="eth'$i'"' >> /etc/udev/rules.d/70-persistent-net.rules
echo'' >> /etc/udev/rules.d/70-persistent-net.rules
let i++
done