Wednesday, April 30, 2014

Connecting to wifi access point from the terminal

The following process has worked for me. I simply followed the procedure mentioned in arch linux wiki with a small tip from one of their forum post. So, a big thanks to the Arch community.

First of all, I am assuming all the wireless drivers are installed and loaded properly. I used the commands: iw, ip, wpa_supplicant for the process. NetworkManager was not used.

 $ iw dev  
   phy#0  
     Interface wlan0  
     ifindex 3  
     type managed  

This gives me the name of the wireless interface: wlan0

 $ ip link show  
 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN   
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
 2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000  
   link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff  
 3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000  
   link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff  

That means my wireless link wlan0 was not UP (otherwise the word UP would be there within <>)

 $ sudo ip link set wlan0 up  
 $ ip link show  
 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN  
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
 2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000  
   link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff  
 3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000  
   link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff  

Now, the wlan0 is UP. So, now it is time to find out what access points are available.

 $ sudo iw dev wlan0 scan | grep SSID  
     SSID: TP-LINK_POCKET_3020_C50F1E  
     SSID: Ramananda  

Ok. I want to connect to the first one. But before that I need to create a wpa_supplicant.conf file with the SSID and Password for the Access Point to which I want to connect.

 $ wpa_passphrase TP-LINK_POCKET_3020_C50F1E xxxxxxxx > wpa_supplicant.conf  

Now that the wpa_supplicant.conf file is generated, I can attempt to connect to the access point.

 $ sudo wpa_supplicant -iwlan0 -c wpa_supplicant.conf  
 ioctl[SIOCSIWENCODEEXT]: Invalid argument  
 ioctl[SIOCSIWENCODEEXT]: Invalid argument  
 Trying to associate with xx:xx:xx:xx:xx:xx (SSID='TP-LINK_POCKET_3020_C50F1E' freq=2462 MHz)  
 Associated with xx:xx:xx:xx:xx:xx  
 WPA: Key negotiation completed with xx:xx:xx:xx:xx:xx [PTK=CCMP GTK=CCMP]  
 CTRL-EVENT-CONNECTED - Connection to xx:xx:xx:xx:xx:xx completed (auth) [id=0 id_str=]  

I don't know about the ioctl lines, but now I am connected to the wireless access point. Now what I need to do is to use dhclient3 or dhcpcd to get an ip address from my access point (which is also configured as a dhcp server)

 $ sudo dhclient3 wlan0  

Done. Now I can successfully ping google :-)
Post a Comment