Score:2

How does NetworkManager choose which WiFi network to connect to when muliple are available?

in flag

When NetworkManager is controlling the WiFi connection on a system, how does it choose which network to connect to?

I'm aware of the connection.autoconnect-priority setting, but I'm interested in understanding the algorithm used to choose a connection when multiple autoconnect networks sharing priority=0 are available.

waltinator avatar
it flag
By use of "packet routing", see `ip route`, read `man ip ip-route`.
in flag
Thanks for the comment, but I'm actually referring to the process by which NetworkManager chooses which SSID/BSSID to associate with, not how Linux routes packets over multiple connected networks.
Score:4
us flag

NetworkManager doesn't do this at all; instead, wpa_supplicant does. NetworkManager simply tries to keep every active connection online, and then it delegates the work to other utilities based on the type of connection involved. For wireless and certain wired 802.1x connections, that's the job of wpa_supplicant .

So, how does wpa_supplicant do it? Each network interface that could be connected looks for connections in each of the following criteria until there is only one network to connect to:

  • Scan for potential networks
  • Rank the scanned networks by priority and connect to the highest-priority network
  • Rank the prioritized networks by connection strength and connect to the strongest one
  • Rank the networks by order in the configuration file and connect to the first one

so if all else fails, the configuration file is the authoritative order. You can read the source code.

in flag
Thanks! Based off of your answer, I was able to find the source code that actually does the prioritization. https://github.com/digsrc/wpa_supplicant/blob/515eb37dd1df3f4a05fc2a31c265db6358301988/wpa_supplicant/scan.c#L1658
in flag
Based off of that, it seems to be priority > config order > prefer WAP2 > prefer privacy > Prefer better signal level > prefer max rate > prefer signal band.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.