[systemd-devel] network interface renaming via PCI ID w/ systemd-udevd

Mantas Mikulėnas grawity at gmail.com
Wed Nov 11 21:59:03 PST 2015

On Thu, Nov 12, 2015 at 7:40 AM, Matthew Hall <mhall at mhcomputing.net> wrote:

> On Thu, Nov 12, 2015 at 12:12:55AM -0500, Matthew Hall wrote:
> > /etc/udev/rules.d/70-net-names.rules:
> > SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", SUBSYSTEM=="pci",
> KERNELS=="0000:00:1f.6", NAME="eth0"
> > SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", SUBSYSTEM=="pci",
> KERNELS=="0000:08:00.0", NAME="eth1"
> > SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", SUBSYSTEM=="pci",
> KERNELS=="0000:0a:00.0", NAME="eth2"
> > SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", SUBSYSTEM=="pci",
> KERNELS=="0000:0a:00.1", NAME="eth3"

I'm not sure if udev even still _allows_ renaming to eth*, but even if it
does, that's explicitly not supported. (For example, between the time eth0
appears and the "rename to eth1" rule gets processed, another eth1 might
also appear, and the rename would fail.) If you want custom names, use en*
or port* or lan* or some other prefix.

> For future users who hits this, I think I finally found the bug.
> You have to use the "SUBSYSTEMS" filter not the "SUBSYSTEM" filter. I am by
> far not an expert on udev and the rules are extremely confusing. Is there a
> better way to write this ruleset?

The way they work is simple though – they directly compare the values you'd
see in `udevadm monitor --env` or `udevadm info /sys/class/net/eth0`. If it
says "SUBSYSTEM=net", then you can match it using SUBSYSTEM=="net", that's

But I guess the more important thing to know is that the network interface
is _not the same thing_ as the raw PCI device; it's shown as a sub-device
in /sys. (A single PCI device could easily expose multiple network
interfaces, for example.) Compare the output of `udevadm
info /sys/devices/pci0000:00/0000:00:1c.0/0000:01:00.0` vs `udevadm
info /sys/devices/pci0000:00/0000:00:1c.0/0000:01:00.0/net/eth0`.

That's why you use "SUBSYSTEMS=" and "KERNELS=" – you're checking
information of the _parent_ device. That said, some of the matches are IMHO
a bit redundant, and you'd be fine with:

ACTION=="add", SUBSYSTEM=="net", KERNELS=="0000:0a:00.1", NAME="em1"

Mantas Mikulėnas <grawity at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20151112/e4102453/attachment-0001.html>

More information about the systemd-devel mailing list