User Tools

Site Tools


haxx:tips:linux:no_predictable_network_names

disabling predictable network names in order to have predictable network devices

Classically, linux systems have adopted a network device naming scheme that abstracted away any notion of underlying hardware or driver.

Things like eth0 corresponded to an ethernet device, and in more recent years, wlan0 would correspond to wireless devices.

This was apparently undesirable, so of late custom names (including the MAC address in the network device name) have been adopted. I find this unnecessary, especially in simple setups where there is no risk of device changes.

Turn it off

So, how to restore desired functionality? On rasbian on a raspberry pi, the following may work:

What is there

In /lib/udev/rules.d/73-usb-net-by-mac.rules, we will see:

# Use MAC based names for network interfaces which are directly or indirectly
# on USB and have an universally administered (stable) MAC address (second bit
# is 0). Don't do this when ifnames is disabled via kernel command line or
# customizing/disabling 99-default.link (or previously 80-net-setup-link.rules).

IMPORT{cmdline}="net.ifnames"
ENV{net.ifnames}=="0", GOTO="usb_net_by_mac_end"

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}"

LABEL="usb_net_by_mac_end"

Change to

If we instead change that to (specifically, the NAME= field):

# Use MAC based names for network interfaces which are directly or indirectly
# on USB and have an universally administered (stable) MAC address (second bit
# is 0). Don't do this when ifnames is disabled via kernel command line or
# customizing/disabling 99-default.link (or previously 80-net-setup-link.rules).

IMPORT{cmdline}="net.ifnames"
ENV{net.ifnames}=="0", GOTO="usb_net_by_mac_end"

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="eth0"

LABEL="usb_net_by_mac_end"

We should be good to go.

Also, to avoid this file getting regenerated:

cp /lib/udev/rules.d/73-usb-net-by-mac.rules /etc/udev/rules.d/

Amusing, I have historically hated udev handling things, because its settings would often grow stale… now here we are intentionally making use of it in order to avoid some other nonsense.

pi cmdline.txt hack

Apparently, this whole process can be disabled right from /boot/cmdline.txt, by adding in net.ifnames=0:

root@pi3b:~# cat /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes net.ifnames=0 rootwait
haxx/tips/linux/no_predictable_network_names.txt · Last modified: 2018/04/11 07:24 by wedge