How can I connect to a specific BSSID?
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.
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: SSID: MySSID_NAME
(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).
EDIT
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.
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.
This is more of an expansion off TheOdd's answer. Since iwconfig is depricated in many distros, iw can be used to associate with a specific access point instead. iw works slightly differently than iwconfig in that you specify specific access points by frequency rather than BSSID. Also, I found it necessary to release the DHCP lease before requesting another one from a different access point. Assuming you're already connected to an access point on the same network, you don't need to re-submit authentication with wpa_supplicant. I'm using wlan0, but your WNIC might have a different name. Here's the complete process of switching between access points with the same ESSID:
show connection info:
iw wlan0 link
take the wlan0 down:
sudo ip link set wlan0 down
free WNIC of any previous IP addresses:
sudo ip addr flush dev wlan0
remove old dhcp lease:
sudo dhclient -r wlan0
bring WNIC back up:
sudo ip link set wlan0 up
scan, take note of freq:
sudo iw dev wlan0 scan
specify ESSID and frequency with iw (not iwconfig) to assoate with specific acces point:
sudo iw wlan0 connect <ESSID> <freq>
for example:
sudo iw wlan connect fly-for-wifi 2462
run dhcp:
sudo dhclient -v wlan0
check:
iw wlan0 link