How do I choose which router to connect to with the same SSID?

5,187

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
Share:
5,187

Related videos on Youtube

Akshat Mittal
Author by

Akshat Mittal

TL;DR I make things. I am primarily a Web & App Developer by profession, but I blog when I feel like. I'm strongly passionate about how things work, and I love to code. Currently building Metacrypt & CreateMyToken.

Updated on September 18, 2022

Comments

  • Akshat Mittal
    Akshat Mittal over 1 year

    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.

    • tvdo
      tvdo about 10 years
      You're looking to connect to a specific BSSID. We have an existing question for Windows ( superuser.com/questions/485517/…), so you can either make this Linux-only or have it closed as a duplicate.
    • tvdo
      tvdo about 10 years
      Also, IIRC Kubuntu's wireless utility lets you specify a BSSID.
    • Akshat Mittal
      Akshat Mittal about 10 years
      @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
    Akshat Mittal about 10 years
    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?
  • MariusMatutiae
    MariusMatutiae about 10 years
    @AkshatMittal No, it is actually easier. Pls see my edit
  • Akshat Mittal
    Akshat Mittal about 10 years
    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.
  • MariusMatutiae
    MariusMatutiae about 10 years
    @AkshatMittal Could you be more specific?
  • Akshat Mittal
    Akshat Mittal almost 10 years
    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.
  • L. D. James
    L. D. James over 6 years
    @MariusMatutiae I get the same error in the same step as Akshat Mittal. Is there some way to identify what is causing this error?