Ubuntu – Need to restart network interfaces and kill wpa_supplicant, how to fix

networkingwpa-supplicant

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?

Best Answer

  • 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
    
  • Related Question