pantz.org banner
Setting up wireless with wpa2 on linux
Posted on 11-08-2007 06:23:00 UTC | Updated on 05-30-2016 22:50:53 UTC
Section: /software/wpa_supplicant/ | Permanent Link

This an example of connecting a linux laptop to an access point that uses WPA2. The example below will use an Dell Inspiron 9300 laptop running Kubuntu 7.10. The laptop uses a built in Intel PRO/Wireless 2200BG (Centrino) Network Connection mini PCI adapter. Kubuntu had the wireless card working on install (wireless driver is called ipw2200) but no setup for WPA2 that I could find.

The access point I'm going to connect to is a Linksys WRT54GL. It is running dd-wrt firmware version 23 sp2. The access point security is set to "wpa2 pre-shared key mixed" with the WPA algorithm set to "AES". The SSID will be set to "wpatest" for this example.

Before continuing any further, turn off an network manager services like "NetworkManager" which will mess with manual network setup like we are going to be doing. A "sudo service NetworkManager stop" should kill it.

The program we will need to connect to the access point is called wpa_supplicant. Supplicant is the IEEE 802.1X/WPA component that is used in the client machines. It implements key negotiation with a WPA Authenticator and it controls the roaming and IEEE 802.11 authentication/association of the wlan driver. Wpa_supplicant only supports certain drivers so if your having problems with this check the wpa_supplicant page (google it) to make sure your driver works with it. Kubuntu 7.10 comes with wpa_supplicant and other wireless tools installed.

First we need to generate a WPA PSK from an passphrase for a SSID so we can try to protect the network. We do this with the wpa_passphrase program using the "wpatest" SSID name I noted above with nice long passphrase. Your pass phrase should have some numbers and special characters in it if you can.

wpa_passphrase wpatest thisisanicelongpassphraseitisniceandlongforareason

This will output a long block of characters that your going to need to put in the /etc/wpa_supplicant.conf file. Keep it handy. Now open the file /etc/wpa_supplicant/wpa_supplicant.conf in your favorite editor. Remember to sudo when opening the file. Now paste the code below into it.

ctrl_interface=/var/run/wpa_supplicant
#ap_scan=2
# commented out lines are optional
network={
  ssid="wpatest"
  scan_ssid=1
  key_mgmt=WPA-PSK
  psk=""
  #proto=WPA RSN
  #pairwise=CCMP TKIP
  #group=CCMP TKIP
}

In the above config you will see the field "ssid=". Put your ssid for your network in there. Mine is "wpatest" above. Next, where you see the line "psk=" after the = sign you have to put the output from the wpa_passphrase we generated above. It would look something like

psk=a6e6af3e3d77b4c7dd6a3c292ecde36839a1f2d921"

Save that file and exit your editor. Now we need to setup the wireless interface. Use the comand "dmesg" to check for your wireless cards inteface. Look for eth0, eth1, wlan0, or something like that in the output. Your wired connections might look like this also so make sure it's your wireless interface. You could also try the command "ifconfig" to see if you see your wireless interface there. Kubuntu is pretty good about finding the wireless card. Once you know what it is lets bring it up. Mine is eth1 so the command would be the following.

sudo ifconfig eth1 up

Now we can scan for networks. This is good if you want to see information about the networks in the area. You might already know your access points info but if you don't just scan.

sudo iwlist scan

It will give the list of access points, Ad-Hoc cells in range, channels, and a lot more info. My access point was listed and showed it's name "wpatest" on channel 7. So lets configure the wireless interface for that.

sudo iwconfig eth1 essid "wpatest" channel 7

Now we need to start wpa_supplicant. You might need to modify command line switches -i and -D to work with your own setup. -D is the driver to use. My Intel card can use the wext driver which is the Linux wireless extensions (generic). Try that one first. If it does not work look at the man page for wpa_supplicant for other driver types like the more modern nl80211. Also, -i is the interface for your wireless card. Mine is eth1. Yours will be what you found in the earlier step. The line we need to run is the following.

