2018-02-28 15:47:51 +00:00
= NetworkManager Command Line Interface (nmcli)
2017-10-26 21:20:01 +00:00
2018-02-27 11:06:06 +00:00
[[description]]
== Description
2017-10-26 21:20:01 +00:00
2018-02-27 11:06:06 +00:00
`nmcli` is a tool that allows NetworkManager management from command line.
2017-10-26 21:20:01 +00:00
2018-02-27 11:06:06 +00:00
[[networkmanager-status]]
== NetworkManager status
2017-10-26 21:20:01 +00:00
2018-02-27 11:06:06 +00:00
Display overall status of NetworkManager
2017-10-26 21:20:01 +00:00
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli general status
2018-02-27 11:06:06 +00:00
----
2017-10-26 21:20:01 +00:00
2018-02-27 11:06:06 +00:00
Display active connections
2017-10-26 21:20:01 +00:00
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli connection show --active
2018-02-27 11:06:06 +00:00
----
2017-10-26 21:20:01 +00:00
2018-02-27 11:06:06 +00:00
Display all configured connections
2018-01-26 18:29:28 +00:00
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli connection show configured
2018-02-27 11:06:06 +00:00
----
2017-10-26 21:20:01 +00:00
2018-02-27 11:06:06 +00:00
[[connectdisconnect-to-an-already-configured-connection]]
== Connect/disconnect to an already configured connection
2017-10-26 21:20:01 +00:00
2018-02-27 11:06:06 +00:00
Connect to a configured connection by name
2017-10-26 21:20:01 +00:00
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli connection up id _connection name_
2018-02-27 11:06:06 +00:00
----
2017-10-26 21:20:01 +00:00
2018-02-27 11:06:06 +00:00
Disconnection by name
2017-10-26 21:20:01 +00:00
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli connection down id _connection name_
2018-02-27 11:06:06 +00:00
----
2017-10-26 21:20:01 +00:00
2018-02-27 11:06:06 +00:00
[[wifi]]
== Wifi
Get Wifi status
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli radio wifi
2018-02-27 11:06:06 +00:00
----
Turn wifi on or off
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli radio wifi _on|off_
2018-02-27 11:06:06 +00:00
----
List available access points(AP) to connect to
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli device wifi list
2018-02-27 11:06:06 +00:00
----
Refresh previous list
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli device wifi rescan
2018-02-27 11:06:06 +00:00
----
Create a new connection to an open AP
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli device wifi connect _SSID|BSSID_
2018-02-27 11:06:06 +00:00
----
Create a new connection to a password protected AP
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli device wifi connect _SSID|BSSID_ password _password_
2018-02-27 11:06:06 +00:00
----
[[network-interfaces]]
== Network interfaces
List available devices and their status
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli device status
2018-02-27 11:06:06 +00:00
----
Disconnect an interface
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli device disconnect iface _interface_
2018-02-27 11:06:06 +00:00
----
[[create-or-modify-a-connection]]
== Create or modify a connection
To create a new connection using an interactive editor
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli connection edit con-name _name of new connection_
2018-02-27 11:06:06 +00:00
----
To edit an already existing connection using an interactive editor
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli connection edit _connection name_
2018-02-27 11:06:06 +00:00
----
[[exampletutorial]]
=== Example/Tutorial
Let's create a new connection
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
$ nmcli connection edit con-name _name of new connection_
2018-02-27 11:06:06 +00:00
----
It will ask us to define a connection type
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
Valid connection types: 802-3-ethernet (ethernet), 802-11-wireless (wifi), wimax, gsm, cdma, infiniband, adsl, bluetooth, vpn, 802-11-olpc-mesh (olpc-mesh), vlan, bond, team, bridge, bond-slave, team-slave, bridge-slave
Enter connection type:
----
In this example we will use ethernet
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
Enter connection type: ethernet
----
2018-02-28 15:47:51 +00:00
Next this will appear, note that `nmcli>` is a prompt and that it lists the main settings available
2018-02-27 11:06:06 +00:00
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
===| nmcli interactive connection editor |===
Adding a new '802-3-ethernet' connection
Type 'help' or '?' for available commands.
Type 'describe [<setting>.<prop>]' for detailed property description.
You may edit the following settings: connection, 802-3-ethernet (ethernet), 802-1x, ipv4, ipv6
nmcli>
----
2018-02-28 15:47:51 +00:00
We will edit the setting `ipv4`
2018-02-27 11:06:06 +00:00
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
nmcli> goto ipv4
----
2018-02-27 11:21:06 +00:00
Note that after this our promt has changed to this to indicate that we are currently editing the "ipv4" setting
2018-02-27 11:06:06 +00:00
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
nmcli ipv4>
----
2018-02-28 15:47:51 +00:00
List available properties under the setting `ipv4` and describe the property `method`
2018-02-27 11:06:06 +00:00
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
nmcli ipv4> describe
Available properties: method, dns, dns-search, addresses, routes, ignore-auto-routes, ignore-auto-dns, dhcp-client-id, dhcp-send-hostname, dhcp-hostname, never-default, may-fail
Property name?
Property name? method
----
2018-02-28 15:47:51 +00:00
Let's set property `method` to `auto`
2018-02-27 11:06:06 +00:00
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
nmcli ipv4> set method auto
----
2018-02-28 15:47:51 +00:00
Now that we have finished editing the `ipv4` setting let's go back to the main level.
Execute the following command until the prompt looks like this `nmcli>`
2018-02-27 11:06:06 +00:00
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
2018-02-28 16:51:56 +00:00
nmcli ipv4> back
2018-02-27 11:06:06 +00:00
----
2018-02-28 15:47:51 +00:00
If you need to list again the main settings use the `goto` command without any arguments.
After that just press enter and ignore the error.
2018-02-27 11:06:06 +00:00
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
nmcli> goto
Available settings: connection, 802-3-ethernet (ethernet), 802-1x, ipv4, ipv6
Setting name?
----
2018-02-27 11:21:06 +00:00
It is possible to set a value for a property directly from the main level
2018-02-27 11:06:06 +00:00
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
2018-02-28 15:47:51 +00:00
nmcli> set __setting__.__property__ _value_
2018-02-27 11:06:06 +00:00
----
2018-02-27 11:21:06 +00:00
For example:
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
nmcli> set connection.autoconnect TRUE
2018-02-28 15:47:51 +00:00
nmcli> set connection.interface-name _interface name this connection is bound to_
2018-02-27 11:06:06 +00:00
2018-02-28 15:47:51 +00:00
nmcli> set ethernet.cloned-mac-address _Spoofed MAC address_
2018-02-27 11:06:06 +00:00
----
Finally check the connection details, save and exit
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
nmcli> print
nmcli> save
nmcli> quit
----
[[manually-editing]]
=== Manually editing
2018-02-27 11:21:06 +00:00
To manually edit a ifcfg connection configuration open or create with a text editor the configuration file of the connection located in `/etc/sysconfig/network-scripts/ifcfg-`
2018-02-27 11:06:06 +00:00
2018-02-27 11:21:06 +00:00
A description of most common configuration options is available at: http://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-networkscripts-interfaces.html
2018-02-27 11:06:06 +00:00
2018-02-28 15:47:51 +00:00
To modify a connection password open with a text editor and edit the file `keys-` located in `/etc/sysconfig/network-scripts/`.
The password is stored in plain text.
For example
2018-02-27 11:06:06 +00:00
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 15:47:51 +00:00
$ cat /etc/sysconfig/network-scripts/keys-__connection name__
2018-02-27 11:06:06 +00:00
WPA_PSK='password'
----
2018-02-27 11:21:06 +00:00
Or if using keyfile, simply edit the connection file located inside `/etc/NetworkManager/system-connections/`
2018-02-27 11:06:06 +00:00
2018-02-27 11:21:06 +00:00
Finally save the files and to apply changes to an already active connection execute
2018-02-27 11:06:06 +00:00
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 15:47:51 +00:00
nmcli connection up id _connection name_
2018-02-27 11:06:06 +00:00
----
[[delete-a-connection-configuration]]
== Delete a connection configuration
Delete the connection
2018-02-28 15:47:51 +00:00
[source,bash,subs="+quotes"]
2018-02-27 11:06:06 +00:00
----
2018-02-28 15:47:51 +00:00
nmcli connection delete id _connection name_
2018-02-27 11:06:06 +00:00
----
Please note this also deactivates the connection.
[[documentation-for-networkmanager-command-line-interface-nmcli]]
== Documentation for NetworkManager Command Line Interface nmcli
2018-02-28 15:47:51 +00:00
The primary reference for nmcli are the manual pages nmcli and nmcli-examples.
For a quick reference, the user can type `nmcli help` to print the supported options and commands.
The help parameter can also be used to obtain a more detailed description for the individual commands.
For example `nmcli connection help` and `nmcli connection add help` show a description for the possible connection operations and for how to add connections, respectively.
2018-02-27 11:06:06 +00:00
2018-02-27 11:21:06 +00:00
The newest version of the manual page can be found on https://developer.gnome.org/NetworkManager/unstable/nmcli.html[nmcli] and https://developer.gnome.org/NetworkManager/unstable/nmcli-examples.html[nmcli-examples].
2018-02-27 11:06:06 +00:00
[[notes]]
=== Notes
2018-02-27 11:21:06 +00:00
nmcli maybe contain some bugs and lack some features graphical tools for NetworkManager have.
2018-02-27 11:06:06 +00:00
To see all available options for your version of nmcli
2018-02-28 15:47:51 +00:00
[source,bash]
2018-02-27 11:06:06 +00:00
----
2018-02-28 17:13:43 +00:00
$ info nmcli
2018-02-27 11:06:06 +00:00
----
2017-10-26 21:20:01 +00:00
2018-02-28 15:47:51 +00:00
See a typo, something missing or out of date, or anything else which can be improved?
Edit this document at https://pagure.io/fedora-docs/quick-docs.