How to rename eth0 ... etc

Hello everyone,

I would like to rename additional network adapters on a custom carrier board on an apalis imx8qm module with Torizon OS so that they are more descriptive of the respective sockets.
How do I do that?
My udev rule always only used the ethernet0 interface. :sob:
A /etc/systemd/network/*.link entry with Match MACAddress or and Path= had no effect. :angry:

The network chips are soldered / connectet onto the board with the USB hubs on the module. They appear as eth0 … 2 in the system and work perfectly. Unfortunately, the names do not appear uniformly on all boards in relation to the sockets.

Best
Gerald

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           5.15.148-6.7.0-devel+git.f437ddb7191d #1-TorizonCore SMP PREEMPT Mon Jul 1 08:03:31 UTC 2024
Kernel command line:      root=LABEL=otaroot rootfstype=ext4 quiet logo.nologo vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fbcon=map:3 ostree=/ostree/boot.1/torizon/0c2a7a82ae747ce050db101a71d4db0b7ea8d5c0d37c60af689476a0c166dc37/0
Distro name:              NAME="TorizonCore"
Distro version:           VERSION_ID=6.7.0-devel-20240701080203-build.0
Distro variant:           VARIANT="Docker"
Hostname:                 apalis-imx8-07279040
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Apalis iMX8QM V1.1 on Apalis Ixora V1.2 Carrier Board
Toradex version:          0037 V1.1E
Serial number:            07279040
Processor arch:           aarch64

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Gerald,

Renaming network interfaces on your Apalis iMX8QM module with Torizon OS can indeed help in making them more descriptive and consistent across different boards. You can achieve this using NetworkManager, which is the default network management tool on Torizon. Here’s a step-by-step guide to help you:

  1. Identify the Interfaces: Start by identifying the current names and MAC addresses of your network interfaces. You can do this by running the following command:

    nmcli device
    

    This command will list all network interfaces along with their MAC addresses.

  2. Create a NetworkManager Configuration: For each interface you want to rename, create a configuration file in the /etc/NetworkManager/system-connections/ directory.

  3. Edit the Configuration File: For each interface, create a file with a .nmconnection extension. Here’s an example configuration to rename an interface based on its MAC address:

    [connection]
    id=DescriptiveName
    uuid=<unique-uuid>
    type=ethernet
    interface-name=DescriptiveName
    
    [ethernet]
    mac-address=<MAC-address>
    

    Replace <unique-uuid> with a unique identifier, which you can generate using uuidgen, and <MAC-address> with the actual MAC address of the interface.

  4. Apply the Configuration: Once you’ve created the configuration files, restart NetworkManager to apply the changes:

    sudo systemctl restart NetworkManager
    
  5. Verify the Changes: Finally, use nmcli device again to verify that the interfaces have been renamed as expected.

This method should help ensure that your network interfaces are consistently named based on their MAC addresses, resolving the issue of inconsistent naming across different boards. If you encounter any issues, double-check that the MAC addresses in your configuration files are correct and that the UUIDs are unique for each interface.

I hope this helps! If you have any further questions, feel free to ask.

Best regards,
Toradex AI Assistant

Please, also check if these links can help you solve your problem:

Change /dev/input/event*.

Hi @gerko !

It is possible that your .link file is loosing the race against Torizon OS’s default udev rule that renames the network interface in /etc/udev/rules.d/10-toradex-net-rename.rules.

Could you test by simply disabling it? For instance, you can add a leading # to the rule’s content so it becomes a comment.

This might make your .link work since this udev rule won’t be in the way.

I tested it on Torizon OS 6.8.0.

Best regards,

Thanks for the quick reply,

I doubt that the suggested solution would have helped in my case. The script (/usr/bin/toradex-net-rename.sh) that is called within the rule only handles 2 ‘real’ network adapters (not connected via USB)

But I found an answer myself:

I’ve worked through these instructions: systemd.link

The USB path can be found under ID_PATH if you call up, for example:
udevadm info /sys/class/net/eth0

An example .link file could look like this:

[Match]
Path=platform-ci_hdrc.1-usb-0:1.3.1:1.0

[Link]
Name=eth_as_i_need_it0

thanks, nevertheless,

I would still like to know where the names eth0 … ethX are assigned.
From the kernel logs you can see:

[    1.354298] fec 5b040000.ethernet: Adding to iommu group 0
[    1.640023] fec 5b040000.ethernet eth0: registered PHC device 0
[    6.641020] fec 5b040000.ethernet ethernet0: renamed from eth0

later:

[    7.882255] SMSC LAN8710/LAN8720 usb-004:004:01: attached PHY driver (mii_bus:phy_addr=usb-004:004:01, irq=POLL)
[    7.901797] smsc95xx 4-1.3.1:1.0 eth0: register 'smsc95xx' at usb-ci_hdrc.1-1.3.1, smsc95xx USB 2.0 Ethernet, 8e:ef:41:01:67:bd

[    8.071378] SMSC LAN8710/LAN8720 usb-004:005:01: attached PHY driver (mii_bus:phy_addr=usb-004:005:01, irq=POLL)
[    8.072561] smsc95xx 4-1.3.2:1.0 eth1: register 'smsc95xx' at usb-ci_hdrc.1-1.3.2, smsc95xx USB 2.0 Ethernet, 82:03:ad:93:08:9c

[    8.252628] SMSC LAN8710/LAN8720 usb-004:006:01: attached PHY driver (mii_bus:phy_addr=usb-004:006:01, irq=POLL)
[    8.253444] smsc95xx 4-1.3.3:1.0 eth2: register 'smsc95xx' at usb-ci_hdrc.1-1.3.3, smsc95xx USB 2.0 Ethernet, c2:cf:69:7f:96:d7

I would assume that when the KSZ9031 network adapter appears, a driver assigns a name like eth#, the udev rule renames it to ethernet0 (???) and then the recognition of the USB Ethernet adapter starts. The driver then starts naming again from 0.

It would be nice to know exactly.

Best Regards
Gerald

Hi @gerko !

You are right. I overlooked it. The Udev rule 10-toradex-net-rename.rules that calls the toradex-net-rename.sh indeed filters by the MAC Address "00:14:2d*". This should not affect your USB-Ethernet interface.

Sorry for overlooking :sweat_smile:
But good to know that you managed to make it work. And thanks for sharing here your solution! :smiley:
I am marking your message as the solution :wink:

Searching for eth% in the folder drivers/net/usb of the Linux kernel, we find:

[ linux-toradex_5.15-2.2.x-imx(toradex_5.15-2.2.x-imx✔) ] 
 $ rg 'eth%' drivers/net/usb
drivers/net/usb/ipheth.c
446:    strscpy(netdev->name, "eth%d", sizeof(netdev->name));

drivers/net/usb/usbnet.c
1751:           // else "eth%d" when there's reasonable doubt.  userspace
1756:                   strscpy(net->name, "eth%d", sizeof(net->name));

With this, I assume that either ipheth.c or usbnet.c are responsible for giving that first eth0 name to it.

Best regards,