USB ethernet not named eth1 on rpi4

Hi there,

I’ve been recently playing with a RPI3 and the Amazon basic USB gigabit ethernet adapter.
It works well. Automatically detects as eth1 interface.
Result from: nmcli d

DEVICE           TYPE      STATE         CONNECTION         
eth0             ethernet  connected     Wired connection 1 
supervisor0      bridge    connected     supervisor0        
eth1             ethernet  connected     eth1               
wlan0            wifi      disconnected  --                 
balena0          bridge    unmanaged     --                 
br-723d1e15cb31  bridge    unmanaged     --                 
resin-dns        bridge    unmanaged     --                 
lo               loopback  unmanaged     --                 
resin-vpn        tun       unmanaged     --                       

Now, on my RPI4, the behavior is different.
Result from: nmcli d

DEVICE           TYPE      STATE                                  CONNECTION         
eth0             ethernet  connected                              Wired connection 2 
supervisor0      bridge    connected                              supervisor0        
enp1s0u2         ethernet  connecting (getting IP configuration)  Wired connection 1 
wlan0            wifi      disconnected                           --                 
balena0          bridge    unmanaged                              --                 
br-aaf04606d358  bridge    unmanaged                              --                 
resin-dns        bridge    unmanaged                              --                 
veth7449af8      ethernet  unmanaged                              --                 
lo               loopback  unmanaged                              --                 
resin-vpn        tun       unmanaged                              --

Ideally I’d like it to appear directly as eth1 so it works well with some of the configsI’m using etc (same base code is going to run on Pi3 and Pi4).

Question is why not eth1 straight like on the rpi3, and how to change this?
Thanks!

1 Like

Out of interest, were you running the same version of balenaOS on both devices? (RPi3 and RPi4) Which version exactly?

I’ve found this other thread where the network interface is renamed through an udev rule, which sounds promising: Rename network interface

And also this other page (not balena specific) where they mention that a network interface could be renamed through a NetworkManager connection profile (nmcli connection modify ...): https://www.thegeekdiary.com/how-to-set-a-custom-interface-name-with-networkmanager-in-centos-rhel-7/

Perhaps you could try one of these approaches and let us know how it goes? :slight_smile:

RPI3 is balenaOS 2.43.0+rev1
And
RPI4 is balenaOS 2.41.0+rev4

I believe each are the latest recommended production ones.

Thanks for sharing these methods. I’m wondering - which would be the recommended on? And how can I have these executed automatically on the first device boot up. So nobody has to go-in each time to set it right.

@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)