network interfaces exchanged

Andreas Sindermann sinder at thp.Uni-Koeln.DE
Fri May 19 22:04:34 CEST 2006


Sorry for answering myself..

Several things needed to be done to enable proper networking on
Ubuntu 6.06 (dapper):

a) /etc/resolv.conf is handled dynamically by the resolvconf
facility. For that reason it is necessary to add the following two
lines to $target/etc/interfaces instead of fcopy'ing a static
/etc/resolv.conf file (in the FAI example files this is done in the
scripts/30-interface script):

          dns-search $DNSDOMAIN
          dns-nameservers $DNSSRVS

b) During FAI installation I save the hardware address and the
interface name of the interface being used during installation in
/etc/mactab of the newly installed system (FAI examples:
scripts/30-interface):

# FAI Ubuntu kernel thinks something different than the normal Ubuntu
# kernel about the order of the network interfaces. So use nameif(1)
# which reads /etc/mactab for defined order of interfaces.
if [ -f $LOGDIR/dhclient.log ]; then
  myif=`grep Listening $LOGDIR/dhclient.log | awk -F/ '{print $2}'`
  mymac=`grep Listening $LOGDIR/dhclient.log | awk -F/ '{print $3}'`
  echo "$myif $mymac" > $target/etc/mactab
fi


b) To reorder (only if necessary) the network interfaces I've created
a little script /usr/local/sbin/ifexchange on the installed FAI
client (based on the 'nameif'):

-------- snip ----------
#!/bin/sh

# In case the system has two interfaces and the kernel accidently 
# configured them in the wrong order, simply exchange them, i.e.
# eth0 becomes eth1 and vice versa.


# 1. Are there two interfaces (eth0 and eth1) at all?

if [ `grep -c eth.: /proc/net/dev` -ne 2 ]; then
  exit 0
fi


# 2. If MAC address used during FAI installation is associated with the same
#    interface used during FAI everything is fine, else the interfaces
#    need to be exchanged.

fai_if=`awk '{print $1}' /etc/mactab`
fai_mac=`awk '{print $2}' /etc/mactab`
current_if=`ifconfig -a|grep -i $fai_mac|awk '{print $1}'`
if [ $fai_if != $current_if ]; then
  # Interfaces need to be exchanged!
  # Get 'wrong' hardware address
  wrong_mac=`ifconfig $fai_if|grep $fai_if|awk '{print $5}'`
  # Shutdown network
  ifdown -a
  # Assing interfaces with exchanged hardware addresses:
  nameif grrrr $wrong_mac
  nameif $fai_if $fai_mac
  nameif $current_if $wrong_mac
  # Bring up network
  ifup -a
fi
------ snip ----------

This ifexchange script is called during the booting phase:

/etc/init.d/checkinterfaces:

------ snip ------
#!/bin/sh

[ -x /usr/local/sbin/ifexchange ] && /usr/local/sbin/ifexchange
----- snip ------


$ROOTCMD update-rc.d checkinterfaces start 41 S 0 6 .


This seems to work at least for me. Perhaps there are others who might
want to try it out..

Andreas



More information about the linux-fai mailing list