Network interface name

From HPCWIKI
Revision as of 13:51, 27 May 2023 by Admin (talk | contribs) (Created page with "The Linux kernel assigns names to network interfaces, nowaday there are multiple network interface naming scheme is available and each has pros and cons. == Simple scheme == <code>eth0</code>, <code>eth1</code>, etc were simply assigned by the kernel. There are many possible way to use this scheme, * . reboot with the kernel parameter <code>net.ifnames=0</code>, or made persistent by editing <code>/etc/default/grub</code> and running <code>update-grub</code> * ove...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The Linux kernel assigns names to network interfaces, nowaday there are multiple network interface naming scheme is available and each has pros and cons.

Simple scheme

eth0, eth1, etc were simply assigned by the kernel.

There are many possible way to use this scheme,

  • . reboot with the kernel parameter net.ifnames=0, or made persistent by editing /etc/default/grub and running update-grub
  • override /lib/systemd/network/99-default.link, with a custom version in /etc/systemd/network/, or similarly override /lib/udev/rules.d/80-net-setup-link.rules, or mask the latter by using a /dev/null symlink instead of a custom version, or...

Persistent names scheme

udev to identify interfaces by MAC address and assign a fixed interface number to any interface by writing the rules to /etc/udev/rules.d/xxx.rules

for example,

#/etc/udev/rules.d/70-persistent-net.rules
# PCI device 0x8086:0x100e (e1000e)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="aa:bb:cc:dd:ee:ff", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Predictable names scheme

Red Hat Enterprise Linux uses predictable network interface names. These names are stable across reboots and network adapter replacements[1]

Custome names scheme[2]

Using systemd.link

#/etc/systemd/network/10-persistent-net.link
[Match]
MACAddress=01:23:45:67:89:ab

[Link]
Name=lan0

To verify the new policies to work after a reboot,

  • run udev control --reload (or /etc/init.d/udev force-reload, or service udev force-reload)
  • then
    • for hotplug NICs, disconnect and reconnect them (or unload/reload the driver; if your SSH session doesn't go through this NIC...)
    • for non-hotplug NICs, run udevadm trigger, then check the logs (your SSH connection should still be okay even if your .link file was rejected as nonsense), then restart networking.

It is also possible to reorganize the naming policy by overriding /lib/systemd/network/99-default.link, for instance to insist that all network interfaces are named purely by MAC address:

 #/etc/systemd/network/99-default.link
 [Match]
 OriginalName=*

 [Link]
 NamePolicy=mac
 MACAddressPolicy=persistent

References