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.


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.

| improve this answer | |
  • uh... why do i have to provide a password? i am trying it on the BSSID I am already connected to, and it still asks for a password. can't i tell it to use the saved password it already has somewhere? – Michael Jul 16 at 21:09
  • Why in the world is nmcli showing ONLY 2.4Ghz connections? nmcli -f in-use,ssid,device,chan,freq,bssid,signal,bars dev wifi. The whole reason I'm on this page is to try to force my computer to connect to my mesh network on 5Ghz instead! – Gabriel Staples Sep 1 at 7:13

This answer was first posted by MariusMatutiae on SuperUser. Please consider voting there if this helps you.

You can do it by connecting to the AP manually.

First, it is easiest to turn off network manager, if you are running one:

  sudo service network-manager stop

Then you need to identify the BSSID of the AP you wish to join: the command

 sudo iw dev wlan0 scan

(if you are using wlan0 as your wireless interface) will produce a lot of output, among which you will find something like:

  BSS f8:1a:67:aa:7f:b9 (on wlan0) -- associated
    TSF: 629432841083 usec (7d, 06:50:32)
    freq: 2417
    beacon interval: 100
    capability: ESS Privacy ShortPreamble SpectrumMgmt ShortSlotTime (0x0531)
    signal: -70.00 dBm
    last seen: 0 ms ago
    Information elements from Probe Response frame:

(the output is longer than this). The relevant part is of course BSS f8:1a:67:aa:7f:b9.

Next, you will have to free your interface of any previous IP addresses, just in case:

  sudo ip link set wlan0 down
  sudo ip addr flush dev wlan0
  sudo ip link set wlan0 up

Now you specify you want to connect to the specific AP:

  sudo iwconfig wlan0 essid MySSID_NAME ap f8:1a:67:aa:7f:b9

where of course ap precedes the BSSID you just identified. Now you need to start wpa_supplicant,

 sudo wpa_supplicant -Dnl80211 -i wlan0 -B -c FILE_with_WPA_Secrets

(if you do not know how to set up the file with your WPA credentials, you may look it up here for instance; just be careful, where it says network= {, it should be network={ without a space). Lastly,

 sudo dhclient -v wlan0

(the -v flag does not work on all Linux distros, I like it because I can monitor what is happening).


The instructions above work for a network with WPA security. Fore WEP security, replace the wpa_supplicant command with:

  sudo iwconfig wlan0 key s:Your_WEP_password

Remember that the two characters s: before your password are necessary. After this, once again

  sudo dhclient -v wlan0

Hope this helps.

| improve this answer | |

The easy way to do this is to use the GUI provided by Network Manager.

Go to the network icon in the top panel, choose Edit Connections, locate the wireless connection profile for the desired SSID, open for EDIT, and go to the BSSID field and either 1)pop up the desired BSSID, or 2)manually enter the desired BSSID.

See below for an example wireless connection showing its BSSID field.

enter image description here

| improve this answer | |
  • @Michael Please start a new question with your details. Thanks! – heynnema Jul 16 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.