Posts Tagged ‘WPA’

November 13th, 2011  Posted at   Linux

When we want to connect to a wireless network protected using WPA/WPA2 schema using command line we cannot use iwconfig to achieve it. We need to use a “supplicant” program. The most common is wpa_supplicant. To use this program we need to provide it a config file, so let’s do it.

Create a new file with the following content:

# WPA/WPA2 PSK Config file

network={

	ssid="MyNetwork"

	scan_ssid=1

	key_mgmt=WPA-PSK

	psk="MyKey"
}

Where “MyNetwork” is the name (ESSID) of the network you want to connect to and “MyKey” is the Pre-Shared Key for the network.

Save this file wherever you want. I’ll use /root/wpa.conf (I’m using BT5 right now :)).

** If the example file configuration does not meet your requirements you can find other configurations in the following file:

http://hostap.epitest.fi/gitweb/gitweb.cgi?p=hostap.git;a=blob_plain;f=wpa_supplicant/wpa_supplicant.conf

The interface I’ll be using for this connection is eth1.

The command we need to launch to finally connect to this network is the following:

wpa_supplicant -Dwext -c/root/wpa.conf -ieth1

Parameters meaning:

-D driver to use. (wext -> Linux wireless extensions (generic))

-c config file to use. (/root/wpa.conf -> our new config file)

-i interface to use. (eth1 -> my wireless interface)

As the wpa_supplicant command that we use needs to be active permanently while we are connected to the network it’s better to launch it in the background so we’ll use the following command:

wpa_supplicant -Dwext -c/root/wpa.conf -ieth1 &

If you’re using a graphical interface like Gnome or KDE you can also press ALT+F2 to run the program in background mode:

And that’s it, you’re connected.

Remember that once you’ve done this you need to configure the IP parameters for the network. If there is a DHCP server running you can use:

dhclient eth1

Enjoy.