Sunday, December 8, 2013

Setting up Wifi via the Command Line – Linux/Raspberry Pi (WPA2)

image

The Raspberry Pi has many great features straight out of the box,  unfortunately WiFi is not one of them, in this guide I’ll show you how I WiFi equipped my Raspberry PI for only a fiver.
We will be assuming that you have a head less setup (without a monitor) so the guide should work for everyone, either via SSH (remote) or via a local terminal session if you do have a monitor.
Also its worth noting that some WiFi adapters will require a powered USB hub between the Raspberry PI and the USB module, the one used below doesn’t due to it’s power consumption assuming you don’t have anything else drawing large currents from the USB power.

1. What you will need…

  • Raspberry Pi, with Wheezy
  • Internet Connection (via the ethernet port to begin with)
  • WiFi network to test on image
  • USB WiFi Dongle, either of the below work:
  • Amazon Link (USA Amazon)
  • Amazon Link or Amazon Link (UK Amazon)


2. Update the OS

There are so many times you will run into a bug when installing something new and find out that it would have worked if your system was up to date, taking no risks here so get your system updated

sudo apt-get update
sudo apt-get upgrade

Due to the RAM/CPU power on the Pi’s, this might take a while, brew anyone? 
  
 
3. Reboot

Power down the device, install your WiFi USB module and turn it back on.


4. Setup the interface configuration

sudo nano /etc/network/interfaces

Normally your base configuration will look something like this?

  allow-hotplug wlan0
 
  iface wlan0 inet manual
  wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

  iface default inet dhcp

Assuming you have a DHCP server on your LAN (normally your DSL/Cable router) use the following configuration, your SSID and password will be put in the wpa_supplicant.conf later on in this guide.

## FILE: /etc/network/interfaces ##
  allow-hotplug wlan0
 
  iface wlan0 inet manual
  wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

  iface wlan0 inet dhcp

If you don’t have a DHCP server, or if you want to just statically assign the IP address you can use the following, however update the IP, Netmask and Gateway to match your network.

## FILE: /etc/network/interfaces ##
  allow-hotplug wlan0
 
  iface wlan0 inet manual                           
  wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
   
  iface wlan0 inet static
  network 192.168.1.0
  address 192.168.1.249
  netmask 255.255.255.0
  gateway 192.168.1.254
  broadcast 192.168.1.255
 

5. Setup the WPA configuration

Finally you will want to edit the WPA configuration as below, don’t forget to update it for your SSID and WPA password!

## FILE: /etc/wpa_supplicant/wpa_supplicant.conf ##
  network={
  ssid="SSID-GOES-HERE"
  proto=RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP TKIP
  group=CCMP TKIP
  psk="WIFI-PASSWORD-GOES-HERE"
  }

6. Final Reboot

Ok that should be it, do a final reboot remove the wired ethernet cable and your IP should automatically come onto the network as a normal WiFi device.

OR do the the following if you don’t want to reboot:

sudo ifdown wlan0
sudo ifup wlan0
   

Problems?

First

This device should work out of the box, if for any reason it doesn’t you will want to do the following:

sudo wget http://dl.dropbox.com/u/80256631/install-rtl8188cus-latest.sh -O /boot/install-rtl8188cus-latest.sh

sudo /boot/install-rtl8188cus-latest.sh

Now go back to step 3 and try again.


Second

Run the below command, you should see your WiFi device there? If not there could be an issue with the hardware, try it in another PC…

lsusb

You should see a line that looks like this:

Bus 001 Device 005: ID 0bda:8189 Realtek Semiconductor Corp. RTL8187B Wireless 802.11g Network adapter.

Based On: http://pingbin.com/2012/12/setup-wifi-raspberry-pi/

 

About WPA2 (aka IEEE 802.11i-2004) & WPA SUPLICANT

Short for Wi-Fi Protected Access 2, the follow on security method to WPA for wireless networks that provides stronger data protection and network access control.

It provides enterprise and consumer Wi-Fi users with a high level of assurance that only authorized users can access their wireless networks.

Based on the IEEE 802.11i standard, WPA2 provides government grade security by implementing the National Institute of Standards and Technology (NIST) FIPS 140-2 compliant AES encryption algorithm and 802.1x-based authentication.  [Adapted from Wi-Fi.org]

There are two versions of WPA2:

  • WPA2-Personal (password)
  • WPA2-Enterprise (server authentication)

WPA2-Personal protects unauthorized network access by utilizing a set-up password. WPA2-Enterprise verifies network users through a server. WPA2 is backward compatible with WPA.

LINKS