Network interface names

Steffen Grunewald steffen.grunewald at aei.mpg.de
Thu Nov 22 17:21:39 CET 2018


On Thu, 2018-11-22 at 12:18:52 +0100, Rémy Dernat wrote:
> Ok; replying to myself. I found the solution.
> 
> I just created a script for my BIONIC64 class (using the debian script) :
> 
> ```
> #! /bin/bash
> 
> iface=`ip -o -f inet addr show |awk '$2 !~ "lo|docker" {print $2;exit;}'`
> mac=`ip -o -f link addr |awk -v iface=$iface '{ if ( $2 == iface":" )
> {print;} }' |cut -d"/" -f2|awk '{print $2}'`
> fields="ID_NET_NAME_FROM_DATABASE ID_NET_NAME_ONBOARD ID_NET_NAME_SLOT
> ID_NET_NAME_PATH"
> for field in $fields; do
>   name=$(udevadm info /sys/class/net/$NIC1 | sed -rn "s/^E:
> $field=(.+)/\1/p")
>   if [[ $name ]]; then
>     newnicname=$name
> break
>   fi
> done
> 
> 
> fcopy /etc/netplan/01-netcfg.yaml
> fcopy /etc/cron.d/dhclient
> 
> sed -ri "s|inet_to_replace|$newnicname|" $target/etc/netplan/01-netcfg.yaml
> sed -ri "s|inet_to_replace|$newnicname|" $target/etc/cron.d/dhclient
> sed -ri "s|inet_to_replace|$newnicname|" $target/etc/network/interfaces
> sed -ri "s|mac_to_replace|$mac|" $target/etc/netplan/01-netcfg.yaml
> ```
> 
> With `{mac,inet}_to_replace` in those files (which is replaced with my sed).

Hi Remy,

this doesn't work for pure Debian (which hasn't been converted to use netplan
AFAICT), but I can imagine to use udev rules to assign any (old or new style)
interface names to the devices.

I'm running a class script that collects all available interface names (as
the FAI NFSROOT creates them) and MACs, and builds a persistent-net.rules file.

For now, I'm sticking with old-style ones, but this script could be adapted
to use udevadm info to retrieve the "new-style name" from /sys/class/net/eth*
should this become necessary.

Thanks for sharing your insight,
 Steffen


More information about the linux-fai mailing list