Ethernet Interface Naming With Systemd

3 Comments

Systemd has a new way of specifying names for Ethernet interfaces as documented in systemd.link(5). The Debian package should keep working with the old 70-persistent-net.rules file, but I had a problem with this that forced me to learn about systemd.link(5).

Below is a little shell script I wrote to convert a basic 70-persistent-net.rules (that only matches on MAC address) to systemd.link files.

#!/bin/bash

RULES=/etc/udev/rules.d/70-persistent-net.rules

for n in $(grep ^SUB $RULES|sed -e s/^.*NAME..// -e s/.$//) ; do
  NAME=/etc/systemd/network/10-$n.link
  LINE=$(grep $n $RULES)
  MAC=$(echo $LINE|sed -e s/^.*address….// -e s/…ATTR.*$//)
  echo "[Match]" > $NAME
  echo "MACAddress=$MAC" >> $NAME
  echo "[Link]" >> $NAME
  echo "Name=$n" >> $NAME
done

3 thoughts on “Ethernet Interface Naming With Systemd”

  1. Elessar says:

    System is now starting to replace Udev rules as well‽ Will it ever stop?

  2. aL says:

    I would like this kind of things being done automatically on upgrade if I havent touched anything manually (no file in /etc/systemd/network for example)

  3. pywy says:

    Hi, could you show how before and after files look like ?
    Would be great!

Comments are closed.