Software >> OS >> Unix >> Linux >> RHEL >> 7 >>  Examples of nmcli command

 

 Example 1. Listing available Wi-Fi APs
 $ nmcli device wifi list

 

 Example 2. Showing general information and properties for a Wi-Fi interface
$ nmcli -p -f general,wifi-properties device show wlan0

 

 Example 3. Listing NetworkManager polkit permissions
$ nmcli general permissions

 

Example 4. Listing NetworkManager log level and domains
$ nmcli general logging

 

 Example 5. Changing NetworkManager logging
$ nmcli g log level DEBUG domains CORE,ETHER,IP
$ nmcli g log level INFO domains DEFAULT

 

Example 6. Adding a bonding master and two slave connection profiles
$ nmcli con add type bond ifname mybond0 mode active-backup
$ nmcli con add type ethernet ifname eth1 master mybond0
$ nmcli con add type ethernet ifname eth2 master mybond0

 

Example 7. Adding a team master and two slave connection profiles

$ nmcli con add type team con-name Team1 ifname Team1 config team1-master-json.conf
$ nmcli con add type ethernet con-name Team1-slave1 ifname em1 master Team1
$ nmcli con add type ethernet con-name Team1-slave2 ifname em2 master Team1

Activate the whole setup by activating both slaves:

  $ nmcli con up Team1-slave1
  $ nmcli con up Team1-slave2

 

 Example 8. Adding a bridge and two slave profiles
$ nmcli con add type bridge con-name TowerBridge ifname TowerBridge
$ nmcli con add type ethernet con-name br-slave-1 ifname ens3 master TowerBridge
$ nmcli con add type ethernet con-name br-slave-2 ifname ens4 master TowerBridge
$ nmcli con modify TowerBridge bridge.stp no

 

Example 9. Adding an ethernet connection profile with manual IP configuration
$ 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

$ nmcli con mod my-con-em1 ipv4.dns "8.8.8.8 8.8.4.4"
$ nmcli con mod my-con-em1 +ipv4.dns 1.2.3.4
$ nmcli con mod my-con-em1 ipv6.dns "2001:4860:4860::8888 2001:4860:4860::8844"
$ nmcli -p con show my-con-em1

 

Example 10. Escaping colon characters in tabular mode
$ nmcli -t -f general -e yes -m tab dev show eth0
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 reas
on 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

 

 

Example 11. nmcli usage in a NetworkManager dispatcher script to make Ethernet and Wi-Fi mutually exclusive
#!/bin/bash
export LC_ALL=C

enable_disable_wifi ()
{
    result=$(nmcli dev | grep "ethernet" | grep -w "connected")
    if [ -n "$result" ]; then
        nmcli radio wifi off
    else
        nmcli radio wifi on
    fi
}

if [ "" = "up" ]; then
    enable_disable_wifi
fi

if [ "" = "down" ]; then
    enable_disable_wifi
fi
     

 

Example 12. Adding an ethernet connection profile in interactive editor (a)
$ nmcli connection edit type ethernet

===| 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, dcb
nmcli> print
===========================================================================
                          Connection details
===========================================================================

connection.id:                      ethernet-4
connection.uuid:                    de89cdeb-a3e1-4d53-8fa0-c22546c775f4
connection.interface-name:          --
connection.type:                    802-3-ethernet
connection.autoconnect:             yes
connection.autoconnect-priority:    0
connection.timestamp:               0
connection.read-only:               no
connection.permissions:
connection.zone:                    --
connection.master:                  --
connection.slave-type:              --
connection.secondaries:
connection.gateway-ping-timeout:    0
---------------------------------------------------------------------------
802-3-ethernet.port:                --
802-3-ethernet.speed:               0
802-3-ethernet.duplex:              --
802-3-ethernet.auto-negotiate:      yes
802-3-ethernet.mac-address:         --
802-3-ethernet.cloned-mac-address:  --
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu:                 auto
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype:        --
802-3-ethernet.s390-options:
---------------------------------------------------------------------------

