Need to restart network interfaces and kill wpa_supplicant, how to fix?

34,195

I had the same problem. It turns out that Network manager is a little overzealous in switching between access points (AP's) when more than one are present. You have two options

  1. Use iwlist to find out how many AP's are there:

    root@debian:/home/nofrills# iwlist wlan0 scan
    
    Scan completed :
      Cell 01 - Address: 00:1E:58:A1:41:87
                ESSID:"iiserk_wireless"
                Mode:Managed
                Frequency:2.462 GHz (Channel 11)
                Quality:4/5  Signal level:-64 dBm  Noise level:-92 dBm
                IE: IEEE 802.11i/WPA2 Version 1
                    Group Cipher : TKIP
                    Pairwise Ciphers (2) : TKIP CCMP
                    Authentication Suites (1) : 802.1x
                   Preauthentication Supported
                Encryption key:on
                Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                          12 Mb/s; 24 Mb/s; 36 Mb/s; 9 Mb/s; 18 Mb/s
                          48 Mb/s; 54 Mb/s
    
      Cell 02 - Address: 00:1E:58:A1:54:7B
                ESSID:"iiserk_wireless"
                #More such details
    

    Then note the Address of the cell with the highest Quality. That is the AP nearest to you. Then click on Network manager applet, select "Edit Connections" and go to the wifi network listed. There will be a text box titled "BSSID". Paste the Cell address there.

  2. Otherwise, you can ditch network manager altogether and use wpa_supplicant (Network manager uses it under the hood anyway). Just create a configuration file and edit your /etc/network/interfaces this way:

    auto lo
    iface lo inet loopback
    
    auto wlan0
    iface wlan0 inet dhcp
        pre-up wpa_supplicant -B -Dwext -i wlan0 -c/etc/wpa_supplicant.conf
        post-down killall -q wpa_supplicant 
    

Option 1 is not very useful unless you spend most of your time at workplace in roughly the same location. Option 2 is what I am using now, and it works pretty well. But wifi does not get automatically reconnected after suspend/resume, so you need to run /etc/init.d/networking/restart manually.

If you like doing things neatly, as an alternative to the generic killall command, you can use the WPA specific tool wpa_client:

wpa_cli -i wlan0 terminate
Share:
34,195

Related videos on Youtube

Wenlin.Wu
Author by

Wenlin.Wu

I develop audio and music software. I started Teragon Audio, and have produced a number of AU/VST plugins, hosts, and other stuff. I am not seeking employment; please do not contact me with job offers, project proposals, and the like.

Updated on September 18, 2022

Comments

  • Wenlin.Wu
    Wenlin.Wu over 1 year

    My workplace uses 802.11x authentication for their WiFi network, and several times per day I get booted from the network and need to do the following:

    1. Disable networking
    2. sudo kill -9
    3. Restart networking

    At this point, the machine will connect to the network just fine. I don't see any weirdness in the syslog, and am running Ubuntu 12.04 (64-bit). What could be wrong?

  • Wenlin.Wu
    Wenlin.Wu over 11 years
    Very helpful answer! Unfortunately I think your configuration of /etc/network/interfaces in your 2nd point wasn't pasted in. Can you please re-add it?
  • nofrills
    nofrills over 11 years
    Oops! My bad. Added it.
  • Oleg Gryb
    Oleg Gryb over 6 years
    You probably mean "/etc/init.d/networking restart". Oddly enough it hangs at "reconfiguring network interfaces" forever. What could be the problem?