sudo wpa_supplicant -B -Dnl80211 -ieth1 -c/etc/wpa_supplicant/wpa_supplicant.conf

If wpa_supplicant started successfully then you can make your dhcp request over the network to get an ip address with dhclient. I use eth1 because again it's my wireless cards interface. Specifying hostname to the DHCP client daemon may help to find the MAC address of a connecting laptop in DHCP logs on the server, in case there�s filtering for MAC addresses.

# simple example
sudo dhclient eth1

# dhcp hostname example using busybox and udhcpc
busybox udhcpc -x hostname iamhere -i eth1

After this you should have an ip and be on the network. Below is the shell script I use to start my wireless interface. If you know the settings of your access point just change to fit your needs.

#!/bin/sh
sudo pkill wpa_supplicant
sudo ifconfig eth1 down
sudo ifconfig eth1 up
# for iwconfig put in "channel 7" if you need to select a specific channel, try without it first
sudo iwconfig eth1 essid "wpatest" 
sudo wpa_supplicant -B -Dnl80211 -ieth1 -c/etc/wpa_supplicant/wpa_supplicant.conf
sudo dhclient eth1

Reddit!

Related stories


RSS Feed RSS feed logo

About


3com

3ware

alsa

alsactl

alsamixer

amd

android

apache

areca

arm

ati

auditd

awk

badblocks

bash

bind

bios

bonnie

cable

carp

cat5

cdrom

cellphone

centos

chart

chrome

chromebook

cifs

cisco

cloudera

comcast

commands

comodo

compiz-fusion

corsair

cpufreq

cpufrequtils

cpuspeed

cron

crontab

crossover

cu

cups

cvs

database

dbus

dd

dd_rescue

ddclient

debian

decimal

dhclient

dhcp

diagnostic

diskexplorer

disks

dkim

dns

dos

dovecot

drac

dsniff

dvdauthor

e-mail

echo

editor

emerald

encryption

ethernet

expect

ext3

ext4

fat32

fedora

fetchmail

fiber

filesystems

firefox

firewall

flac

flexlm

floppy

flowtools

fonts

format

freebsd

ftp

gdm

gmail

gnome

google

gpg

greasemonkey

greylisting

growisofs

grub

hacking

hadoop

harddrive

hba

hex

hfsc

html

html5

http

https

hulu

idl

ie

ilo

intel

ios

iperf

ipmi

iptables

ipv6

irix

javascript

kde

kernel

kickstart

kmail

kprinter

krecord

kubuntu

kvm

lame

ldap

linux

logfile

lp

lpq

lpr

maradns

matlab

memory

mencoder

mhdd

mkinitrd

mkisofs

moinmoin

motherboard

mouse

movemail

mplayer

multitail

mutt

myodbc

mysql

mythtv

nagios

nameserver

netflix

netflow

nginx

nic

ntfs

ntp

nvidia

odbc

openbsd

openntpd

openoffice

openssh

openssl

openvpn

opteron

parted

partimage

patch

perl

pf

pfflowd

pfsync

photorec

php

pop3

pop3s

ports

postfix

power

procmail

proftpd

proxy

pulseaudio

putty

pxe

python

qemu

r-studio

raid

recovery

redhat

router

rpc

rsync

ruby

saltstack

samba

schedule

screen

scsi

seagate

seatools

sed

sendmail

sgi

shell

siw

smtp

snort

solaris

soundcard

sox

spam

spamd

spf

spotify

sql

sqlite

squid

srs

ssh

ssh.com

ssl

su

subnet

subversion

sudo

sun

supermicro

switches

symbols

syslinux

syslog

systemd

systemrescuecd

t1

tcpip

tcpwrappers

telnet

terminal

testdisk

tftp

thttpd

thunderbird

timezone

ting

tls

tools

tr

trac

tuning

tunnel

ubuntu

unbound

vi

vpn

wget

wiki

windows

windowsxp

wireless

wpa_supplicant

x

xauth

xfree86

xfs

xinearama

xmms

youtube

zdump

zeromq

zic

zlib