Stable network interface names for USB Ethernet Dongles

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

2 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

OK definitely getting better. Changed the script. After running service staticeth restart it appears the renames worked (eth8 was eth3) but the interfaces are down and LUCI reports error: unknown error (DEVICE_CLAIM_FAILED) on the interfaces tab.

ip a follows:

root@rpi-dca63263b8 /42# 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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br-lan state UP 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 62:04:56:c4:36:f6 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: eth1: <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: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 00:0e:c6:62:e2:b1 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: eth8: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether a0:ce:c8:d9:2d:e4 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 dc:a6:32:63:b8:7d 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::dea6:32ff:fe63:b87d/64 scope link
       valid_lft forever preferred_lft forever

read above or reboot

2 Likes

Ok so the script did its job. Changing interface names on the fly does confuse OpenWrt networking service so if you run the script manually like that, you need to also do
service network restart
so the OpenWrt system sees the changed interfaces

Otherwise you can just reboot, the system will run it before network service is started.

1 Like

Service restart worked, end user needs to RTFM :pleading_face: :pleading_face: :pleading_face:

@bobafetthotmail this is awesome. There are a number of threads out there pleading for this.

What other testing can I do to help bulletproof this so @wulfy23 can add it to his build?

More dongles? Add hubs and dongles? or will that not matter?

Assume I should do something with hotplug? Do we need two versions, one for boot and one for hotplug with service restart?