Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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

Other posts seems to be addressing more complicated network connection issues from the command line.

The Unity panel Network indicator/button doesn't respond too well sometimes - it keeps trying to connect to a network even when i click on "disconnect", stuff like that.

So I want to go command line for the control. I don't like GUIs anyway.

Is there not some simple command line tool which can do something like the following?

wifi connect MyNetworkNameA
wifi disconnect
wifi connect MyNetworkNameB
share|improve this question
2  
Depends , what wireless security ? This is covered in detail here - help.ubuntu.com/community/NetworkConfigurationCommandLine/… – bodhi.zazen May 6 '14 at 15:27
up vote 53 down vote accepted

I think you want to keep using managed interface (by NetworkManager). nmcli is a command‐line tool for controlling NetworkManager.

Ubuntu <= 15.10

  • Disconnect:

    nmcli d disconnect iface <wlan0>
    
  • Connect:

    nmcli d wifi connect <WiFiSSID> password <WiFiPassword> iface <wlan0>
    

    Just change <wlan0>, <WiFiSSID>, <WiFiPassword> to reflect your setup.

If WiFi info already saved, easier way:

  • Disconnect:

    nmcli c down id <WiFiConn>
    
  • Connect:

    nmcli c up id <WiFiConn>
    

    <WiFiConn> name of connection as it was save in NetworkManager (Check nmcli c).

Myself prefer nmcli d disconnect iface <wlan0> & nmcli c up id <WiFiConn> which have minimum input from myside.

Reference: man nmcli

share|improve this answer
1  
Works like a charm! And, as suspected, the command line responds immediately, while the GUI can be sluggish, uncooperative, and unresponsive sometimes. – cmo May 6 '14 at 15:55
    
And thank you for distilling it down to the few basic commands! – cmo May 6 '14 at 15:56
1  
Saved my day when I lost my Unity dash and taskbar, and the Network Settings dialog kept on crashing upon any kind of network connection establishment. – Janaka Bandara Nov 27 '14 at 1:21
    
is there a way to automate it so it connects whenever the wifi is available ? – kirill_igum Dec 1 '15 at 19:44
1  
@kirill_igum , sorry to be late quiet busy, You may use cron for scheduling wifi scan using iwlist wlan0 scanning or nmcli d wifi list then nmcli to connect to the corresponding wifi network depending on your needs. – Sneetsher Jan 11 at 21:59

If your wi-fi access point is saved, it will auto-connect. Turn wireless on or off with a simpler command:

nmcli nm wifi on
nmcli nm wifi off

on newer version:

nmcli radio wifi on
nmcli radio wifi off

For reference, see man nmcli.

share|improve this answer
    
Yep, this the best (simpler then mine :) ) when working with single WiFi network. – Sneetsher Apr 13 '15 at 8:27
1  
How do you make NM enable wifi automatically during boot? Every time I reboot, Network Manager starts with wifi disabled. – Cerin Jul 25 '15 at 21:46
    
@Cerin, you may try adding this command to startup applications, see askubuntu.com/questions/243139/… – Sneetsher Jan 11 at 21:47
1  
Note the nm option has been removed or replaced (?) in newer versions of nmcli – dgorissen Mar 18 at 14:30
    
@dgorissen, yes it seems changed on newer version, replace nm with radio. I've updated this answer. – Sneetsher Apr 1 at 18:31

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.