linux ethernet numbering reset

Check the udev rules in /etc/udev/rules.d.

In my Fedora distribution, there is an automatically written rule in 70-persistent-net.rules

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:f1:cc:2f:1a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

which clearly links the ethernet address to the device name. The comments at the top of the file give good clues how to adjust this behavior.


Add this to your script. It may need to be run as root depending on your system.

ethX=`ifconfig -s | awk 'NR==2 {print $1}'`

Then you can use $ethX as a variable to your NIC.
This just takes the output of ifconfig -s and parses out everything except for the text on line 2 and column 1.