Ubuntu 17.04: how to rename a USB network interface based on Path? (NOT based on MAC)
So I finally figured out myself what really is happening.
Alas, the problem I'm seeing that renaming USB-based network interfaces doesn't work is actually caused by the udev rule /lib/udev/rules.d/73-usb-net-by-mac.rules
on Ubuntu/Debian (and thus also Raspbian). The culprit in it is here:
ACTION=="add", SUBSYSTEM=="net", SUBSYSTEMS=="usb", NAME=="", \
ATTR{address}=="?[014589cd]:*", \
TEST!="/etc/udev/rules.d/80-net-setup-link.rules", \
TEST!="/etc/systemd/network/99-default.link", \
IMPORT{builtin}="net_id", NAME="$env{ID_NET_NAME_MAC}"
Notice how this specific rule checks for /etc
/udev/rules.d/80-net-setup-link.rules
to be present; if it's not, then NAME
will be set to a MAC48-based name, and the later default install rule /lib
/udev/rules.d/80-net-setup-link.rules
will never get a chance to assign NAME
. Now that's sad. Again.
In order to enable the ability to assign user-defined names to USB network interfaces, we need to have /etc
/udev/rules.d/80-net-setup-link.rules
, as this is the rule set 73-usb-net-by-mac.rules
checks against before assigning NAME
.
This means that simply linking from /etc/udev/rules.d/80-net-setup-link.rules
to /lib/udev/rules.d/80-net-setup-link.rules
is needed in order to avoid that user-assigned network interface names get ignored any longer.
sudo ln -s /lib/udev/rules.d/80-net-setup-link.rules /etc/udev/rules.d/80-net-setup-link.rules
Reboot. Done.
Please note that a side-effect of the way 73-usb-net-by-mac.rules
is set up, this causes all USB-based network interfaces to assume "old" naming eth0
, et cetera, unless explicitly named in a .link
file.
I don't know why the rules have been written as they are, as it would be fine to have MAC-based naming for all USB network adapters not explicitly named. On a second thought ... no, using MAC48-based names does not make any sense, unless you happen to label all your USB network dongles and constantly swap them around; but maybe the MAC-based names are used with docking stations, where it actually would make sense...?
As per this thread and especially this paragraph:
Custom net interface naming ... The name of the rules file needs to have a prefix smaller than "80" so that it runs before /lib/udev/rules.d/80-net-setup-link.rules, and should have a prefix bigger than "75" so that it runs after 75-net-description.rules and thus you can use matches on ID_VENDOR and similar properties. ...
I did create this file : /etc/udev/rules.d/76-netnames.rules
with this content
# USB device by path
# get ID_PATH if not present yet
ENV{ID_PATH}=="", IMPORT{builtin}="path_id"
SUBSYSTEM=="net", ACTION=="add", ENV{ID_PATH}=="*-usb-0:1.*", NAME="eth%n"
it is working fine, without the workaround you provided.
I created this file in a debian preseed.cfg to set my target network configuration in a Debian fully automated installation.
Doing this on an Intel NUC, my internal NIC is now named eno1
by Debian 9.5 (stretch)