Tuesday, August 12, 2008

Connect to WPA Connection via Terminal in Ubuntu

WPA Connection - WPA-PSK or WPA2-PSK

[interface] - You must replace this with your network interface(eth0, wlan0, wlan1) Example command : sudo ifconfig wlan0 down
Guide - What's My Network Interface in Ubuntu

For uses of Ra-based chipsets: rt61, rt73, rt2500 please skip directly to the WPA Section entitled 'WPA with Ra' based chipsets below.

Requirements: In most cases the wpa_supplicant package is required in order to connect via WPA. If you have a working ethernet or unencrypted/WEP wireless connection, this package may be installed via:

sudo aptitude install wpasupplicant

If only wireless is available, I would recommend that an unencrypted connection first by established and tested first before directly proceeding to make a WPA connection. WPA adds another layer of complexity.

Creation of /etc/wpa_supplicant.conf file

In Terminal, type :

gksu gedit /etc/wpa_supplicant.conf

Inside the file add the following for WPA(1):

ap_scan=1
ctrl_interface=/var/run/wpa_supplicant

network={
ssid="ESSID_IN_QUOTES"
scan_ssid=0
proto=WPA
key_mgmt=WPA-PSK
psk="ASCII PSK Password in Quotes"
pairwise=TKIP
group=TKIP
}

For WPA(2)

ctrl_interface=/var/run/wpa_supplicant

network={
ssid="ESSID_IN_QUOTES"
psk="ASCII PSK Password in Quotes"
key_mgmt=WPA-PSK
proto=RSN
pairwise=CCMP
}

***Word of caution -- In some cases I have found WPA(2) to have different settings than the above. Some Broadcom cards use the pairwise/group TKIP cipher for WPA2 rather than CCMP. I would suggest all initially use WPA(1) and then later convert to WPA2 since some variations to the above may be needed

Connect via Terminal :

sudo ifconfig [interface] down
sudo dhclient -r [interface]
sudo wpa_supplicant -w -D[****see footer below***] -i[interface] -c/etc/wpa_supplicant.conf -dd
sudo ifconfig [interface] up
sudo iwconfig [interface] mode Managed
sudo dhclient [interface]

***footer
The value listed here is dependent on the driver you have installed. Typing man wpa_supplicant at command line will give you the full gamut of choices however a quick reference
ndiswrapper=wext (use wext and not ndiswrapper despite what documentation might suggest)
ath_pci = madwifi
ipw2100/2200=ipw

WPA with Ra Based Chipsets

Ra cards do not require the wpa_supplicant package to use WPA. Here is how to connect from the command line with these cards

WPA(1)

sudo ifconfig [interface] down
sudo dhclient -r [interface]
sudo ifconfig [interface] up
sudo iwconfig [inteface] essid “ESSID_IN_QUOTES”
sudo iwpriv [interface] set AuthMode=WPAPSK
sudo iwpriv [interface] set EncrypType=TKIP
sudo iwpriv [interface] set WPAPSK=”YOUR_WPA_PSK_KEY”
sudo dhclient [interface]

A successful connection in all cases will results in this

user@computer:~$ sudo dhclient wlan0
There is already a pid file /var/run/dhclient.pid with pid 134993416
Internet Systems Consortium DHCP Client V3.0.4
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/

Listening on LPF/wlan0/00:12:17:35:17:10
Sending on LPF/wlan0/00:12:17:35:17:10
Sending on Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 4
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7
DHCPOFFER from 192.168.1.1
DHCPREQUEST on wlan0 to 255.255.255.255 port 67
DHCPACK from 192.168.1.1
bound to 192.168.1.101 — renewal in 299133 seconds.

The computer in this example has received an IP address of 192.168.1.101

Users of RTL 8180, RTL8185, RTL 8187 using the built in native r8187 / r818x drivers

By default the r8187 and r818x drivers are blacklisted due to a know bug. These drivers are usuable however with a twist to the above methods

If you want to try using these drivers, please load the kernel modules:

sudo modprobe r818x
sudo modprobe r8187

These drivers require a bogus or extra letter be suffixed to the essid name in order for these drivers to work

For example if your are trying to connect to a router with essid=Router, at he command line you would type essid=Routerx. Notice the extra x or bogus character. I have provided an example using the unencrypted connection procedure below, however this extra character needs to be used if attempting to connect to all network types (unencrypted/ WEP / WPA)

sudo ifconfig [interface] down
sudo dhclient -r [interface]
sudo ifconfig [interface] up
sudo iwconfig [interface] essid “Routerx”
sudo iwconfig [interface] mode Managed
sudo dhclient [interface]

If these drivers work for you, and you would like these drivers to load automatically at startup for you, avoiding to have to type sudo modprobe everytime, please edit your blacklist file

gksu gedit /etc/modprobe.d/blacklist

And comment out (or prefix the following lines with a # sign). You want the following lines to appear as below:

#blacklist r8187
#blacklist r818x

0 comments: