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.)The cli for the connection to the
BSSID
is:That command will give you a GUI prompt for the password. You could enter the password on the commanline (may be a security concern):
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.
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