Sei sulla pagina 1di 3

Ubuntu Community Ask!

Developer Design Hardware Insights Juju Shop More


sign up log in tour help

_
Ask Ubuntu is a question and answer Here's how it works:
site for Ubuntu users and developers.
Join them; it only takes a minute:

Sign up
Anybody can ask Anybody can The best answers are voted
a question answer up and rise to the top

connect to wifi from 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

wireless command-line network-manager panel

asked May 6 '14 at 15:20


cmo
743 2 8 13

3 Depends , what wireless security ? This is covered in detail here -


help.ubuntu.com/community/NetworkConfigurationCommandLine/ bodhi.zazen May 6 '14 at 15:27

2 Answers

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 ( <SavedWiFiConn> )


nmcli c

To see list of available WiFi hotspots ( <WiFiSSID> )

nmcli d wifi list

or:
sudo iwlist wlan0 scanning

To see list of interfaces ( <WifiInterface> )


ifconfig -a

Just change <WifiInterface> , <WiFiSSID> , <WiFiPassword> in the following commands to


reflect your setup. If WiFi info already saved, easier way using <SavedWiFiConn> name of
connection as it was saved in NetworkManager.

Ubuntu 16.04

##disconnect
nmcli d disconnect <WifiInterface>
##connect
nmcli d connect <WifiInterface>

Another way:

##disconnect
nmcli c down <SavedWiFiConn>

##connect
nmcli c up <SavedWiFiConn>

Ubuntu 15.10 & previous

##disconnect
nmcli d disconnect iface <WifiInterface>

##connect
nmcli d wifi connect <WiFiSSID> password <WiFiPassword> iface <WifiInterface>

Another way:

##disconnect:
nmcli c down id <SavedWiFiConn>

##connect:
nmcli c up id <SavedWiFiConn>

Reference: man nmcli

edited Jun 20 '16 at 21:47 answered May 6 '14 at 15:36


user.dz
30k 11 70 147

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

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

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. user.dz Jan 11 '16 at 21:59

1 The command that I was issuing was giving an error. I was issuing this command: nmcli c up id "Apollo III
Connect" It gave an error. When I leave out the word id and typed this it connects without error: nmcli c
"Apollo III Connect" . I understand how to connect it now. You're saying id as the parameter and saying
replace the word id with the name of the connection, which you are naming <WiFiConn>. Thanks! L. D. James
Jun 15 '16 at 22:48

1 mcli tool, version 1.2.0 L. D. James Jun 15 '16 at 23:48

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 .

edited Apr 1 '16 at 18:30 answered Mar 4 '15 at 20:16


user.dz LinuxLearner
30k 11 70 147 139 1 2

Yep, this the best (simpler then mine :) ) when working with single WiFi network. user.dz 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/
user.dz Jan 11 '16 at 21:47

1 Note the nm option has been removed or replaced (?) in newer versions of nmcli dgorissen Mar 18 '16 at 14:30

1 @dgorissen, yes it seems changed on newer version, replace nm with radio . I've updated this answer. user.dz
Apr 1 '16 at 18:31
protected by Community May 25 at 2:43
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on
this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Potrebbero piacerti anche