My general questions is how to make sure an Ubuntu 24.04 system only uses the highest-priority network interface (where I set the priority myself)? Preferably in an user-friendly and "official" way?
To make it more clear what I mean, this is my specific usecase: I run Ubuntu 24.04, very much stock using the default Gnome desktop environment and Network Manager in charge of networks, on an old HP laptop which only has a 2.4 GHz Wifi module. It has a wired Ethernet port, and I also have a 5 GHz Wifi USB dongle. What I want is this:
- If the wired ethernet port is connected, only use that and don't bother about any Wifi ports whatsoever.
- If the USB dongle is attached, use that one to connect to a 5 GHz Wifi AP (obviously with pre-stored credentials)
- In other cases, use the internal 2.4 GHz Wifi module to attach to a 2.4 GHz Wifi AP
Also, I'd like a "user-friendly" way of fixing this so that non-technical members of the household can just plug in the USB dongle if they want better coverage.
What happens, is that both Wifi adapters get assigned a valid IPv4 address, both end up in the routing table.
To be clear, both internal Wifi and the USB Wifi dongle work, but the problem is that both connect at the same time to two different SSIDs on the same IPv4 subnet, and the 2.4 GHz link is very unstable (due to too many neighbors with 2.4 GHz Wifi APs whose signals reach into my home).
I have tried or considered these things:
- Disabling the internal Wifi module using the settings dialogs. This ended up disabling both the internal module and the USB Wifi dongle. Doesn't work.
- Using
rfkill
to disable the internal module - But this also has the effect of disabling the USB Wifi dongle, even when only blocking the internal 2.4 GHz module. I suppose it is NetworkManager that interprets any blocked Wifi device to block all of them. Doesn't work. - Deleting the routes that involve the 2.4 GHz Wifi module, using
ip route del
. This works, in the sense that the connections to the Wifi APs remain, but no traffic is routed over the 2.4 GHz link. This works, sort of, but the routes get re-added if the laptop switches to another AP, so not a stable long-term solution. - Using
ip link set dev DEVICE down
on the 2.4 GHz Wifi interface, when a 5 GHz device is detected. This is almost the same solution as deleting the routing entries above, have not tested this but this should work unless Network Manager re-ups them. - Blacklisting the driver for internal module. Will not be a workable solution, since it's not acceptable to reboot every time the USB Wifi dongle is attached/removed.
- Deleting all 2.4 GHz AP credentials. Not acceptable, since I want the laptop to be "seamlessly" usable even if the USB Wifi dongle is removed.
Is there a completely different method I'm missing? If not, I guess a script that monitors the state of the various adapters is needed, that uses ip route
/ip link
commands to disable the lower-prio interfaces whenever higher-prio interfaces are detected.
I realize this precludes having different network adapters connected to different networks, but if I ever have that specific usecase, I'll sort it out then.
Advanced Network Configuration
That is the name of the app you are looking for. Search for Advanced Network Configuration also called the Network Connections and open the app. You will see something like this:
You will be able to configure the settings of both the Ethernet connection and the two WiFi connections. Note, The WiFi connections won't be identified by their radio frequencies, 5Ghz and 2.4Ghz. They may be called something like
Give highest priority to Ethernet
Give Medium priority to 5Ghz WiFi
Follow the same steps as above for the AP of the 5Ghz WiFi.
Give Lowest priority to 2.4Ghz WiFi
Since the default is 0, you don't have to change anything as long as the other two have higher priority.
Clarification
The actual numbers are not important as long as the Ethernet has the highest and the 5Ghz WiFi has the middle value. Higher number has higher priority.
In this example:
Hope this helps