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

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.


Solution 1:

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.