Thursday, April 23, 2009

Linux: Connecting to Wireless Networks with wpa_supplicant

Connecting to a wireless network in Linux is easy with wpa_supplicant. If you haven't, install the wpasupplicant package first. Also, install wireless-tools.



Of course, the driver for the wireless adapter has to be installed and loaded too. You can either use Linux native driver or Windows NDIS driver for your wireless device. The Linux kernel itself provides native driver modules for popular wireless chips. Alternatively, you can use a Windows driver in Linux with the help of ndiswrapper. I prefer using ndiswrapper to enable my wireless adapters. Once ndiswrapper is configured correctly, the following command will load the driver for the wireless network adapter.



modprobe ndiswrapper


In order to be able to control wpasupplicant with wpa_cli and wpagui, you should add useself to the netdev group.


adduser username netdev

To automatically have wpasupplicant take care of wireless connections, you should edit two files, /etc/network/interfaces and /etc/wpa_supplicant/wpa_supplicant.conf. The following is a sample /etc/network/interfaces file.



auto lo wlan1

iface lo inet loopback

iface default inet dhcp

iface WPA_hidden inet static
address 192.168.1.250
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

iface wlan1 inet manual
wpa-driver wext
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf


Then, you need to create a configuration file /etc/wpa_supplicant/wpa_supplicant.conf. Its contents typically looks like this:



ap_scan=1
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

network={
ssid="MyWifiNet"
scan_ssid=1
key_mgmt=WPA-PSK
proto=WPA
pairwise=TKIP
group=TKIP
psk="WPA password"
id_str="WPA_hidden"
}

network={
ssid="linksys"
key_mgmt=NONE
wep_key0=e2c45314910abf72e871beda87
wep_tx_keyidx=0
}


In the example above, the ssid= and psk= lines should to be adjusted for each wireless network. The second nework linksys is an example of WEP networks. Next, run the following command to start a WPA connection to your wireless network.



wpa_supplicant -c /etc/wpa_supplicant.conf -i wlan1 -B


The steps below finalize wirless network setup.



ifconfig wlan0 192.168.1.201 up

route add default gw 192.168.1.1


Additionally, check the contents of /etc/resolv.conf which set up DNS servers.



To Kill WPA_supplicant


To terminate wpa_supplicant, execute wpa_cli and type the following commands:


terminate
quit

No comments:

Post a Comment

About This Blog

KBlog logo This blog is about current events and issues concerning general population. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

icon
Powered By Blogger