Chasing systemd/udev network devices names

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
User avatar
Чебурашка
Posts: 6
Joined: 2023-05-17 06:35

Chasing systemd/udev network devices names

#1 Post by Чебурашка »

Hello,
I am using deb 12 with udev and systemd.

My problem is this: I have to deal with an array of lenovo devices (edge se-30) equipped with 2 ethernet ports (maybe more but here I car only about these). Depending on certain optionals of the device purchased that can vary from device to device (additional wlans, additional bluetooth or other things), the network interface names recognized by systemd/udev change. This is expected because this is how systemd/udev works after introduction of consistent naming schema policy some years ago (sometimes enp3s0 and enp8s0, sometimes enp46s0 and enp47s0, or other combinations).

I am fine with this and I don't want to rename to legacy naming schemas now discontinued(eth0).

After machine runs, I have some custom scripts needed to operate on the network interfaces. With the current situation basically what I need to do is: for each specific lenovo device I configure, I need to adjust the scripts (config files) in order to map to the actual network interface name present in that machine. This is a small modification but requires a person to be "trained enough" to know how to do this.

My idea is to modify these custom scripts so that they refer to "networkinterface1" and "networkinterface2" because all the machines I have to deal with do have at these interfaces and they are the only ones I am interested in.
In this way the scripts don't need to be modified every time a new specific lenovo device is configured.

To allow this I was thinking that I need a way to create an alias to the network interface, something like

Code: Select all

# ip link property add dev enp46s0 altname networkinterface1
and this has to be done at every reboot.

Can someone suggest some other way, maybe more compliant to the systemd/udev operating model to achieve my goal? The best would be to have something that does automatically adjust, but also a manually setup system would be ok as long as it has to be done once and is maintained across reboots/system ugrades.

:linked:

CwF
Global Moderator
Global Moderator
Posts: 3073
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 63 times
Been thanked: 254 times

Re: Chasing systemd/udev network devices names

#2 Post by CwF »

Create link files to match MAC's. Do not use matchable strings as the link name. Nearly every network device has a MAC printed on a label somewhere so that the OS can be prepared before ever using the device, this is how we get a system to boot up with correct networking on first boot. The GUI interfaces and scripts should be configured with FriendlyName. Any number of devices can point to a common FriendlyName as long as it's only possible for one to be present at a time.

Code: Select all

#/etc/systemd/network/10-[devicename]-[name].link
[Match]
MACAddress=00:00:00:00:00:00
[Link]
Name=FriendlyName
Mottainai

Aki
Global Moderator
Global Moderator
Posts: 3950
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 109 times
Been thanked: 518 times

Re: Chasing systemd/udev network devices names

#3 Post by Aki »

Hello,

Following up the previous post by @CwF, just a little addendum:
  • Debian Wiki > NetworkInterfaceNames > CUSTOM_SCHEMES_USING_.LINK_FILES:
    CUSTOM SCHEMES USING .LINK FILES

    The scheme detailed above is the new standard default, but there's also a canonical way of overriding the default: you can use .link files to set up naming policies to suit your needs. Thus for instance if you have two PCs each of which has only a single wireless card, but one calls it wlp0s1 and the other wlp1s0, you can arrange for them both to use the name wifi0 to simplify sharing firewall configurations. For details see systemd.link(5).

    Here's a relatively futureproof "manual" version of the example given above:

    #/etc/systemd/network/10-persistent-net.link

    Code: Select all

    [Match]
    MACAddress=01:23:45:67:89:ab
    
    [Link]
    Name=lan0
    
    Note: per systemd.link(5), you shouldn't use a name that the kernel might use for another interface (for example "eth0").

    If instead of trusting your new policies to work after a reboot you want to take things step by step:
    • 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

    Code: Select all

    [Match]
    OriginalName=*
    
    [Link]
    NamePolicy=mac
    MACAddressPolicy=persistent
    
Hope this helps.
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

Aki
Global Moderator
Global Moderator
Posts: 3950
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 109 times
Been thanked: 518 times

Re: Chasing systemd/udev network devices names

#4 Post by Aki »

Hello @Чебурашка,

I assume you sorted it out.

Can you please confirm ?

Thanks.
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

Post Reply