How To Configure Wireless / WiFi Networking in Ubuntu via the Command Line (CLI)

There are a number of tutorials available on-line for sorting out WiFi in Ubuntu via the CLI, but most of them seem quite outdated, so I decided to do my own.

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:

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:


This will result in something that looks like this:

psk=fe727aa8b64ac9b3f54c72432da14faed933ea511ecab1 5bbc6c52e7522f709a

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     #change this as appropriate for your network, this value is usually right
gateway     #change this as appropriate for your network
address     #only needed for a static IP address
dns-nameservers     #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:

auto wlan0
iface wlan0 inet dhcp
wpa-driver wext
wpa-ssid MYPLACE
wpa-ap-scan 1
wpa-proto WPA
wpa-pairwise CCMP
wpa-group CCMP
wpa-key-mgmt WPA-PSK
wpa-psk 71c81a844973ae7bb1243141e5caa7b6bb0e2d7eetcetcetc

Finally, comment out the top section so it looks like this:

#auto eth0
#iface eth0 inet dhcp

This stops your wired network from working. This helps to ensure there are no conflicts. Remember, if you want your wired network to work again, remove these two comments (the #).

Finally, save the file by pressing CTRL and X and then pressing Y to save to the file. Now, reboot and your network should come up. Yay!

Some people have found that this doesn’t always work, so the next thing to do is to edit the configuration file for the wpasupplicant program. Do this by issuing:

sudo nano /etc/wpa_supplicant.conf

Basically, you add pretty much the same information here as you did to the interfaces file, except without the wpa- part. So, my file looks like this:


As far as I am aware, the options are the same. So, edit this file as necessary, make sure you add the ctrl_interface and network={ at the beginning and the } part at the end. Save it and try restarting again. If it still doesn’t work, then kick your PC, wish you had installed Windows 7 instead and go off and do some Googling. You’ll find the answer on the Ubuntu forums and you’ll be happy again.

Best of luck!

18 thoughts on “How To Configure Wireless / WiFi Networking in Ubuntu via the Command Line (CLI)

  1. Is it possible to have both the wired and wireless connection start up automatically? I noticed you said to comment out the auto eth0 so there will be no conflicts. But ideally I’d like both connections to be active.

  2. Ahh, not sure if my reply got here it is again:

    Yes, it is fine to have both the WiFi connection and the eth0 connection running at the same time, just uncomment the two lines I told you to comment out. The only issue is that you will have a PC with two IP addresses. This means that some apps might use one IP address and some apps will use the other. This can, however, be really useful, since you can assign a bandwidth heavy app to the eth0 card and then use the WiFi card for everything else…

  3. Thanks a lot for this post, I struggling to setup my wifi (broadcom device) in ubuntu 10.04 but after following your post i managed to set it up correctly and now i can use both wired and wireless correctly. Thanks again for this post….

  4. Just wanted to add my thanks for such a clear guide that even a total linux novice like myself can follow. Worked a charm.

  5. Thanks for the steps. It worked great for me but one thing to note is that when creating the hex key with wpa_passphrase you will need to escape any special characters. If your passphrase is “Password$” it needs to be entered “Password$”. Fortunately the output tells you what it thinks your passphrase is but you need to pay attention if you use special characters.

  6. Just a tip to get the right wpa-key into the interface file. I did:

    wpa_passphrase your_ssid Your_wpapassword | grep psk >> /etc/network/interfaces

    This adds the key last in the interface file. You have to edit and delete some crap but it is a easy way to get it into the file if you can’t copy it another way. If you don,t have the right key it will not work.

  7. Hi ,
    can u tell me how i can connect wifi open and secure network using command.please give me any solutions .i am working on ubuntu 12.0.4 with 32-bit.


  8. Thank you so much. I’ve tried many things without success and finally your manual helped me to make my wifi working. What manual did you take this info from? I couldn’t find this in any official documentation

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.