Linux For Cynics One user's experiences with Linux


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

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.


Install Wifi Firmware and WPA Support in Debian

Debian is a wonderful distribution but it is a bit strict on what it comes packaged with. Most wifi cards do not have open drivers, so you have to install them from the non-free repos. Here's now to install them and use them with wpa-supplicant.

First, we need to add the non-free Debian repositories. Add these lines to the /etc/apt/sources.list file:

deb wheezy main contrib non-free
deb-src wheezy main contrib non-free
deb wheezy/updates main contrib non-free
deb-src wheezy/updates main contrib non-free

Once the non-free repo is added, update and install the driver I need. You might need different firmware:

$ sudo apt-get update
$ sudo apt-get install firmware-iwlwifi

Also get the wireless-tools package:

$ sudo apt-get install wireless-tools

So we have the driver, but now we need to use it!

Since the iwlwifi module is automatically loaded for supported devices, we need to reload this module to access installed firmware:

$ sudo modprobe -r iwlwifi ; modprobe iwlwifi

Now we see if the device has an available interface:

$ sudo iwconfig

Yep! Mine is called wlan0. Connecting to a wpa secured wifi will be covered in the next post.