How To Configure Wireless / WiFi Networking in Ubuntu via the Command Line (CLI)
25 06 2010
I did this on a minimal install of Ubuntu Lucid, so it is as up-to-date as possible. The PC I was using has no Windows Manager of Graphical Display Manager, just the good old terminal so all this is done via the CLI only. I did this using a USB WiFI dongle, but it should be the same whether you use an internal card or a USB card.
First, you need to install the relevant software. You need to have a wired connection at this point, otherwise this wont work.
sudo apt-get install wireless-tools wpasupplicant
If you are connecting to an open network, you wont need wpasupplicant. Next, you need to “bring up” (essentially this means activate) your WiFi interface. So, issue:
sudo ifconfig wlan0 up
Next, to make sure your wireless device is working as it should issue:
iwconfig and then sudo iwlist scan
This should show you some wireless networks as proof that the WiFi device is working, if something goes wrong here, then there is a problem with your device or driver and you need to get googling.
If you are accessing a secured network and you really should be, you need to access the correct version of your WiFi key. To get your key, issue this command:
wpa_passphrase YOURSSID YOURWIFIPASSWORD
This will result in something that looks like this:
You need to make a note of the long phrase after psk= (NOT #psk=) as this your WiFi password in hex format.
Next, you need to edit your interfaces file, so issue:
sudo nano /etc/network/interfaces
At the end of this file, you need to add your WiFi configuration. Here are the options you can add.
auto wlan0 #change this to the name of your WiFi interface iface wlan0 inet dhcp #this is normally fine, if you want a static IP address replace “dhcp” with “static” netmask 255.255.255.0 #change this as appropriate for your network, this value is usually right gateway 192.168.1.1 #change this as appropriate for your network address 192.168.1.100 #only needed for a static IP address dns-nameservers 192.168.1.1 #only needed for a static IP address wpa-driver wext #you shouldn’t need to change this wpa-ssid YOURSSID #just type the name of your SSID here wpa-ap-scan 1 #if the name of your SSID is hidden usually, type 2 instead of 1 wpa-proto WPA #if you use WPA1 type WPA, if you use WPA2 type RSN wpa-pairwise CCMP #if you use AES type CCMP, if you use TKIP type TKIP wpa-group CCMP #if you use AES type CCMP, if you use TKIP type TKIP wpa-key-mgmt WPA-PSK #usually WPA-PSK (if you share a key) but sometimes WPA-EAP (for enterprises) wpa-psk YOURHEXKEYFROMABOVE #the hex key that you generated earlier
Thus, since I am using a WiFi card that is identified as wlan0 and am connecting to a WPA1 AES encrypted network called MYPLACE that isn’t hidden without a static IP address, this is what I added: