Stable network interface names for USB Ethernet Dongles

Given what you also said in the OP, I'd guess this is more of a raspberry issue:

When I plugged the ASIX USB device directly into my laptop and went direct laptop->server I got 900+ Mbps, so the USB device is capable of handling near line speed.

which is also what I've noticed. I've been using ASIX USB dongles (Ugreen brand of USB 3.0 gigabit dongles, specifically) on a Linux-based DYI NAS that has been transferring data at nearly line speed for days on end, and they are perfectly fine, also used for passthrough around in VMs (windows or linux) and so on, never had a problem in years.

A few realtek USB dongles I tried tend to crap out after a hour or so of actual serious use, and may or may not like being passed through without being unplugged first. This is also the case on a Macbook when syncing data to the same NAS (using a different dongle but stil a realtek chipset).

that said, if you also actually look at the market, dongles with ASIX chipsets are more expensive than ones with Realtek chipsets.
Or at least if you look at sub-10 euro dongles on ebay you only get stuff with Realtek chipsets.

EDIT: speaking of raspberry and ethernet, recently a youtuber also did some benchmarking of raspberry CM4 on two "router" boards, one with ethernet on PCIe and one with Ethernet on USB.

It had similar results to you, top speed was lower and throughput was less than half with the USB ethernet controller https://www.youtube.com/watch?v=w7teLVwi408 (skip to 10:40 to see the graph)

1 Like

On my next build I am going to try the script @bobafetthotmail posted. It seems simple enough which is good for a guy like me that was banned from writing code in 1999. Its a long story......

But seriously, for novice users, a LUCI page could probe for the mac addresses and ask the user to assign them, then generate the config file at /etc/config/mac-static-interfaces. @anon50098793 perhaps the default on the build is not to bring up interfaces if we detect them to be USB until this is done. Kindly take this all in the context of a noob trying to do everything via LUCI...

1 Like

good idea... re-reading how it works... it bypasses the need to 'swap' names... so you don't need to use new uniq names...

probably more sensible in retrospect...

point taken... and thanks... can't exactly work like that due to interactions with typical OS functions... but I do understand the point you are making and will consider it if tackling this again...

I never would have gotten this far without you :slight_smile:

Thank you for everything you've done to make this work.

I have been experiencing issues with the realtek chipsets from 2 vendors. The dongles seem to get hot to the touch and crap out. This has happened on OPENWRT on the PI and now with OPNSENSE on an i7 PC when there is no load on the router, just the MWAN pinging every minute. I put a fan on the dongle to stabilize it. Really odd behavior.

If you would report the mfg, brand, product ID etc to the thread on dongle reliability that'd be great.

Dongle collection....

that's a very dramatic thing to say, but ok.
I mean I'm not a programmer either but I can hack together some shell (Linux) or batch (Windows) scripts with the help of online documentation and tutorials.

The config file is written with OpenWrt standard configuration syntax so people can add a Luci package to manipulate the config.

