Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save SwagDevOps/b2daafd7a5ece37e11d5624f927be708 to your computer and use it in GitHub Desktop.

Select an option

Save SwagDevOps/b2daafd7a5ece37e11d5624f927be708 to your computer and use it in GitHub Desktop.

Names incorporating the interfaces's MAC address

With systemd 197 we have added native support for a number of different naming policies into systemd/udevd proper and made a scheme similar to biosdevname's (but generally more powerful, and closer to kernel-internal device identification schemes) the default. The following different naming schemes for network interfaces are now supported by udev natively:

  1. Names incorporating Firmware/BIOS provided index numbers for on-board devices (example: eno1)
  2. Names incorporating Firmware/BIOS provided PCI Express hotplug slot index numbers (example: ens1)
  3. Names incorporating physical/geographical location of the connector of the hardware (example: enp2s0)
  4. Names incorporating the interfaces's MAC address (example: enx78e7d1ea46da)
  5. Classic, unpredictable kernel-native ethX naming (example: eth0)

source: PredictableNetworkInterfaceNames

/lib/systemd/network/99-default.link

# less /lib/systemd/network/99-default.link

Original

#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Link]
NamePolicy=kernel database onboard slot path
MACAddressPolicy=persistent

You SHOULD NOT modify this file, it COULD be regularly reverted by packages updates.

Edited

# /etc/systemd/network/99-default.link

[Match]
OriginalName=*

[Link]
NamePolicy=mac path
MACAddressPolicy=none

NamePolicy= An ordered, space-separated list of policies by which the interface name should be set. NamePolicy= may be disabled by specifying net.ifnames=0 on the kernel command line. Each of the policies may fail, and the first successful one is used. The name is not set directly, but is exported to udev as the property ID_NET_NAME, which is, by default, used by a udev(7), rule to set NAME. The policies used above are:

  • path The name is set based on the device's physical location, as exported by the udev property ID_NET_NAME_PATH.
  • mac The name is set based on the device's persistent MAC address, as exported by the udev property ID_NET_NAME_MAC.

source: systemd.link — Network device configuration

/etc/default/grub

GRUB_CMDLINE_LINUX="net.ifnames=1"
# sudo update-grub
# sudo update-initramfs -u
# sudo reboot

Check/ensure

# ls /sys/class/net/
(cd /sys/class/net && find * -maxdepth 1) | grep -Ev '^lo$' | \
  head -1 | \
  perl -pe "s/\n//" | \
  xargs -r0I {} sudo udevadm test /sys/class/net/{} 2> /dev/null | grep NAME

Sample output:

ID_NET_NAME_MAC=enx9c5c8e538309
ID_NET_NAME_ONBOARD=eno1
ID_NET_NAME_PATH=enp0s25

See also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment