Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

3 Answers 3

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
4  
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
1  
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

 
discard

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.