HOWTO: Exchange WLAN0 <-> WLAN1 devicename?

I have both 2.4GHz WLAN and 5GHz WLAN on the router. However, device WLAN0 is the 5GHz.
Is there a possivility to permanently assign wlan0 to the 2.4GHz, and wlan1 to the 5GHz, when building custom image ?

root@OpenWrt:~# iw dev
Interface wlan1
channel 11 (2462 MHz), width: 20 MHz, center1: 2462 MHz
Interface wlan0
channel 36 (5180 MHz), width: 80 MHz, center1: 5210 MHz

:thinking: too difficult for me. Interesting question tough

By default the wlanX device name is derived from the radio phy. The first netdev on phy0 will be called wlan0, the first netdev on phy1 will be called wlan1 and so on.

The first spontaneous idea would be to simply swap the phy names from a hotplug script using a command sequence like:

iw phy phy0 set name phy_tmp
iw phy phy1 set name phy0
iw phy phy_tmp set name phy1

Unfortunately this does not work since the kernel explicitly forbids assigning phy<digit> names:

The code above allows names like phy<digit><digit> names though so I tried the following hotplug script:

root@OpenWrt:~# cat /etc/hotplug.d/ieee80211/09-swap-phy-names 

[ $ACTION = add ] || exit 0

if iw phy phy0 info 2>/dev/null | grep -q "5... MHz" && \
   iw phy phy1 info 2>/dev/null | grep -q "2... MHz";
	iw phy phy0 set name phy01
	iw phy phy1 set name phy00

The script is prefixed with 09- to precede the default 10-wifi-detect script which is responsible for enumerating the phys and generating the initial wireless config.

After staging this script and deleting /etc/config/wireless, the radio0 and radio1 identifiers will be swapped on the next boot (radio0 = 2.4GHz, radio1 = 5GHz).

Only downside is that the resulting wlan interfaces will be called wlan00 and wlan01 now instead of wlan0 and wlan1 respectively. If this is an issue, you can fix the names using the ifname option in the corresponding wifi-iface sections:

root@OpenWrt:~# iw list | grep Wiphy
Wiphy phy00
Wiphy phy01
root@OpenWrt:~# ip link | grep wlan
1020: wlan00: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-lan state UP qlen 1000
1021: wlan01: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-lan state UP qlen 1000
root@OpenWrt:~# uci set wireless.@wifi-iface[0].ifname=wlan0
root@OpenWrt:~# uci set wireless.@wifi-iface[1].ifname=wlan1
root@OpenWrt:~# uci commit wireless
root@OpenWrt:~# wifi
root@OpenWrt:~# ip link | grep wlan
1029: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-lan state UP qlen 1000
1030: wlan1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-lan state UP qlen 1000

However, when you change the names anyway, you can as well assign descriptive names to them, like phy_n and phy_ac which will yield interface names like wlan_n or wlan_ac (the wireless setup will strip the leading phy prefix and simply replace it with wlan as can be seen here:;a=blob;f=package/kernel/mac80211/files/lib/netifd/wireless/;h=e7d442f8ef1a0efb8087be90a740b4cd6348337f;hb=9b8ea3623b22509b7c5090dc50e18e9af1f13405#l451)

Wouldn't it be worth an official patch/update, to be applied for every device having 2.4g+5g ?

I consider it more natural, to have wlan0 for 2.4GHz, always. May be, just because of history, as 2.4 GHz was earlier.