Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sometimes I boot into recovery kernel with CLI and networking for troubleshooting my laptop. So is there a way to connect to a wireless router or AP over command line? If it is possible what are the commands for the following:

  1. To list available networks.
  2. To connect to a network with: SSID, WPA2 key and DHCP mode.
  3. A command to connect with: SSID, ad-hoc mode, ip-address, netmask, gateway.
share|improve this question
up vote 8 down vote accepted

You will need the wpasupplicant package in order to connect to a network secured with wpa or wpa2.

Listed by order :
1 : sudo iwlist scan

2 : sudo iwconfig <interface> essid "my network"
iwpriv <interface> set AuthMode=<WPA2PSK or WPA2AES>
iwpriv <interface> set <WPA2PSK or WPA2AES>='WPA PASSPHRASE'

3 : sudo iwconfig <interface> essid "my network"
ifconfig <interface> inet <ip> netmask <mask> then set a route to your gateway route add <destination> gw <gateway ip>

share|improve this answer
You maybe want to put a blank in front of the 'iwpriv' line containing your password. That way it won't show up in the history. – htorque Oct 28 '10 at 15:11
Do you need to do the iwconfig essid step twice? – Marius Gedminas Nov 3 '10 at 11:19
In step 3, what is <destination>? I am familiar with all of the above values, with the exception of that one. – InkBlend Dec 26 '12 at 1:13

nm-tool or sudo iwlist scan will show you all available wireless networks.

There's a cnetworkmanager package that ought to let you control Network Manager from the command line. I've never used it myself.

share|improve this answer

I think iwlist and iwconfig does this. Here is the forum that talks about this.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.