ipv4.method:                        auto
ipv4.dns:
ipv4.dns-search:
ipv4.addresses:
ipv4.gateway:                       --
ipv4.routes:
ipv4.route-metric:                  -1
ipv4.ignore-auto-routes:            no
ipv4.ignore-auto-dns:               no
ipv4.dhcp-client-id:                --
ipv4.dhcp-send-hostname:            yes
ipv4.dhcp-hostname:                 --
ipv4.never-default:                 no
ipv4.may-fail:                      yes
---------------------------------------------------------------------------
ipv6.method:                        auto
ipv6.dns:
ipv6.dns-search:
ipv6.addresses:
ipv6.gateway:                       --
ipv6.routes:
ipv6.route-metric:                  -1
ipv6.ignore-auto-routes:            no
ipv6.ignore-auto-dns:               no
ipv6.never-default:                 no
ipv6.may-fail:                      yes
ipv6.ip6-privacy:                   -1 (unknown)
ipv6.dhcp-hostname:                 --
---------------------------------------------------------------------------

nmcli> goto ethernet
You may edit the following properties: port, speed, duplex, auto-negotiate,
 mac-address, cloned-mac-address, mac-address-blacklist, mtu, s390-subchann
els, s390-nettype, s390-options
nmcli 802-3-ethernet> set mtu 1492
nmcli 802-3-ethernet> b
nmcli> goto ipv4.addresses
nmcli ipv4.addresses> desc

=== [addresses] ===
[NM property description]
Array of IP addresses.

[nmcli specific description]
Enter a list of IPv4 addresses formatted as:
  ip[/prefix], ip[/prefix],...
Missing prefix is regarded as prefix of 32.

Example: 192.168.1.5/24, 10.0.0.11/24

nmcli ipv4.addresses> set 192.168.1.100/24
Do you also want to set 'ipv4.method' to 'manual'? [yes]: yes
nmcli ipv4.addresses>
nmcli ipv4.addresses> print
addresses: 192.168.1.100/24
nmcli ipv4.addresses> back
nmcli ipv4> b
nmcli> set ipv4.gateway 192.168.1.1
nmcli> verify
Verify connection: OK
nmcli> print

===========================================================================
                          Connection details
===========================================================================
connection.id:                      ethernet-4
connection.uuid:                    de89cdeb-a3e1-4d53-8fa0-c22546c775f4
connection.interface-name:          --
connection.type:                    802-3-ethernet
connection.autoconnect:             yes
connection.autoconnect-priority:    0
connection.timestamp:               0
connection.read-only:               no
connection.permissions:
connection.zone:                    --
connection.master:                  --
connection.slave-type:              --
connection.secondaries:
connection.gateway-ping-timeout:    0
---------------------------------------------------------------------------
802-3-ethernet.port:                --
802-3-ethernet.speed:               0
802-3-ethernet.duplex:              --
802-3-ethernet.auto-negotiate:      yes
802-3-ethernet.mac-address:         --
802-3-ethernet.cloned-mac-address:  --
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu:                 1492
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype:        --
802-3-ethernet.s390-options:

---------------------------------------------------------------------------
ipv4.method:                        manual
ipv4.dns:
ipv4.dns-search:
ipv4.addresses:                     192.168.1.100/24
ipv4.gateway:                       192.168.1.1
ipv4.routes:
ipv4.route-metric:                  -1
ipv4.ignore-auto-routes:            no
ipv4.ignore-auto-dns:               no
ipv4.dhcp-client-id:                --
ipv4.dhcp-send-hostname:            yes
ipv4.dhcp-hostname:                 --
ipv4.never-default:                 no
ipv4.may-fail:                      yes
---------------------------------------------------------------------------
ipv6.method:                        auto
ipv6.dns:
ipv6.dns-search:
ipv6.addresses:
ipv6.routes:
ipv6.route-metric:                  -1
ipv6.ignore-auto-routes:            no
ipv6.ignore-auto-dns:               no
ipv6.never-default:                 no
ipv6.may-fail:                      yes
ipv6.ip6-privacy:                   -1 (unknown)
ipv6.dhcp-hostname:                 --
---------------------------------------------------------------------------
nmcli> set ipv4.dns 8.8.8.8 8.8.4.4
nmcli> print
===========================================================================
                          Connection details
