8 comments to A More Elegant Solution to Ubuntu Wi-Fi Reconnecting Issue

  • […] In: Linux 5 Nov 2010 I have an updated fix for this issue using a startup script to connect and a time scheduled script for checking the connection, rather than having one constantly running in the background, avalible here – http://alexsleat.co.uk/2011/01/09/a-more-elegant-solution-to-ubuntu-wi-fi-reconnecting-issue/ […]

  • Hi There:

    In some cases (like me) the wifi appears still connected… so i change the script a little, hope helps!

    #!/bin/bash
    if ping -c 2 192.168.2.254 | grep -o “Destination Host Unreachable”
    then
    ifconfig wlan0 down
    sleep 5
    iwconfig wlan0 essid NAMEHERE
    iwconfig wlan0 key KEYHERE
    ifconfig wlan0 up
    fi

  • Good call, I’m going to assume that the 192.168.2.254 is your routers address? Which others using this would have to change?

  • endcee

    After a few weeks of preparing to throw my laptop from the top of my building, I believe your scripts have saved it’s fate. Thank you! This disconnect with no reconnect issue was driving me nuts. thank you for the simple fix, albeit a workaround to a problem inherent in the system itself.

  • If you use the ifup/ifdown scripts and you configured your /etc/network/interfaces correctly there is no need to use the ssid, just the interface. I also modified it slightly to lookup the default gw automatically, and ping that, so if your mobile it will use whichever is the active default gateway.

  • If you use the ifup/ifdown scripts and you configured your /etc/network/interfaces correctly there is no need to use the ssid, just the interface. I also modified it slightly to lookup the default gw automatically, and ping that, so if your mobile it will use whichever is the active default gateway.

    #!/bin/bash
    GW=`/sbin/ip route list | grep default | awk ‘{print $3}’`
    if ping -c 2 $GW | grep -o Unreachable; then
    echo down;
    echo `date`”: reconnected to wlan” >> /var/log/wlan0-detail
    ifdown wlan0
    sleep 5
    ifup wlan0
    fi

  • Roberto

    this is exactly what I was looking for. after doing the mentioned steps I rebooted, it doesn’t connect to my wireless network. I tried the 1st command
    iwconfig wlan0 essid NETWORKNAME in terminal and I get:
    set failed on device wlan0 operation not permitted
    then I checked: iwconfig wlan0 and I got: no such device.
    any ideas what am I doing wrong?

    thank you.

  • You need to replace wlan0 with whatever your device is named. Use the command ‘ifconfig’ to return a list of network devices and replace every instance of it in the script and instructions to the device you wish to connect.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>