15

I need my machine to connect to a wireless network automatically every time it starts

I'm running a headless server (10.04) and I use following commands to manually connect to the network

sudo iwconfig wlan0 essid "SSID_Name"
sudo iwconfig wlan0 key XXXXX
sudo iwconfig wlan0 key open
sudo iwconfig wlan0 mode Managed
sudo dhclient wlan0

I will appreciate if we can do that by modifying etc/network/interfaces file

Please note that my router is running wep, thanks in advance

Braiam
  • 67,791
  • 32
  • 179
  • 269
loo3y35
  • 511
  • 4
  • 9
  • 19
  • I don't see the relevance. I can connect with no problem to the AP, I just wanna automate the process and your guide doesn't include that – loo3y35 Jan 28 '14 at 23:13
  • You are totally right. – Luis Alvarado Jan 28 '14 at 23:15
  • I have posted an answer, please test and let me know. – Luis Alvarado Jan 28 '14 at 23:31
  • Okay...this worked for me yesterday with dhcp but today I remembered that I was trying to accomplish this by running a script at login, so I removed the script and my machine doesn't work anymore; I can connect either the VGA or the WiFi module at one time, when I remove the Wi-Fi module the machine works fine and eth1 gets a valid IP – loo3y35 Jan 29 '14 at 09:33
  • On the GUI, you can: Bring-up NetworkManager -> (Click on) Edit Connections -> Select the current connection From the list of connections -> (Click) Edit -> (Click) General -> (Checkmark) Automatical connect to this network & All users may connect to this network (Copied from linuxquestions.org by L. James) – Tom Mar 08 '20 at 01:03
  • @Tom it’s a headless server. And it’s been 6 years. – loo3y35 Mar 08 '20 at 16:34
  • @loo3y35 Which is why that's a comment not an answer my guy – Tom Mar 08 '20 at 18:07

2 Answers2

14

Please amend your /etc/network/interfaces file to:

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet dhcp
wireless-ssid SSID_Name
wireless-key XXXXX

If you expect to ssh and ftp into the server, you need to know where it is. Do so with a static IP address:

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.1
wireless-ssid SSID_Name
wireless-key XXXXX
dns-nameservers 8.8.8.8 192.168.1.1

Moreover, your settings imply that your network is encrypted with WEP which is quite insecure. I recommend you change the router to WPA2-AES:

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.1
wpa-essid SSID_Name
wpa-psk XXXXX
dns-nameservers 8.8.8.8 192.168.1.1

Be sure to select an address outside the range used by the DHCP server in the router and, of course, substitute your details here.

chili555
  • 60,188
  • 2
    The procedure works but at every reboot after login I need to do this:

    sudo ifdown wlan0 && sudo ifup -v wlan0

    There is a way to do this automatically?

    – ad3luc Oct 02 '15 at 07:52
  • @ad3luc Were you able to solve this issue ? – user427969 Mar 23 '16 at 00:46
  • @user427969 nope...but I think that is a hardware compatibility. I have abandoned that laptop. Thanks anyway. – ad3luc Mar 23 '16 at 08:43
2

Automatic Wireless Connection when Login

For cases where you would like to login automatically to a wireless router here are the steps:

  1. Open the interface file:

    sudo nano /etc/network/interfaces
    
  2. Add the following information (Assuming your interface is called wlan0):

    auto wlan0
    iface wlan0 inet static
    address ASSIGNED_IP
    netmask 255.255.255.0
    gateway THE_GATEWAY
    wireless-essid YOURSSID
    wireless-key WIRELESSKEY_HERE
    
  3. Save the file and reboot computer.

Luis Alvarado
  • 211,503
  • My linux machine is RB110 (a single board computer) and I have only one pci interface (both wifi and VGA are pci) so, I can't connect them simultaneously and therefore I can't see the error message but I'm pretty sure the machine is not even getting an address on eth1; I use SSH to access the machine – loo3y35 Jan 29 '14 at 15:07
  • 1
    If I configured the automatic wifi as you guided me and the module was connected I can't access the machine via SSH. However, if the module wasn't connected I can SSH and I get wlan0 not found errors and if I removed the configuration I can SSH without any problem even if the VGA module wasn't connected – loo3y35 Jan 29 '14 at 17:55
  • I would recommend first updating to a newer version of Ubuntu (Just noticed the 10.04) since it includes a couple of updates that could fix the problem you are having and many more, specially in the whole ssh / networking / remote access scenario. Is it possible in your case to use a newer version? I ask since I am doing it right now here in 13.10 and it is working correctly. Of course not the same hardware but the ssh work after connecting to the wireless with the configuration mentioned above. – Luis Alvarado Jan 29 '14 at 21:51
  • Actually no, this is the most recent version I can run on my hardware; it's pretty old. In addition, the version I'm running is LTS and is still supported until April 2015 – loo3y35 Jan 29 '14 at 22:34
  • Can you provide a link to the website of the rb110. – Luis Alvarado Jan 29 '14 at 22:46
  • 1
    http://www.roboard.com/RB-110.htm and it has an i486 processor – loo3y35 Jan 29 '14 at 23:01