Ubuntu – How to connect to a specific BSSID

nmcliwireless

There are multiple wireless networks available with same SSID.
I am looking for a solution to connect to a specific one (by BSSID).

nmcli con up ifname ap seems good, but, unfortunately, it's not working. It just connects back to the original network.

Best Answer

You can use Network Manager's cli interface, nmcli.

I'm sure you already have the BSSID. You can check and verify it with:
(the $ is the command prompt. The lines following the command is the output.)

$ nmcli -f in-use,ssid,bssid,signal,bars  dev wifi
*  SSID               BSSID              SIGNAL  BARS 
*  Apollo III (TWC)   XX:XX:XX:XX:XX:XX  98      ▂▄▆█ 
   Chromecast8481     XX:XX:XX:XX:XX:XX  97      ▂▄▆█ 
   --                 XX:XX:XX:XX:XX:XX  94      ▂▄▆█ 
   Apollo III (1)     XX:XX:XX:XX:XX:XX  87      ▂▄▆█ 
   TWCWiFi            XX:XX:XX:XX:XX:XX  80      ▂▄▆_ 
   CableWiFi          XX:XX:XX:XX:XX:XX  80      ▂▄▆_ 
   TWCWiFi-Passpoint  XX:XX:XX:XX:XX:XX  80      ▂▄▆_ 
   Apollo III (1)     XX:XX:XX:XX:XX:XX  70      ▂▄▆_

The cli for the connection to the BSSID is:

$ nmcli d wifi connect XX:XX:XX:XX:XX:XX

That command will give you a GUI prompt for the password. You could enter the password on the commanline (may be a security concern):

$ nmcli d wifi connect XX:XX:XX:XX:XX:XX password "mypassword"

The latter won't prompt for a password but will connect to the specified network by the BSSID in the command. If you were already previously connected to a different network, it will be replaced with the one specified in the command.

The command will also add the connection info to the /etc/NetworkManager/system-connections location. The location is protected.

Subsequent connections can be made via the network icon in the notification area by the name created.

Related Question