Setup wifi adapter in linux

This little guide should help with configuring a USB WiFi adapter in Linux – this was in Ubuntu 12.04 but should work for later releases and other Debian based Unix versions. I recently configured my Raspberry Pi to use a wiki dongle but this guide didn’t work for some reason. This guide still works though and is much preferable since it is entirely done on the command line. The Raspberry Pi guide (which I’ll add at a later date) makes use of some GUI elements so not great for a headless server use case.I use the Edimax EW7811-UN which is very cheap and complies with normal the 802.11b/g/n IEEE standards. The device has a Realtek RTL8188CUS based chipset which has support for Windows, Mac & Linux. It also works great in the Raspberry Pi.
When the device is inserted to a USB port on the machine, the rtl8192cu module should be loaded automatically.

Load wifi module driver
First, check if the driver is automatically loaded on your machine with

lsmod | grep 8192.

If the result shows that the “8192cu” driver module is loaded, you have nothing left to do to load the module. If the result is nil, continue.
If it shows some other “…8192…” driver, uninstall it with rmmod -r .
Find the latest linux driver download address from Edimax:
Go to the Edimax website
-> Downloads
-> Communications Network ICs
-> Wireless LAN ICs
-> WLAN NIC
-> IEEE 802.11b/g/n Single Chip
-> Software
-> “Software: Drivers and Utilities”
-> “Step 1. Select one or more models”: check the box by RTL8192CU) and use in the correct line below:

mkdir -p /home/USERNAME/wifidriver
cd -p /home/USERNAME/wifidriver
wget ftp://WebUser:wK9xBuD5@58.211.24.153/cn/wlan/RTL8192xC_USB_linux_v3.4.4_4749.20121105.zip
unzip RTL8192xC_USB_linux_v3.4.4_4749.20121105.zip
bash install.sh

Insert the Edimax device into a USB port and check to see if the module has been loaded correctly automatically:

lsmod | grep 8192cu 

If nothing is returned, the module can be loaded manually:

modprobe 8192cu

Configure wifi connection

Install dependencies and kill network management utilities for configuration:

apt-get -y install wpa_supplicant psmisc
sudo stop network-manager
sudo killall wpa_supplicant
sudo killall nm-applet

Perform the SSID & password config

wpa_passphrase "YOUR_ESSID" | sudo tee /etc/wpa_supplicant.conf

-> then type your password

wpa_supplicant –d wext -B -c /etc/wpa_supplicant.conf -i wlan0

If you get your IP address automatically assigned by your router (most users) by DHCP just use the following (Note that you may have configured your router to assign a static IP to your server but from your server’s perspective this is still an auto assignation from your router so do this):

dhclient wlan0

If you want to configure a static IP then use:

ifconfig wlan0 192.168.1.12

You should now be able to ping your router by IP:

ping 192.168.0.2

Now add the default gateway using the IP address of your router:

route add default gw 192.168.0.2

You should be able to ping the net at large now (Google’s IP = 8.8.8.8):

ping 8.8.8.8

Add DNS. This one is Google’s free DNS service which is pretty fast and reliable so a great choice – however there are privacy implications which we’ll not get into here). You could also use your ISP DNS servers which you should have been given when you joined them or which will be the ones defined in your ISP provided modem/router.

echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

You should be done now, test by pinging Google:

ping google.com

Make persistent through a reboot

This will not last through a reboot, to make this persistent we need to make a little script:

mkdir –p /usr/bin/wifi_connect
nano /usr/bin/wifi_connect/scripts/wifi_connect.sh

Add this:

#!/bin/bash
wpa_supplicant -d wext -B -c /etc/wpa_supplicant.conf -i wlan0
dhclient wlan0
route add default gw 192.168.0.2
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
chmod 755 /usr/bin/wifi_connect/wifi_connect.sh

You should now add to crontab or rc.local to run at startup. Crontab is a task scheduling tool in linux, whereas rc.local is a script which runs at boot so you can add things to it to make them run at startup.
The easiest way I found to add to crontab is through Webmin (see this post for Webmin installation guide).

To manually add to crontab you can do this:

sudo echo '@reboot /usr/bin /wifi_connect/wifi_connect.sh xbindkeys' >> /etc/crontab

Or to add to rc.local:

cp /etc/init.d/rc.local /etc/init.d/rc.local.old
nano /etc/init.d/rc.local

Add this above ‘exit 0’:

sh /usr/bin/wifi_connect/wifi_connect.sh

Useful sources
http://www.cianmcgovern.com/getting-the-edimax-ew-7811un-working-on-linux/
http://askubuntu.com/questions/8568/can-ubuntu-server-connect-to-a-wpa2-encrypted-wireless-network/73025#73025

1 Comment

Leave a Reply

(email optional)


Warning: Undefined array key "rerror" in /home/public/blog/wp-content/plugins/wp-recaptcha/recaptcha.php on line 291