Rename network interface

Anyone tried to rename the network interface in a running container?

I have tried udev rules and systemd-networkd without any luck. This serverfault hints that it is possible with docker, but I am unsure if all the volume mounts are present in a running balena docker container.

I am running privileged and network_mode=host.

Use case is a device containing 4 NIC which needs to be named explicitly instead of getting the default NIC names

You may do that through the host OS:

This involves modifying the config.json of the device, which currently is not accessible from application containers, but you may add the necessary udev rules manually from a host OS terminal and reboot the device for those to take place.

Since the udev rule is entered in the json config, the quotes need to be escaped (shown in the docs). One approach is to target the interfaces by their persistent MAC address:

  "udevRules": { "10" : "SUBSYSTEM==\"net\", ACTION==\"add\", ATTR{address}==\"b8:15:61:20:9b:45\", NAME=\"newname1\"" } 

Please let us know if you have any questions.

Hi @majorz

Lets say I download a base os image and generate a config.json like this:

balena config generate --device ${BalenaDeviceUUID} --network ethernet --generate-device-api-key --version 2.39.0 --appUpdatePollInterval 10 --output config.json

Would it then be possible to manually add the “os” entry to the config.json and then perform balena os configure and hereby get the “os” entry into a flash image?

By doing this I do not need to modify all devices as the os entry is present from when the device was flashed.

Yes, this should be the best approach. You may use a tool like jq to insert the necessary entries in the config.json you would like to inject.

Now the tricky part would be the udev rule. MAC address will not be suitable, so you may play around with udevadm and see how you can target individual interfaces by a slot number or something similar.

Cool. I will look into it

Please post the udev rules you find on the thread as it will be interesting for us as well.

The following changes the interface name on pci level if multiple NICS are on the same network card:

"os":{ "udevRules": { "10" : "SUBSYSTEMS==\"pci\", ACTION==\"add\", KERNELS==\"0000:04:01.0\", NAME=\"test\"" } },

Wildcard may be need to change multiple NICs

Changes can also be done via MAC, but that may change:

"os":{ "udevRules": { "10" : "ACTION==\"add\", SUBSYSTEM==\"net\", ATTR{address}==\"00:00:00:00:00:00\", NAME=\"test\"" } },

Awesome, thanks @aliasbits for the info!

Note that pci level udev rules will match the motherboard and may not be reusable in a general manner.

Which means that software for different hardware must be injected with different udev rules when the flash image is created

Use udevadm info -a -p /sys/class/net/xxx for detailed udev matching information