===========================================================================
connection.id:                      ethernet-4
connection.uuid:                    de89cdeb-a3e1-4d53-8fa0-c22546c775f4
connection.interface-name:          --
connection.type:                    802-3-ethernet
connection.autoconnect:             yes
connection.autoconnect-priority:    0
connection.timestamp:               0
connection.read-only:               no
connection.permissions:
connection.zone:                    --
connection.master:                  --
connection.slave-type:              --
connection.secondaries:
connection.gateway-ping-timeout:    0
---------------------------------------------------------------------------
802-3-ethernet.port:                --
802-3-ethernet.speed:               0
802-3-ethernet.duplex:              --
802-3-ethernet.auto-negotiate:      yes
802-3-ethernet.mac-address:         --
802-3-ethernet.cloned-mac-address:  --
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu:                 1492
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype:        --
802-3-ethernet.s390-options:
---------------------------------------------------------------------------
ipv4.method:                        manual
ipv4.dns:                           8.8.8.8,8.8.4.4
ipv4.dns-search:
ipv4.addresses:                     192.168.1.100/24
ipv4.gateway:                       192.168.1.1
ipv4.routes:
ipv4.route-metric:                  -1
ipv4.ignore-auto-routes:            no
ipv4.ignore-auto-dns:               no
ipv4.dhcp-client-id:                --
ipv4.dhcp-send-hostname:            yes
ipv4.dhcp-hostname:                 --
ipv4.never-default:                 no
ipv4.may-fail:                      yes
---------------------------------------------------------------------------

ipv6.method:                        auto
ipv6.dns:
ipv6.dns-search:
ipv6.addresses:
ipv6.gateway:                       --
ipv6.routes:
ipv6.route-metric:                  -1
ipv6.ignore-auto-routes:            no
ipv6.ignore-auto-dns:               no
ipv6.never-default:                 no
ipv6.may-fail:                      yes
ipv6.ip6-privacy:                   -1 (unknown)
ipv6.dhcp-hostname:                 --
---------------------------------------------------------------------------
nmcli> verify
Verify connection: OK
nmcli> save
Connection 'ethernet-4' (de89cdeb-a3e1-4d53-8fa0-c22546c775f4) successfully
 saved.
nmcli> quit

 

Example 13. Activating a connection that is not under Network Manager control

 

# we have 3 enp0s* interfaces in the server
[root@rhel7server1 ~]# ifconfig | grep ^enp
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
enp0s9: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

# only enp0s9 is currently activated in Network Manager
[root@rhel7server1 ~]# nmcli con show | egrep 'NAME|enp0'
NAME    UUID                                  TYPE            DEVICE
enp0s9  f649e5db-80c5-4934-95a5-b0700ed5b337  802-3-ethernet  enp0s9
enp0s3  4ef6ad54-81dd-4f6a-bd0c-548060dfd841  802-3-ethernet  --    
enp0s8  8feb3cca-9a2f-413a-8c91-efa332a604b8  802-3-ethernet  --    

# activate it
[root@rhel7server1 ~]# nmcli con up enp0s3
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/16)

# assuming we have DHCP to assign IP and the IPv4.method is manual

[root@rhel7server1 ~]# nmcli con show | egrep 'NAME|enp0'
NAME    UUID                                  TYPE            DEVICE
enp0s3  4ef6ad54-81dd-4f6a-bd0c-548060dfd841  802-3-ethernet  enp0s3
enp0s9  f649e5db-80c5-4934-95a5-b0700ed5b337  802-3-ethernet  enp0s9

enp0s8  8feb3cca-9a2f-413a-8c91-efa332a604b8  802-3-ethernet  --