@xyala, I’ve now successfully tested the udev method as follows.
First, I was able to reproduce the enp1s0u2 interface name with a USB-Ethernet adapter, using an RPi4 device running balenaOS 2.44.0+rev3:
$ dmesg
...
[ 394.126615] ax88179_178a 2-2:1.0 eth1: register 'ax88179_178a' at usb-0000:01:00.0-2, ASIX AX88179 USB 3.0 Gigabit Ethernet, 00:0e:c6:aa:cb:79
[ 394.154992] ax88179_178a 2-2:1.0 enp1s0u2: renamed from eth1
Note the last line above: enp1s0u2: renamed from eth1. Colleagues have pointed out that this appears to be the “Predictable Network Interface Names” feature; some references: ref1, ref2, ref3.
Then I edited the config.json file (on the root of the SD card) to add an udev rule to rename the interface to newname1:
"os":{
"udevRules": { "10" : "SUBSYSTEM==\"net\", ACTION==\"add\", ATTR{address}==\"00:0e:c6:aa:cb:79\", NAME=\"newname1\"" }
},
This rule matches on the MAC address of my network interface (00:0e:c6:aa:cb:79), but it should be possible to write a rule that matches on vendor and product IDs listed with lsusb -v, in case you wanted to write a single rule for all devices in your fleet. More on udev rules: ref4, ref5, ref6.
Then I created a single-container (‘main’) balena app with this trivial Dockerfile:
FROM balenalib/raspberrypi3:stretch
ENV UDEV=1
CMD ["/bin/bash"]
In my experiment, it was important to use a balenalib base image (in the FROM Dockerfile line) because then my Dockerfile “inherits” the default ENTRYPOINT ["/usr/bin/entry.sh"] instruction; references: ref7, ref8.
Then after pushing the app and rebooting the device, the interface was renamed to newname1, as per udev rule:
$ dmesg
[ 7.996531] ax88179_178a 2-2:1.0 eth1: register 'ax88179_178a' at usb-0000:01:00.0-2, ASIX AX88179 USB 3.0 Gigabit Ethernet, 00:0e:c6:aa:cb:79
[ 8.103277] ax88179_178a 2-2:1.0 newname1: renamed from eth1
$ ifconfig
...
newname1 Link encap:Ethernet HWaddr 00:0E:C6:AA:CB:79
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)