[CLUG] network card id switching

Tony Breeds tony at bakeyournoodle.com
Mon Jun 12 00:56:58 GMT 2006

On Fri, Jun 09, 2006 at 05:50:08PM +1000, freegazer wrote:
> I will soon need to do a bit of work on some dual nic'd machines. I remember
> during the recent presentation on diskless booting that there was more than
> a little discussion on the problem of nic addresses changing at boot time.
> If memory serves right Bob mentioned that he resolved the issue be changing
> the default boot sequence for Debian so that the cards would keep the same
> "eth" location.
> Does anyone know of an article on this? Or perhaps is there a chance sombody
> kept reasonable notes?
> The systems need to be running RH rather than Debian so I don't know if
> exactly the same fix will work but I would like to look into it.

Debian has a couple of nice ways to do this but you say you need Redhat
so we'll ignore them

The quickest way to do it I can think of is write a init.d script that
runs before the network is brought up.

something like: (completely untested)

# Hmm what if /usr isn't available?
NR_ETH=$(/bin/ip link | /bin/egrep eth.: | /usr/bin/wc -l )

# Rename all interfaces to avoid conflicts
for i in $( /usr/bin/seq 0 $(( ${NR_ETH} - 1 )) ; do
	/bin/ip link set eth${i} name eth${i}_

for i in $( /usr/bin/seq 0 $(( ${NR_ETH} - 1 )) ; do
	MAC=$( /bin/ip ip link show dev eth${i}_ | \
		/bin/egrep link | /usr/bin/awk '{print $2}' | \
		/usr/bin/tr A-Z a-z )

	# This could be a shell style glob
	case "${MAC}" in
		/bin/ip link set eth${i}_ name eth1
		/bin/ip link set eth${i}_ name eth0
		/bin/echo "Unknown device ${MAC} left at eth${i}_" >&2


Of course this means you need to know the MAC address and the order you
want them in and have physical access to the console.
You could do all sorts of smart things like walking /sys/class/net/*/ or
parsing dmesg to get the mappings you want.  You could also read the
mappings from a file on disk (that way the script is unchanged from
system to system)

Another option would be to build a custom kernel with the drivers built
in.  Then they /must/ be initialised in a given order and will always
get the same device name.

yet another option would be to work some udev magic to rename the
interfaces as required when modules are loaded but I've got 0 experience
with that.

I guess it all depends on how many machines your talking about and how
hackish you're prepared to be, and how kind you want to be to whomever
comes after you :).  There are lots of options.

Yours Tony

   linux.conf.au       http://linux.conf.au/ || http://lca2007.linux.org.au/
   Jan 15-20 2007      The Australian Linux Technical Conference!

More information about the linux mailing list