If someone wants to do that I can submit my script as a package in the package feed (technically speaking it's already a package, just a local package I use in my builds).

@bobafetthotmail now that I re-read what I wrote, it is pretty dramatic. So Explanation. Sometime in 1999 some really smart guys code reviewed the c++ I had checked into the build and told me there were things that I was pretty good at and coding was not one of them. They strongly recommended I should stick to what I am good at :-(.

Unfortunately, I never learned to write bash hence my pleas for help.

Ok, with the following instructions the script will be run on device start and will assign the interface name you want to a device that has the MAC address you want, for all devices defined in the config file.
Devices not defined in the config will be ignored. It's better if you define all network interfaces you have in the config.

You need to put the script in /etc/init.d folder and call it staticeth (or whatever you want, name does not matter)

#!/bin/sh /etc/rc.common

START=11

# don't run within buildroot
[ -n "${IPKG_INSTROOT}" ] && return 0

#use busybox grep as GNU grep may be set differently and break the script
grep(){
/bin/busybox 'grep' $@
}

#shutting down all interfaces, then assigning temporary name to free up interface names
#bridges and virtual interfaces are already excluded by  /sys/class/net/*/device/uevent as only physical interfaces have that
for i in $( ls /sys/class/net/*/device/uevent | awk -F'/' '{print $5}' | tr '\n' ' ' ) ;
do

	mac_address=$( grep $i /etc/config/mac-static-interfaces | awk '{print $3}' | tr -d '"' )
	if [ "$mac_address" != '' ]; then
	
		ip link set "$i" down 
		ip link set "$i" name old"$i"
		
	fi
done

for i in $( ls /sys/class/net/*/device/uevent | awk -F'/' '{print $5}' | tr '\n' ' ' ) ;
do

mac_address=$( cat /sys/class/net/$i/address  )
	interface_name=$( grep -i $mac_address /etc/config/mac-static-interfaces | awk '{print $2}' )
	if [ "$interface_name" != '' ]; then
	
		ip link set "$i" down 
		ip link set "$i" name "$interface_name"
		
	fi
done

Then make it executable with
chmod +x /etc/init.d/staticeth

Then "enable" it to make it start as a service when the system is turned on.

service staticeth enable

now create the config file
/etc/config/mac-static-interfaces

and write the interface name and the mac address of the devices you want to remap. The interface names and mac addresses below are just examples, please write the right ones for your device.

config mac-static-interfaces
	option eth0 "70:85:c2:8a:57:4d"
	option eth6 "00:0e:c6:70:2a:22"
	option eth8 "00:0e:c6:c3:82:a6"

Then after you are done, restart the raspberry

5 Likes

yes, although I'm dumb and originally I copied only half of it, now the script is complete (both in that post and in my answer to the other guy).

It is simply run on boot and will rename interfaces with a temporary name to "make space" if the same name already exists before doing the actual rename so you can freely choose interface names. It is run before network service but after hardware initialization so it should not screw up network.

If you want to call it after device boot (like by a script in /etc/hotplug.d to react to hotplugged devices), call the script and then service network restart to force network service to adjust to new device names.

2 Likes

Thanks for posting.

I configured and ran. It broke after the rename and I am left with interfaces named "old".

I think I have a problem with my bridge config and am generating one less interface than I should have and am breaking the "for i in... " loop. Will work on it more tomorrow.

thanks for all your help.

having more or less interfaces shouldn't change much, and afaik it should already ignore the bridges

I assume you are using interface names like eth0 eth1 ecc, right?

Can you post the result of
ip a

and

ls /sys/class/net/*/device/uevent

the first should list all interfaces and the second command should list all interfaces the script can work on.

Also if you run the script manually with service staticeth restart does it print errors?

I lost access to the router after running so I plugged in another dongle which I think is #17 in the following ip a

root@rpi-dca63263b8 /39# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: oldeth0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether dc:a6:32:63:b8:7d brd ff:ff:ff:ff:ff:ff
3: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN group default qlen 1000
    link/tunnel6 :: brd ::
4: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/ipip 0.0.0.0 brd 0.0.0.0
5: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
6: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether de:f9:ac:99:e8:09 brd ff:ff:ff:ff:ff:ff
7: gre0@NONE: <NOARP> mtu 1476 qdisc noop state DOWN group default qlen 1000
    link/gre 0.0.0.0 brd 0.0.0.0
8: gretap0@NONE: <BROADCAST,MULTICAST> mtu 1476 qdisc noop state DOWN group default qlen 1000
    link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
9: erspan0@NONE: <BROADCAST,MULTICAST> mtu 1464 qdisc noop state DOWN group default qlen 1000
    link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
10: ip6gre0@NONE: <NOARP> mtu 1448 qdisc noop state DOWN group default qlen 1000
    link/gre6 :: brd ::
11: teql0: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 100
    link/void
12: oldeth1: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 00:0e:c6:70:bf:6a brd ff:ff:ff:ff:ff:ff
13: oldeth2: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 00:0e:c6:62:e2:b2 brd ff:ff:ff:ff:ff:ff
14: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br-wifi state UP group default qlen 1000
    link/ether dc:a6:32:63:b8:7e brd ff:ff:ff:ff:ff:ff
    inet6 fe80::dea6:32ff:fe63:b87e/64 scope link
       valid_lft forever preferred_lft forever
16: br-wifi: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether dc:a6:32:63:b8:7e brd ff:ff:ff:ff:ff:ff
    inet 10.10.90.1/24 brd 10.10.90.255 scope global br-wifi
       valid_lft forever preferred_lft forever
    inet6 fe80::dea6:32ff:fe63:b87e/64 scope link
       valid_lft forever preferred_lft forever
17: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br-lan state UP group default qlen 1000
    link/ether 00:0e:c6:62:e2:b1 brd ff:ff:ff:ff:ff:ff
18: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0e:c6:62:e2:b1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 brd 192.168.1.255 scope global br-lan
       valid_lft forever preferred_lft forever
    inet6 fd52:2bc3:b646::1/60 scope global noprefixroute
       valid_lft forever preferred_lft forever
    inet6 fe80::20e:c6ff:fe62:e2b1/64 scope link
       valid_lft forever preferred_lft forever
root@rpi-dca63263b8 /40# ls /sys/class/net/*/device/uevent
/sys/class/net/eth0/device/uevent     /sys/class/net/oldeth1/device/uevent  /sys/class/net/wlan0/device/uevent
/sys/class/net/oldeth0/device/uevent  /sys/class/net/oldeth2/device/uevent
root@rpi-dca63263b8 /38# lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
    |__ Port 1: Dev 2, If 0, Class=, Driver=ax88179_178a, 5000M
    |__ Port 2: Dev 3, If 0, Class=, Driver=ax88179_178a, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=, Driver=hub/4p, 480M
        |__ Port 4: Dev 3, If 0, Class=, Driver=asix, 480M

Please use the "Preformatted text </>" button for logs, scripts, configs and general console output.
grafik
Please edit your post(s) accordingly. Thank you! :slight_smile:

also post

cat /etc/config/mac-static-interfaces
2 Likes

Done and done

root@rpi-dca63263b8 /38# cat /etc/config/mac-static-interfaces
config mac-static-interfaces
        option eth0 "DC:A6:32:63:B8:7D"
        option eth1 "00:0E:C6:70:BF:6A"
        option eth2 "00:0E:C6:62:E2:B2"
        option eth8 "A0:CE:C8:D9:2D:E4"
1 Like

So yeah it's my script that isn't handling MAC addresses with UPPER CASE letters like you wrote.

MAC addresses are correct in both "lower case" and "UPPER CASE" so what you wrote was not wrong.

please find and edit the following line in the script
interface_name=$( grep $mac_address /etc/config/mac-static-interfaces | awk '{print $2}' )

to become

'interface_name=$( grep -i $mac_address /etc/config/mac-static-interfaces | awk '{print $2}' )'

or copy-paste again the whole script from above

And then reboot.

1 Like

and dont forget to run this command so they come up properly when you upgrade;

echo "/etc/init.d/staticeth" >> /etc/sysupgrade.conf
1 Like