Linux: Connect wireless during boot-up
Posted by dilationtime on June 7, 2008
Please read entire post before modifying your system.
Notice: Use this information at your own risk, make sure you have current backups and know how to restore them. This cannot be overstated.
You should disable Network-Manager before starting. You can always fall back to using it if desired. Right click the network-manager icon and untick “enable networking” to disable your connection to the net. Re-tick it to reconnect.
In order to bypass the Network Manager in Ubuntu, and most other Linux flavors, and have your wireless connection configured and brought up during boot you need to configure the /etc/network/interface file.
The settings you use depend in part on the make and model of your wireless adapter and the settings for your LAN. This example presumes an Intel 3945ABG card. For other cards you may need to change the driver from ‘wext’ to whatever is appropriate for you. More info can be found in this thread on the ubuntuforums.
If it’s not already on your system you will need to install wpa_supplicant. Add it by doing:
sudo apt-get install wpasupplicant
You should also make a backup copy of your interfaces file.
To do that issue this command:
sudo cp /etc/network/interfaces /etc/network/interfaces.$(date +%y%m%d-%H%M%S)
this will give you with a copy of your interface file with the current date & time appended.
If, for whatever reason, you need to revert to your original file, just copy the backup file you created onto the current one. For example:
cd /etc/network
cp interfaces.080607-152706 interfaces
…except your date & time stamp will be different so adjust accordingly.
Next you need to know the name of your wireless adapter so do:
ifconfig -a
to find it. You will need to change the wlan0 references in the following instructions to match your system.
Ok, using your favorite editor, load /etc/network/interfaces:
sudo vi /etc/network/interfaces
or
gksu gedit /etc/network/interfaces
and insert the following configuration snippet into the appropriate section for your wireless card, eschewing duplicate entries:
auto wlan0
#iface wlan0 inet dhcp
iface wlan0 inet static
address 192.168.0.14
netmask 255.255.255.0
gateway 192.168.0.1
broadcast 192.168.0.255
#wireless-mode managed
#wireless-essid default
wpa-driver wext
wpa-ssid w00t
wpa-ap-scan 1
wpa-proto WPA
wpa-pairwise CCMP
wpa-group CCMP
wpa-key-mgmt WPA-PSK
wpa-psk c30142b13dbb49f7571f67e540090377d725ad19f416d1842cd690f0becead82
This configuration uses a static IP address because it’s faster than waiting for a new lease via DHCP during boot. You may wish to use DHCP, if so change the entries at the top to something like this:
auto wlan0
iface wlan0 inet dhcp
#iface wlan0 inet static
#address 192.168.0.14
#netmask 255.255.255.0
#gateway 192.168.0.1
#broadcast 192.168.0.255
Now, you need to change the wpa-psk (pre-shared key) value, used in the example, to encrypt the connection. You can do this using the wpa_passphrase utility to generate a WPA-PSK from an ASCII password/phrase that’s suitable for use with wpa_supplicant.
To do this you must pass the SSID of your AP and the password/phrase used by your AP to encrypt connections to wpa_passphrase:
wpa_passphrase ´w00t´ ´passphrase_key´
where ‘w00t’ is the SSID and ‘passphrase_key’ is the WPA password/phrase. This command will give the following output:
network={
ssid="´w00t´"
#psk="´passphrase_key´"
psk=c30142b13dbb49f7571f67e540090377d725ad19f416d1842cd690f0becead82
}
Now insert the new psk value (after the wpa-psk directive in the interface file) and you should be set. See:
man wpa_passphrase
for more details.
Finally, make sure you set this file read/write for root only else others may be able to read your WPA-PSK password/phrase:
chmod 600 /etc/network/interfaces
Depending on the umask in use on your system you may want to check the permissions on the backup file(s) you created and do the same for them.
Now you can restart the network to effect the changes:
sudo /etc/init.d/networking restart
…and try pinging some host to see if it works:
ping google.com
If not try issuing the following commands, substututing your adapter name in place of wlan0:
sudo ifdown wlan0
sudo ifup wlan0
sudo /etc/init.d/networking restart
You should also make sure your /etc/resolv.conf file contains the IP’s of your nameservers.
Troubleshooting:
If your connection does not come up automagically after booting then you’ll need to place a hook to re-initialize the connection during boot. I think Ubuntu Gusty users need to so this, I’m not sure about Hardy or other distros. ymmv
Open a terminal and do:
sudo -s
…to give us a root shell. Feel free to do it anyway your comfortable with, as long as your issuing commands with root authority. Now that your root issue:
cd /etc/init.d/ && echo -e ‘#!/bin/sh \n/etc/init.d/networking restart’ >> test && chmod +x wireless-restart
…all on one line. This command will cd to /etc/init.d then create a shell script called wireless-restart with two lines:
#!/bin/sh
/etc/init.d/networking restart
The chmod command on the end will make the script executable. (Using the double ampersand && tells the shell to move to the next command if the first one was successful.)
All that’s left is to create a symbolic link to this script in /etc/rcS.d:
cd /etc/rcS.d/ && ln -s /etc/init.d/wireless-restart S42wireless-restart
This command cds into /etc/rcS.d and creates a soft link to the /etc/init.d/wireless-restart script. Feel free to change the filenames, they are more or less arbitrary anyway.
That’s it. Just reboot. Simple and straight forward. If you need help or clarification leave a comment and I’ll help point you in the right direction.







hhlem said
i cant explain it but it works !!!
dilationtime said
hhlem: Glad it worked for you.