Linux For Cynics One user's experiences with Linux

29Apr/131

Wifi from Command Line

In this short how-to I'll show you how to connect to a WPA wifi network from the network without any GUI tools.

First, we have to install the relevant software. Some distros do not come with much wifi firmware or wpa support out of the box and they must be installed after the fact. In Debian, follow this guide to install them.

Display the currently active network interfaces:

$ sudo iwconfig

You should see something like wlan0. Let's activate it:

$ sudo ifconfig wlan0 up

Optional if you know the SSID of the network you want:
Scan the interface for access points:

$ sudo iwlist wlan0 scan

Open the /etc/network/interfaces file (replace editor with text editor of your choice):

$ sudo editor /etc/network/interfaces

and add an entry for the network you want to join (replace words in CAPS with your details, where NAME is what you want to call the entry):

iface NAME inet dhcp
  wpa-ssid YOUR-SSID
  wpa-psk YOUR-PASSWORD

Now, just connect to that network!

$ ifup wlan0=NAME

To connect to a different network, simply add another entry to /etc/network/interfaces and run ifup wlan0=NEW-NETWORK-NAME.