1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
6 Copyright 2013 - 2014 Red Hat, Inc.
9 <refentry id="nmcli-examples">
11 <title>nmcli-examples</title>
12 <date>19 November 2014</date>
13 <author>NetworkManager developers</author>
17 <refentrytitle>nmcli-examples</refentrytitle>
18 <manvolnum>5</manvolnum>
19 <refmiscinfo class="source">NetworkManager</refmiscinfo>
20 <refmiscinfo class="manual">Examples</refmiscinfo>
21 <refmiscinfo class="version">1.2</refmiscinfo>
25 <refname>nmcli-examples</refname>
26 <refpurpose>usage examples of nmcli</refpurpose>
31 <command>nmcli <arg choice="opt" rep="repeat">OPTIONS</arg></command>
36 <title>Description</title>
38 <emphasis>nmcli</emphasis> is a command-line client for NetworkManager. It
39 allows controlling NetworkManager and reporting its status. For more information
40 please refer to <citerefentry><refentrytitle>nmcli</refentrytitle><manvolnum>1</manvolnum></citerefentry>
44 The purpose of this manual page is to provide you with various examples and
45 usage scenarios of <emphasis>nmcli</emphasis>.
47 <para>Note: this page has "work-in-progress" status.</para>
51 <title>Examples</title>
53 <example><title>Listing available Wi-Fi APs</title>
54 <synopsis><emphasis role="bold">
55 $ nmcli device wifi list
56 </emphasis></synopsis>
58 * SSID MODE CHAN RATE SIGNAL BARS SECURITY
59 netdatacomm_local Infra 6 54 Mbit/s 37 ▂▄__ WEP
60 * F1 Infra 11 54 Mbit/s 98 ▂▄▆█ WPA1
61 LoremCorp Infra 1 54 Mbit/s 62 ▂▄▆_ WPA2 802.1X
62 Internet Infra 6 54 Mbit/s 29 ▂___ WPA1
63 HPB110a.F2672A Ad-Hoc 6 54 Mbit/s 22 ▂___ --
64 Jozinet Infra 1 54 Mbit/s 19 ▂___ WEP
65 VOIP Infra 1 54 Mbit/s 20 ▂___ WEP
66 MARTINA Infra 4 54 Mbit/s 32 ▂▄__ WPA2
67 N24PU1 Infra 7 11 Mbit/s 22 ▂___ --
68 alfa Infra 1 54 Mbit/s 67 ▂▄▆_ WPA2
69 bertnet Infra 5 54 Mbit/s 20 ▂___ WPA1 WPA2
73 This command shows how to list available Wi-Fi networks (APs). You can also use
74 <emphasis>--fields</emphasis> option for displaying different columns.
75 <emphasis role="bold">nmcli -f all dev wifi list</emphasis> will show all of them.
78 <example><title>Showing general information and properties for a Wi-Fi interface</title>
79 <synopsis><emphasis role="bold">
80 $ nmcli -p -f general,wifi-properties device show wlan0
81 </emphasis></synopsis>
83 ===============================================================================
84 Device details (wlan0)
85 ===============================================================================
88 GENERAL.VENDOR: Intel Corporation
89 GENERAL.PRODUCT: PRO/Wireless 5100 AGN [Shiloh] Network Connection
90 GENERAL.DRIVER: iwlwifi
91 GENERAL.DRIVER-VERSION: 3.8.13-100.fc17.x86_64
92 GENERAL.FIRMWARE-VERSION: 8.83.5.1 build 33692
93 GENERAL.HWADDR: 00:1E:65:37:A1:D3
95 GENERAL.STATE: 100 (connected)
96 GENERAL.REASON: 0 (No reason given)
97 GENERAL.UDI: /sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/wlan0
98 GENERAL.IP-IFACE: wlan0
99 GENERAL.IS-SOFTWARE: no
100 GENERAL.NM-MANAGED: yes
101 GENERAL.AUTOCONNECT: yes
102 GENERAL.FIRMWARE-MISSING: no
103 GENERAL.CONNECTION: My Alfa WiFi
104 GENERAL.CON-UUID: 85194f4c-d496-4eec-bae0-d880b4cbcf26
105 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/10
106 -------------------------------------------------------------------------------
107 WIFI-PROPERTIES.WEP: yes
108 WIFI-PROPERTIES.WPA: yes
109 WIFI-PROPERTIES.WPA2: yes
110 WIFI-PROPERTIES.TKIP: yes
111 WIFI-PROPERTIES.CCMP: yes
112 WIFI-PROPERTIES.AP: no
113 WIFI-PROPERTIES.ADHOC: yes
114 -------------------------------------------------------------------------------
118 This command shows information about a Wi-Fi device.
121 <example><title>Listing NetworkManager polkit permissions</title>
122 <synopsis><emphasis role="bold">
123 $ nmcli general permissions
124 </emphasis></synopsis>
127 org.freedesktop.NetworkManager.enable-disable-network yes
128 org.freedesktop.NetworkManager.enable-disable-wifi yes
129 org.freedesktop.NetworkManager.enable-disable-wwan yes
130 org.freedesktop.NetworkManager.enable-disable-wimax yes
131 org.freedesktop.NetworkManager.sleep-wake no
132 org.freedesktop.NetworkManager.network-control yes
133 org.freedesktop.NetworkManager.wifi.share.protected yes
134 org.freedesktop.NetworkManager.wifi.share.open yes
135 org.freedesktop.NetworkManager.settings.modify.system yes
136 org.freedesktop.NetworkManager.settings.modify.own yes
137 org.freedesktop.NetworkManager.settings.modify.hostname auth
141 This command shows configured polkit permissions for various NetworkManager
142 operations. These permissions or actions (using polkit language) are configured
143 by a system administrator and are not meant to be changed by users. The usual
144 place for the polkit configuration is /usr/share/polkit-1/actions/org.freedesktop.NetworkManager.policy.
145 <emphasis>pkaction</emphasis> command can display description for polkit actions.
147 pkaction --action-id org.freedesktop.NetworkManager.network-control --verbose
148 </command></synopsis>
149 More information about polkit can be found at http://www.freedesktop.org/wiki/Software/polkit.
152 <example><title>Listing NetworkManager log level and domains</title>
153 <synopsis><emphasis role="bold">
154 $ nmcli general logging
155 </emphasis></synopsis>
158 INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,WIFI_SCAN,IP4,IP6,AUTOIP4,DNS,VPN,SHARING,SUPPLICANT,AGENTS,SETTINGS,SUSPEND,CORE,DEVICE,OLPC,WIMAX,INFINIBAND,FIREWALL,ADSL,BOND,VLAN,BRIDGE,DBUS_PROPS,TEAM,CONCHECK,DCB,DISPATCH
162 This command shows current NetworkManager logging status.
165 <example><title>Changing NetworkManager logging</title>
166 <synopsis><emphasis role="bold">
167 $ nmcli g log level DEBUG domains CORE,ETHER,IP
168 $ nmcli g log level INFO domains DEFAULT
169 </emphasis></synopsis>
172 The first command makes NetworkManager log in DEBUG level, and only for CORE, ETHER and
173 IP domains. The second command restores the default logging state. Please refer to the
174 <citerefentry><refentrytitle>NetworkManager.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> manual page
175 for available logging levels and domains.
178 <example><title>Adding a bonding master and two slave connection profiles</title>
179 <synopsis><emphasis role="bold">
180 $ nmcli con add type bond ifname mybond0 mode active-backup
181 $ nmcli con add type ethernet ifname eth1 master mybond0
182 $ nmcli con add type ethernet ifname eth2 master mybond0
183 </emphasis></synopsis>
186 This example demonstrates adding a bond master connection and two slaves. The
187 first command adds a master bond connection, naming the bonding interface
188 <emphasis>mybond0</emphasis> and using <emphasis>active-backup</emphasis> mode.
189 The next two commands add slaves connections, both enslaved to <emphasis>mybond0</emphasis>.
190 The first slave will be bound to <emphasis>eth1</emphasis> interface, the second to
191 <emphasis>eth2</emphasis>.
194 <example><title>Adding a team master and two slave connection profiles</title>
195 <synopsis><emphasis role="bold">
196 $ nmcli con add type team con-name Team1 ifname Team1 config team1-master-json.conf
197 $ nmcli con add type ethernet con-name Team1-slave1 ifname em1 master Team1
198 $ nmcli con add type ethernet con-name Team1-slave2 ifname em2 master Team1
199 </emphasis></synopsis>
202 This example demonstrates adding a team master connection profile and two slaves. It is
203 very similar to the bonding example. The first command adds a master team profile, naming
204 the team interface and the profile <emphasis>Team1</emphasis>. The team configuration
205 for the master is read from <emphasis>team1-master-json.conf</emphasis> file. Later, you can
206 change the configuration with <emphasis>modify</emphasis> command
207 (<emphasis role="bold">nmcli con modify Team1 team.config team1-master-another-json.conf</emphasis>).
208 The last two commands add slaves profiles, both enslaved to <emphasis>Team1</emphasis>.
209 The first slave will be bound to <emphasis>em1</emphasis> interface, the second to
210 <emphasis>em2</emphasis>. The slaves don't specify <emphasis>config</emphasis> and thus
211 <emphasis>teamd</emphasis> will use its default configuration. You will activate the whole setup
212 by activating both slaves:
213 <synopsis><emphasis role="bold">
214 $ nmcli con up Team1-slave1
215 $ nmcli con up Team1-slave2
216 </emphasis></synopsis>
217 By default, the created profiles are marked for auto-activation. But if another
218 connection has been activated on the device, the new profile won't activate
219 automatically and you need to activate it manually.
222 <example><title>Adding a bridge and two slave profiles</title>
223 <synopsis><emphasis role="bold">
224 $ nmcli con add type bridge con-name TowerBridge ifname TowerBridge
225 $ nmcli con add type ethernet con-name br-slave-1 ifname ens3 master TowerBridge
226 $ nmcli con add type ethernet con-name br-slave-2 ifname ens4 master TowerBridge
227 $ nmcli con modify TowerBridge bridge.stp no
228 </emphasis></synopsis>
231 This example demonstrates adding a bridge master connection and two slaves. The
232 first command adds a master bridge connection, naming the bridge interface and
233 the profile as <emphasis>TowerBridge</emphasis>.
234 The next two commands add slaves profiles, both will be enslaved to
235 <emphasis>TowerBridge</emphasis>.
236 The first slave will be tied to <emphasis>ens3</emphasis> interface, the second to
237 <emphasis>ens4</emphasis>.
238 The last command will disable 802.1D STP for the TowerBridge profile.
241 <example><title>Adding an ethernet connection profile with manual IP configuration</title>
243 <emphasis role="bold">
244 $ nmcli con add con-name my-con-em1 ifname em1 type ethernet ip4 192.168.100.100/24 gw4 192.168.100.1 ip4 1.2.3.4 ip6 abbe::cafe
245 $ nmcli con mod my-con-em1 ipv4.dns "8.8.8.8 8.8.4.4"
246 $ nmcli con mod my-con-em1 +ipv4.dns 1.2.3.4
247 $ nmcli con mod my-con-em1 ipv6.dns "2001:4860:4860::8888 2001:4860:4860::8844"
248 $ nmcli -p con show my-con-em1
253 The first command adds an Ethernet connection profile named <emphasis>my-con-em1</emphasis>
254 that is bound to interface name <emphasis>em1</emphasis>. The profile is configured
255 with static IP addresses. Three addresses are added, two IPv4 addresses and one IPv6.
256 The first IP 192.168.100.100 has a prefix of 24 (netmask equivalent of 255.255.255.0).
257 Gateway entry will become the default route if this profile is activated on em1 interface
258 (and there is no connection with higher priority). The next two addresses do not
259 specify a prefix, so a default prefix will be used, i.e. 32 for IPv4 and 128 for IPv6.
260 The second, third and fourth commands modify DNS parameters of the new connection profile.
261 The last <emphasis>con show</emphasis> command displays the profile so that all
262 parameters can be reviewed.
265 <example><title>Escaping colon characters in tabular mode</title>
267 <emphasis role="bold">
268 $ nmcli -t -f general -e yes -m tab dev show eth0
272 GENERAL:eth0:ethernet:Intel Corporation:82567LM Gigabit Network Connection:e1000e:2.1.4-k:1.8-3:00\:22\:68\:15\:29\:21:1500:100 (connected):0 (No reason given):/sys/devices/pci0000\:00/0000\:00\:19.0/net/eth0:eth0:yes:yes:no:ethernet-13:89cbcbc6-dc85-456c-9c8b-bd828fee3917:/org/freedesktop/NetworkManager/ActiveConnection/9
276 This example shows escaping colon characters in tabular mode. It may be
277 useful for script processing, because ':' is used as a field separator.
280 <example><title>nmcli usage in a NetworkManager dispatcher script to make Ethernet and Wi-Fi mutually exclusive</title>
285 enable_disable_wifi ()
287 result=$(nmcli dev | grep "ethernet" | grep -w "connected")
288 if [ -n "$result" ]; then
295 if [ "$2" = "up" ]; then
299 if [ "$2" = "down" ]; then
305 This dispatcher script makes Wi-Fi mutually exclusive with wired
306 networking. When a wired interface is connected, Wi-Fi will be set
307 to airplane mode (rfkilled). When the wired interface is disconnected,
308 Wi-Fi will be turned back on.
309 Name this script e.g. 70-wifi-wired-exclusive.sh and put it into /etc/NetworkManager/dispatcher.d/
311 See <citerefentry><refentrytitle>NetworkManager</refentrytitle><manvolnum>8</manvolnum></citerefentry>
312 manual page for more information about NetworkManager dispatcher scripts.
316 <para><emphasis role="bold">Example sessions of interactive connection editor</emphasis></para>
318 <example><title>Adding an ethernet connection profile in interactive editor (a)</title>
320 <emphasis role="bold">
321 $ nmcli connection edit type ethernet
326 ===| nmcli interactive connection editor |===
328 Adding a new '802-3-ethernet' connection
330 Type 'help' or '?' for available commands.
331 Type 'describe [<setting>.<prop>]' for detailed property description.
333 You may edit the following settings: connection, 802-3-ethernet (ethernet), 802-1x, ipv4, ipv6, dcb
335 ===============================================================================
337 ===============================================================================
338 connection.id: ethernet-4
339 connection.uuid: de89cdeb-a3e1-4d53-8fa0-c22546c775f4
340 connection.interface-name: --
341 connection.type: 802-3-ethernet
342 connection.autoconnect: yes
343 connection.autoconnect-priority: 0
344 connection.timestamp: 0
345 connection.read-only: no
346 connection.permissions:
348 connection.master: --
349 connection.slave-type: --
350 connection.secondaries:
351 connection.gateway-ping-timeout: 0
352 -------------------------------------------------------------------------------
353 802-3-ethernet.port: --
354 802-3-ethernet.speed: 0
355 802-3-ethernet.duplex: --
356 802-3-ethernet.auto-negotiate: yes
357 802-3-ethernet.mac-address: --
358 802-3-ethernet.cloned-mac-address: --
359 802-3-ethernet.mac-address-blacklist:
360 802-3-ethernet.mtu: auto
361 802-3-ethernet.s390-subchannels:
362 802-3-ethernet.s390-nettype: --
363 802-3-ethernet.s390-options:
364 -------------------------------------------------------------------------------
371 ipv4.route-metric: -1
372 ipv4.ignore-auto-routes: no
373 ipv4.ignore-auto-dns: no
374 ipv4.dhcp-client-id: --
375 ipv4.dhcp-send-hostname: yes
376 ipv4.dhcp-hostname: --
377 ipv4.never-default: no
379 -------------------------------------------------------------------------------
386 ipv6.route-metric: -1
387 ipv6.ignore-auto-routes: no
388 ipv6.ignore-auto-dns: no
389 ipv6.never-default: no
391 ipv6.ip6-privacy: -1 (unknown)
392 ipv6.dhcp-hostname: --
393 -------------------------------------------------------------------------------
395 You may edit the following properties: port, speed, duplex, auto-negotiate, mac-address, cloned-mac-address, mac-address-blacklist, mtu, s390-subchannels, s390-nettype, s390-options
396 nmcli 802-3-ethernet> set mtu 1492
397 nmcli 802-3-ethernet> b
398 nmcli> goto ipv4.addresses
399 nmcli ipv4.addresses> desc
402 [NM property description]
403 Array of IP addresses.
405 [nmcli specific description]
406 Enter a list of IPv4 addresses formatted as:
407 ip[/prefix], ip[/prefix],...
408 Missing prefix is regarded as prefix of 32.
410 Example: 192.168.1.5/24, 10.0.0.11/24
412 nmcli ipv4.addresses> set 192.168.1.100/24
413 Do you also want to set 'ipv4.method' to 'manual'? [yes]: yes
414 nmcli ipv4.addresses>
415 nmcli ipv4.addresses> print
416 addresses: 192.168.1.100/24
417 nmcli ipv4.addresses> back
419 nmcli> set ipv4.gateway 192.168.1.1
421 Verify connection: OK
423 ===============================================================================
425 ===============================================================================
426 connection.id: ethernet-4
427 connection.uuid: de89cdeb-a3e1-4d53-8fa0-c22546c775f4
428 connection.interface-name: --
429 connection.type: 802-3-ethernet
430 connection.autoconnect: yes
431 connection.autoconnect-priority: 0
432 connection.timestamp: 0
433 connection.read-only: no
434 connection.permissions:
436 connection.master: --
437 connection.slave-type: --
438 connection.secondaries:
439 connection.gateway-ping-timeout: 0
440 -------------------------------------------------------------------------------
441 802-3-ethernet.port: --
442 802-3-ethernet.speed: 0
443 802-3-ethernet.duplex: --
444 802-3-ethernet.auto-negotiate: yes
445 802-3-ethernet.mac-address: --
446 802-3-ethernet.cloned-mac-address: --
447 802-3-ethernet.mac-address-blacklist:
448 802-3-ethernet.mtu: 1492
449 802-3-ethernet.s390-subchannels:
450 802-3-ethernet.s390-nettype: --
451 802-3-ethernet.s390-options:
452 -------------------------------------------------------------------------------
456 ipv4.addresses: 192.168.1.100/24
457 ipv4.gateway: 192.168.1.1
459 ipv4.route-metric: -1
460 ipv4.ignore-auto-routes: no
461 ipv4.ignore-auto-dns: no
462 ipv4.dhcp-client-id: --
463 ipv4.dhcp-send-hostname: yes
464 ipv4.dhcp-hostname: --
465 ipv4.never-default: no
467 -------------------------------------------------------------------------------
473 ipv6.route-metric: -1
474 ipv6.ignore-auto-routes: no
475 ipv6.ignore-auto-dns: no
476 ipv6.never-default: no
478 ipv6.ip6-privacy: -1 (unknown)
479 ipv6.dhcp-hostname: --
480 -------------------------------------------------------------------------------
481 nmcli> set ipv4.dns 8.8.8.8 8.8.4.4
483 ===============================================================================
485 ===============================================================================
486 connection.id: ethernet-4
487 connection.uuid: de89cdeb-a3e1-4d53-8fa0-c22546c775f4
488 connection.interface-name: --
489 connection.type: 802-3-ethernet
490 connection.autoconnect: yes
491 connection.autoconnect-priority: 0
492 connection.timestamp: 0
493 connection.read-only: no
494 connection.permissions:
496 connection.master: --
497 connection.slave-type: --
498 connection.secondaries:
499 connection.gateway-ping-timeout: 0
500 -------------------------------------------------------------------------------
501 802-3-ethernet.port: --
502 802-3-ethernet.speed: 0
503 802-3-ethernet.duplex: --
504 802-3-ethernet.auto-negotiate: yes
505 802-3-ethernet.mac-address: --
506 802-3-ethernet.cloned-mac-address: --
507 802-3-ethernet.mac-address-blacklist:
508 802-3-ethernet.mtu: 1492
509 802-3-ethernet.s390-subchannels:
510 802-3-ethernet.s390-nettype: --
511 802-3-ethernet.s390-options:
512 -------------------------------------------------------------------------------
514 ipv4.dns: 8.8.8.8,8.8.4.4
516 ipv4.addresses: 192.168.1.100/24
517 ipv4.gateway: 192.168.1.1
519 ipv4.route-metric: -1
520 ipv4.ignore-auto-routes: no
521 ipv4.ignore-auto-dns: no
522 ipv4.dhcp-client-id: --
523 ipv4.dhcp-send-hostname: yes
524 ipv4.dhcp-hostname: --
525 ipv4.never-default: no
527 -------------------------------------------------------------------------------
534 ipv6.route-metric: -1
535 ipv6.ignore-auto-routes: no
536 ipv6.ignore-auto-dns: no
537 ipv6.never-default: no
539 ipv6.ip6-privacy: -1 (unknown)
540 ipv6.dhcp-hostname: --
541 -------------------------------------------------------------------------------
543 Verify connection: OK
545 Connection 'ethernet-4' (de89cdeb-a3e1-4d53-8fa0-c22546c775f4) successfully saved.
550 Example session in the nmcli interactive connection editor.
551 The scenario creates an Ethernet connection profile with static addressing (IPs and DNS).
557 <title>See Also</title>
559 <citerefentry><refentrytitle>nmcli</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
560 <citerefentry><refentrytitle>NetworkManager</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
561 <citerefentry><refentrytitle>NetworkManager.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
562 <citerefentry><refentrytitle>nm-settings</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
563 <citerefentry><refentrytitle>nm-online</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
564 <citerefentry><refentrytitle>nm-applet</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
565 <citerefentry><refentrytitle>nm-connection-editor</refentrytitle><manvolnum>1</manvolnum></citerefentry>