Axeman.IN

A Weblog of Programming, Philosophy and Random Thoughts.

How to Connect to Wifi (WPA) Through Command Line

Ever wondered what would happen if you are stuck on command line or if something happened to your network manager, and only source of Internet is WiFi. How would you connect ?

Here are few simple steps:

  1. Add your network in wpa_supplicant.conf

$ sudo vim /etc/wpa_supplicant.conf

  1. Press i to start editing the file. Write your configuration in following format

network={ ssid=”wifi_name” psk=”wifi_password” }

  1. Press Escape then type ‘:wq’ (without quotes) to save the file.

  2. Now back to shell type the following command

$ sudo wpa_supplicant -B -iwlan0 -c/etc/wpa_supplicant.conf -Dwext

Replace wlan0 by your interface name. Generally it is wlan0 or eth1. To confirm execute sudo iwconfig in shell.

  1. Now you will be connected to WiFi, but you won’t have the IP address ( If your WiFi connection gives you IP address automatically do this step otherwise do step 6). To get an IP address execute following command

$ sudo dhclient wlan0

  1. If your WiFi connection doesn’t give you IP automatically, execute this command.

$ sudo ifconfig wlan0 w.x.y.z

Replace w.x.y.z by the IP address already assigned to you by your network administrator.

Hope this helps you. Please give your feedback through comments.

Thank You !

Comments