(I'm intentionally imprecise with the actual steps i've tried because there are hundreds of things - I know because I looked at the size of my BASH history)

CentOS 7, NetworkManager

(Please correct anything i'm wrong about below)

A customer has an environment with multiple APs having the same SSID. I have to write a BASH script that connects a linux box to each AP in turn, executes a command to gather data, then moves on to the next AP, wash, rinse, repeat. The BSSID is the obvious thing to use to connect. The script qua script is working beautifully, but the BSSID-based wifi connection bit is not.

I have tried iw, iwconfig, nmcli, and wpa_supplicant and cannot get it to reliably connect to the BSSID I specify - regardless of what I put in the command the actual BSSID connected to just seems to be random. From what I have gathered, all of these tools, aside from wpa_supplicant, just take the BSSID, associate it with an SSID, then use the SSID in the connection setup, which, if correct, seems kinda stupid (to be blunt).

wpa_supplicant is just too fragile to use this way - it always gets into a state where wpa_cli cannot connect and I have to continually restart it and often restart NetworkManager.

I thought about switching to Python, but the Python modules just seem to be wrappers to the linux commands, so nothing changes.

If anyone has any ideas please pass them along. I cannot believe that this is so difficult, so I must be missing something obvious...

I tried Eduardo's solution below.

I cannot implement this exactly as provided. I'm running the connection attempt in a loop in a shell script where the MAC address / BSSID is a variable (SSID and password/psk are static).

The command i'm using to connect is:

nmcli connection up ifname wlp4s0 ap $AP passwd-file passwdfile

where passwdfile contains the psk. This is in a loop through the list of $AP.

It still connects to a random AP from the list. (Probably the one that at that instant had the best signal), and more confusing (to me) is that iw event shows a different connected BSSID than

nmcli -f SSID,BSSID,ACTIVE dev wifi list | grep yes

There must be something really obvious i'm not doing correctly (this is still mostly new to me).

  • Is it absolutely necessary to connect through Wi-Fi instead of LAN using IP addresses? Mar 30 at 19:30
  • yes - the purpose is to gather some stats from the APs about the wifi connection to the test device, so it has to connect. And i think to use the IP via ethernet the target IPs would have to be configured ahead of time. I get the ssid/bssid automatically using a scan. The idea is to have a standard load for the test devices that requires little to no config before they are deployed - ship it to the customer, plug it in, and go.
    – msampson
    Mar 31 at 20:08

1 Answer 1


If you only provide the normal ascii password then wpa_supplicant needs to find out the SSID, because the 64 hex digits PSK (kind of the actual password) is derived from it. At this moment it goes into SSID mode.

So the solution is to specify just the BSSID and the 64 hex digits PSK password.

You can get the 64 hex digits PSK by running:

wpa_passphrase YourSSID YourAsciiPassword

For example:

$ wpa_passphrase Example myexample

Then you use BSSID instead of SSID and end up with something like this:


That should connect you just to that BSSID.

  • great - i will give that a try and see what happens.
    – msampson
    Mar 31 at 20:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .