Output of `nmcli device wifi list` is often nearly empty on Ubuntu 18.04
When I moved from Ubuntu 14.04, to Ubuntu 18.04, I noticed that often the output of nmcli d wifi
would, instead of listing a bunch of visible access points, only lists the access point that the computer is connected to.
An example of this looks like:
me@computer:~$ sudo nmcli device wifi list
IN-USE SSID MODE CHAN RATE SIGNAL BARS SECURITY
* XYZ Infra 161 540 Mbit/s 67 ▂▄▆_ WPA2
This can be "fixed" by manually invoking sudo iw wlan0 scan
, and then re-running the above and seeing the nearby APs as expected.
My understanding is that periodically, the system is doing scans automatically (every 300s, if I recall correctly from past research). It seems as if in the meantime, Ubuntu/NetworkManager is deciding to discard what it knows from the last scan.
Is this a known change, and/or a feature, or a bug? Can this be changed? When researching, I regularly end up at this question, which suggests that the scan frequency is driven by NetworkManager and is hardcoded.
So far, I have seen this behavior with the Intel 7260, 8260, and 9260 wifi cards, as well as an Atheros wifi card, so I am fairly certain this is not a hardware issue. The system I'm looking at at the moment has network-manager 1.10.6
To demonstrate whether this apparent cache-clearing is happening on a given system, one approach is to monitor the output of this command: while [ 1 ]; do nmcli device wifi list | wc -l; sleep 15; done
. When the symptom occurs described above, the output will be "2". If you do a new scan while the command is running, i.e. iw wlan0 scan
, the output will reflect that NetworkManage is now aware of other access points.
On the two machines I've tested the above with, I am consistently seeing 17x 15 second intervals before the cache is cleared, so that's a cache lifetime of ~255-280 seconds. Of note is this doesn't match the 120 s in the link from above (which I confirmed remains unchanged in the current github repo).
Solution 1:
Update/Note: I haven't dug into commit history, but it appears the scan interval changed back with 20.04's version of NetworkManager, to something a bit more reasonable, on the order of every 4 minutes (I might be misrecalling this number).
So this is a side effect of a intentional change made to NetworkManager.
Previously, NetworkManager would do periodic scans regardless of quality of wifi connection. This caused issues for common usecases, such as videoconferencing.
At the time of this writing, the logic has been tweaked so that the time between scans (on common WPA2 setups) is once-per-day, as long as the signal strength is good, in this case, > 70/100 (seemingly arbitrary units used by NM). If the signal strength is below this threshold, scans will occur every 30s until a better connection is established. This is Network Manager's hardcoded setting of the bgscan roam threshold belonging to the underlying wpa_supplicant. (Approximate link to current version of this code)
I didn't dig further, but evidently, nmcli device wifi list
is loading cached information about what wifi networks are available. It seems reasonable to me (now that I understand more of what's going on) that this cache is discarded when it reaches some staleness threshold, and thus no other APs/networks are listed.
So this question resulted from observation of a symptom of this change on a machine in a static environment. And for the vast majority of realworld usecases, it's harmless. Had I moved to an area served better by a different AP, my laptop would have roamed without my noticing, probably.
What about for a machine moving around continually, needing to jump from AP to AP quickly? It might work, but that depends. Ultimately, that's not the designed for use-case here, and the above logic is hardcoded, and not tweakable.