Tuesday, February 9, 2010

Start your wireless connection before Ubuntu login

Recently I started asking myself how I could get Ubuntu to forge its wireless connection (with WEP encryption) to my router without having to log-in through the GUI. I noticed that the default way of logging in through the GUI and then having a wireless connection available was limiting for two reasons: (1) If I wanted to be able to connect to my openSSH server then I needed to be logged in, and (2) If there was something wrong with the GUI and I had to log-in through the command line then I wouldn't have internet access.

So I started looking around on the net. Most pages that I found showed messageboard threads suggesting modifications to the /etc/network/interfaces file. This is the file that is supposed to tell your Linux system what to do with your network interfaces at boot-up. I tried to modify it so that my wireless card would start-up with a static IP at boot-up, but no matter how I changed this file, nothing worked.

Finally, I decided to ask a question on ubuntuforums. I found out that Gnome Network Manager, the program in Ubuntu which manages all your wired and wireless network connections, works terribly with the settings in the /etc/network/interfaces file. In other words, if you want Ubuntu to start your wireless connection at bootup instead of after login, you have to get rid of Gnome Network Manager!

So, on the advice of chili555 from ubuntuforums, I got rid of Gnome Network Manager by typing in sudo apt-get remove --purge network-manager and modified my /etc/network/interfaces file to look like the following (SSID and WEP key changed for privacy):

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
address 192.168.2.11
netmask 255.255.255.0
gateway 192.168.2.1
wireless-essid MYSSID
wireless-key 12345678912345678912345678

iface eth0 inet dhcp


Now, every time I start my computer, my wireless connection is available before login so that I can login to my openSSH server or go to the command-line without logging in to the GUI!

21 comments:

  1. Thank you I had been going crazy looking for a fix for the same issue. I even tried changing that interfaces file as well.

    ReplyDelete
  2. I don't know if this will be a problem, but I've read that UbuntuOne requires that Network Manager be running.

    ReplyDelete
  3. I had the same problem, but I don't think it's a bug.
    For me what worked was simply to edit my connection in the Network Manager and check the box "Available to all users" (I also have "Connect Automatically" checked).
    Now it connects as soon as it boots up, before the first login.

    ReplyDelete
  4. I had tried to use the "Available to all users" checkbox, but every time I clicked on it my connection got messed up. That's why I went through the process I described in this post and installed WICD. They just work better :)

    ReplyDelete
  5. It's a good solution, however it does have a minor security issue to consider. The challenge with the /etc/network/interfaces file is that your WEP key is stored plain text in that file. The gnome network manager stores the key in it's keychain, which makes the key a whole lot more secure...

    JT

    ReplyDelete
  6. Hello, I do not agree with the previous commentator - not so simple

    ReplyDelete
  7. my wireless connection works most of the time but soon as i loose signal i just type in the code and it works again, maybe you need to change your box.

    ReplyDelete
  8. Then, how to detect SSID and auto connect to it, instead of hard code the SSID in the configuration?

    ReplyDelete
  9. thanks men this is what i looking for

    ReplyDelete
    Replies
    1. This is exactly what I was looking for. Great job for posting this. Other Google searches had more complicated instructions, that did not really provide a good solution to this problem. Thanks a lot!!

      Delete
    2. During reboot/restart of your system, you can create a script (.sh shell script file) that is run during reboot, that will send an email and send a message to your cell phone.
      Copy the script file to /etc/init.d/ to make it part of the boot-up sequence.

      This is how you do this:
      Reference- http://ubuntu.wordpress.com/2005/09/07/adding-a-startup-script-to-be-run-at-bootup/

      So you have a script of your own that you want to run at bootup, each time you boot up. This will tell you how to do that.

      Write a script. put it in the /etc/init.d/ directory > sudo cp reboot-send-email.sh /etc/init.d/
      Lets say you called it reboot-send-email.sh. You then run

      sudo update-rc.d reboot-send-email.sh defaults

      You also have to make the file you created, reboot-send-email.sh, executable, using
      sudo chmod +x /etc/init.d/reboot-send-email.sh

      ----------------------------------
      #
      ## send to cell phone that system was rebooted
      #
      # sendEmail -f laptop_reboot`date +%Y%b%a%d_%H%M`@gmail.com -t @ -u " laptop Restart" -m " Started on > "`date +%Y%b%a%d_%H%M` -s smtpauth..net -xu -xp

      #
      ## send email that system was rebooted
      #
      # sendEmail -f laptop_reboot`date +%Y%b%a%d_%H%M`@gmail.com -t -u " laptop Restart" -m " Started on > "`date +%Y%b%a%d_%H%M` -s smtpauth..net -xu -xp

      ----------------------------------

      Delete
  10. Natty seems to connect before login by default. I don't want it to. It adds approx 15 seconds to my boot time.

    ReplyDelete
  11. It works beautifully but my next problem is: since there is no network-manager under gnome, when my netbook comes back from sleep there is no way to re-connect. Logout-then-re-login does not work either. I have to restart the netbook. I must be doing something wrong.

    ReplyDelete
  12. I had the same issue until I checked on "Available to all users" option which works fine for me.

    ReplyDelete
  13. Hey i think of your blog is pretty - i found it pleasant in google and I put on my list of favorites would like to see more posts from u soon.

    ReplyDelete
  14. This seems exactly what i was looking for to fix a samba share issue on shutdown. With the network-manager the network is stopped before the umount of shared drives.

    ReplyDelete
  15. Really helpful, thanks. On Precise Pangolin server, with a wifi only connection, wanted SSH to be the only route in (it's headless) and to connect prior to login. I am using wpa, and my /etc/network/interfaces is;

    auto wlan0
    iface wlan0 inet dhcp
    address 192.168.10.9
    newmask 255.255.255.0
    gateway 192.168.10.1
    wpa-ssid [hidden ssd]
    wpa-psk [password]

    I then commented out eth0 as it isn't connected, and server was waiting a minute for eth0 to connect, and boot is back to almost instant (SSHD), and connection is immediate. One thing which may help the odd person - my SSD is multi word with gaps - enclose the SSD (or password) in quotes to get it recognised.

    ReplyDelete
  16. Directory of sizegenetics therapists that provide Sensual sizegenetics, erotic sizegenetics and Tantra sizegenetics in New York, Los Angeles, Chicago, San Francisco, San diego, Washington D.C, Boston, Philadelphia, Miami, Miami Beach, Atlanta. If having an erotic gay sizegenetics is something you wish to own, there will be just a few things it's best to look for inside the sizegenetics therapist. Going through the way to know the qualities in the chosen gay sizegenetics professional will always possess a satisfactory experience from your own sizegenetics therapist.
    http://buysizegeneticsonline.tumblr.com/

    ReplyDelete
  17. exciting along with exquisite enthusiasts web log insomnia

    ReplyDelete
  18. a better way would be allowing the connection for all users through network manager ;)

    ReplyDelete
  19. Really inspirational to hear someone pursuing their dreams and becoming successful instead of following the traditional path. I have read your article about This topic. I think it's good and impressed to know your service. Thanks for share this Information.
    Lenovo Storage V3700 V2 SFF Control

    ReplyDelete