Help with hotplug config for USB ETH modules

Hello,

I have a RPi zero W with Waveshare ETH/USB hat. An USB LTE dongle is connected to that hat.
Both are recognized as a ETHxx port, but sometimes they switch names (ETH0 and ETH1). I cannot configure them right when they don't have persistent names.

I read about it on this forum, and with Hotplug this problem can be solved
I tried to understand and configure it, but unfortunately failed. Can someone help me with step-by-step instructions?

Make sure you read the linked threads too Stable network interface names for USB Ethernet Dongles

This hotplug script should swap eth0 and eth1 if the MAC address of eth1 is not the expected one.
I assume the interface names are lowercase. Otherwise, fix them accordingly.

cat << "EOF" > /etc/hotplug.d/iface/10-swap_eth_ifaces
[ "$ACTION" == "ifup" -a "$DEVICE" == "eth1" ] || exit 0

	eth1mac="00:11:11:33:44:55" # The correct eth1 MAC address here
	currmac=$(ip link show dev eth1 | grep link | awk '{print $2}')

if [ "$eth1mac" != "$currmac" ]; then
	
	ip link set eth0 down
	ip link set eth0 name tmp
	ip link set eth1 down
	ip link set eth1 name eth0
	ip link set eth0 up
	ip link set tmp name eth1
	ip link set eth1 up
	exit 0
else
	exit 0
fi
EOF
3 Likes

Hi Pavel,

Thanks for your help.

should this also work voor wlan0 and wlan1 (after changing naming and mac address accordingly)? Or does that also change the code on other points?

Sorry, I don't follow you...
What are the problems with the wireless interfaces, so you have to play with their names too?

The code you provided works great on the eth devices. I expected it to work also on the two wlan devices (RPi has one and there is one USB wifi device). But for some reasons that doesn't work well.

When starting the router without the usb device connected, wlan0 is the RPi onboard wifi devices. But with the usb wifi device connected at startup, wlan0 is the usb device, and wlan1 is the onboard RPi device.

Your code swaps the devices when eth1 does not have the expected mac-address. I guess another way could be that at startup or when an usb device is connected, the (new) device will get it's name (wlan0, wlan1) based upon the mac address.

When configuring a wifi-iface (in /etc/config/wireless), you can define a name for the corresponding wlan device (option ifname 'wlan0'). Connect this wifi-iface with the network, which has eth0 as its wired interface. That's all. Good luck.

1 Like

Like this?

config wifi-device 'radio0'
        option ifname 'wlan0'
        option type 'mac80211'
        (...)

It doesn't solve the problem.
After booting with the usb wifi device disconnected, RPi onboard wifi device = wlan0
After booting with the usb wifi device connected, RPI onboard wifi device = wlan1, usb wifi device = wlan0
So the names are not persistent.

The ifname option must be set in the wifi-iface, not in the wifi-device section.

If the idea is just to keep the interface names persistent, you could try the following:

Rename the onboard wifi-device to radio1 and set the interface name to wlan1.
Thus, the embedded device should always use these names.

config wifi-device 'radio1'
        ...

config wifi-iface 'default_radio1'
        option device 'radio1'
        option ifname 'wlan1'
	    ...

Then plug in the usb wifi device and see if it will take the vacant radio0/wlan0

Unfortunately I don't have the necessary equipment to test it so I can't say how it will work.

As @pavelgl already wrote: The ifname option must be set in the wifi-iface , not in the wifi-device section.

This works for me on a Linksys WRT1900ACS with OpenWrt 19.X. I guess, it should work in newer version of OpenWRT too. Did you try it?

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.