Thursday, September 8, 2016

wireless - How to connect to WiFi from the command line?



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


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





  • To see list of saved connections, use ()



    nmcli c

  • To see list of available WiFi hotspots ()



    nmcli d wifi list


    or:




    sudo iwlist  scanning

  • To see list of interfaces ()



    ifconfig -a



Just change , , in the following commands to reflect your setup. If WiFi info already saved, easier way using name of connection as it was saved in NetworkManager.




Ubuntu 16.04



##disconnect
nmcli d disconnect

##connect
nmcli d connect



Another way:



##disconnect
nmcli c down

##connect
nmcli c up


Ubuntu 15.10 & previous




##disconnect
nmcli d disconnect iface

##connect
nmcli d wifi connect password iface


Another way:




##disconnect:
nmcli c down id

##connect:
nmcli c up id


If your password isn't automatically recognized type this:



nmcli -a c up 



Reference: man nmcli


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...