3

In my area, there is a big network of around 50 routers with same SSID. My devices automatically connect to the closest and strongest network.

How can I connect to one of those manually which are in the range?

Example:

| Router || Network SSID || Strength |
--------------------------------------
| One    || RandomName   || 85%      |
| Two    || RandomName   || 75%      |
| Three  || RandomName   || 65%      |
| Four   || RandomName   || 60%      |
--------------------------------------

My device automatically connect to Router One because it has the maximum strength. How can I connect to Router Two or Router Three (or Four)?

I need a solution for Linux.

Akshat Mittal
  • 2,255
  • 3
  • 24
  • 44
  • You're looking to connect to a specific BSSID. We have an existing question for Windows ( http://superuser.com/questions/485517/how-can-i-connect-to-an-access-point-by-bssid-instead-of-essid-in-windows-7), so you can either make this Linux-only or have it closed as a duplicate. – Bob May 01 '14 at 10:30
  • Also, IIRC Kubuntu's wireless utility lets you specify a BSSID. – Bob May 01 '14 at 10:31
  • @Bob, I made the question Linux only, but I don't think that specific question has a good solution already. How can I get the Kubuntu's wireless utility on Ubuntu? – Akshat Mittal May 01 '14 at 10:37

1 Answers1

5

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
MariusMatutiae
  • 46,990
  • 12
  • 80
  • 129
  • This is interesting. I'll try it for sure, but one thing I notice is it says `WPA credentials`, the network I am talking about is on WEP, it will still be the same? – Akshat Mittal May 01 '14 at 11:45
  • @AkshatMittal No, it is actually easier. Pls see my edit – MariusMatutiae May 01 '14 at 13:09
  • Seems like it ain't working for me, I tried on multiple systems. I always have some sort of error in any one of the steps. – Akshat Mittal May 04 '14 at 14:01
  • @AkshatMittal Could you be more specific? – MariusMatutiae May 05 '14 at 05:23
  • 1
    1. `sudo iwconfig wlan0 essid MySSID_NAME ap f8:1a:67:aa:7f:b9` says "SET failed on device wlan0 ; Operation already in progress." but it ain't. I am disconnected. 2. `sudo iwconfig wlan0 key s:Your_WEP_password` says "Error for wireless request "Set Encode" (8B2A) : SET failed on device wlan0 ; Invalid argument.". Don't know why. I am disconnected from the network and I have changed ESSID, BSSID, Password at appropriate places. – Akshat Mittal May 18 '14 at 14:01
  • @MariusMatutiae I get the same error in the same step as Akshat Mittal. Is there some way to identify what is causing this error? – L. D. James Nov 26 '17 at 18:38