Stable network interface names for USB Ethernet Dongles

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 @anon50098793 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?

I don't really need more testing... hotplug edits and whatnot I would look at... ( but feel free to keep testing / trying if your interested )

As it stands (re: build)... it's more a question of;

build-stuff
  • how many users would use this ( 6-7+ )
  • clean user hooks (noob friendly config)

if one is capable of editing a config file... technically they are capable of adding the init script and sysupgrade.conf line...?

but you can ask about that on the build thread...

edit: on second thought one thing that would be useful to test is mac-override...

cancel-that

/etc/config/network

option macaddr '00:11:32:96:42:65'

then try either this fake mac or the real mac in the config (mac-static-interfaces) file... rebooting after each test...

I have a feeling that if you have two lines for say 'eth3' with both the fake and real macs... it would work...

the script reads the MAC from /sys/class/net/eth0/address (eth0 is an example of interface name).

if it is run on boot it will always use real mac because it is run BEFORE the network init script so nobody has changed the MAC. If it is run later it depends from what that file contains.

The issue is that if your interfaces are assigned randomly on boot why are you assigning a MAC to a device name (which can be a different interface on next boot) from that config file?

1 Like

right... gotcha... so we need to handle at final move...

what do you want to do exactly?

well... my wan is mac-cloned...

so... I can't present a new mac to the arris hfc... won't issue an ip

( technically I could wait 30mins / phone them to remove the clone requirement but the idea is to keep this static in the router and ensure it is always this value to make it idiot proof )

(i'm happy to iron it out...) @vgaetera s wiki hotplug solution reverse walks uci from hotplug re-assigning correct detected interface name... (needs work for new device syntax, when finalized)... which would might work... just need to find energy to dive into it properly...

on second thought... for your script... (forgetting about hotplug for a second) i'd probably need to add a earlier step / config option to handle the mac change first from a separate value/value-pair...

finally got around to simplifying a hotplug version... (draft needs testing)

cheated a little... as requires the user to manually enter the new device name as well as the mac into uci network config...

(does not support non-single-network-device-sections or non-usb devices at present... optional standard macaddr entries should be honoured)

1 Like