#!/bin/bash #Syn-3 Interface assign script. #path to configfile #\t CONFIG_FILE=/mnt/if-assign.conf; #shut all interfaces down and move them out of the way for NET in /sys/class/net/eth*/address; do INTERFACE="`echo $NET|cut -f5 -d/`"; if [ "`cat /sys/class/net/$INTERFACE/type`" == "1" ]; then MAC="`cat $NET`"; ifconfig "$INTERFACE" down nameif "tmp_$INTERFACE" "$MAC" fi done #first, if we have a config, rename interfaces that have an explicit mac assignment if [ -e $CONFIG_FILE ]; then for NET in /sys/class/net/tmp_eth*/address; do INTERFACE="`echo $NET|cut -f5 -d/`"; if [ "`cat /sys/class/net/$INTERFACE/type`" == "1" ]; then MAC="`cat $NET`"; NEW_INTERFACE="`grep -i "^$MAC" $CONFIG_FILE |head -1|cut -f2`" 2>/dev/null if [ "$NEW_INTERFACE" ]; then echo "Assigning known adaptor $MAC to interface $NEW_INTERFACE." nameif "$NEW_INTERFACE" "$MAC" fi fi done fi #now rename the unknown adapters in ORDER of macadres. #this will guarantee consistency. in some complex setups, interfaces seem to be assigned at random/detection speed. #after booting this assignment will be stored permanently and can be changed by the user. IF_COUNTER=0 for MAC in `cat /sys/class/net/tmp_eth*/address 2>/dev/null|sort`; do NET=`grep -l $MAC /sys/class/net/tmp_eth*/address 2>/dev/null` INTERFACE="`echo $NET|cut -f5 -d/`"; #determine next available eth number while true; do NEW_INTERFACE=eth$IF_COUNTER if ! [ -e /sys/class/net/$NEW_INTERFACE ]; then echo "Assigning new adaptor $MAC to interface $NEW_INTERFACE" nameif "$NEW_INTERFACE" "$MAC" break; fi IF_COUNTER=$(( IF_COUNTER+1 )) done done