Product SiteDocumentation Site

2.4.2. Connecting to a Network Using nmcli

To list the currently available network connections, issue a command as follows:
~]$ nmcli con show
NAME               UUID                     TYPE            TIMESTAMP-REAL
eth0               4d5c449a-a6c5-451c-8206  802-3-ethernet  Tue 22 Oct 2013 19:50:00 BST
MyWiFi             91451385-4eb8-4080-8b82  802-11-wireless Tue 22 Oct 2013 08:50:08 BST
Bond connection 1  720aab83-28dd-4598-9325  bond            never
Note that the NAME field in the output always denotes the connection ID (name). It is not the interface name even though it might look the same. In the example above eth0 is the connection ID given by the user to the profile applied to the interface eth0. In the second line the user has assigned the connection ID MyWiFi to the interface wlan0.
Device status can also be viewed:
~]$ nmcli dev status
DEVICE      TYPE            STATE
wlan0      802-11-wireless  connected
bond0       bond            connecting (getting IP configuration)
eth0        ethernet        disconnected
lo          loopback        unmanaged

Adding an Ethernet Connection

To add an Ethernet connection with manual IP configuration, issue a command as follows:
~]$ nmcli con add con-name my-eth1 ifname eth1 type ethernet ip4 192.168.100.100/24 \
      gw4 192.168.100.1
Optionally, at the same time specify IPv6 addresses for the device as follows:
~]$ nmcli con add con-name my-eth1 ifname eth1 type ethernet ip4 192.168.100.100/24 \
 gw4 192.168.100.1 ip6 abbe::cafe gw6 2001:db8::1
To add two IPv4 DNS server addresses:
~]$ nmcli con mod my-eth1 ipv4.dns "8.8.8.8 8.8.4.4"
To add two IPv6 DNS server addresses:
~]$ nmcli con mod my-eth1 ipv6.dns "2001:4860:4860::8888 2001:4860:4860::8844"
To bring up the new connection, issue a command as follows:
~]$ nmcli -p con up "my-eth1" ifname eth1
To view detailed information about the newly configured connection, issue a command as follows:
~]$ nmcli -p con show configured my-eth1
To lock a profile to a specific interface, issue a command as follows:
~]$ nmcli connection add type ethernet con-name "my-eth1" ifname eth1
To make a profile usable for all compatible Ethernet interfaces, issue a command as follows:
~]$ nmcli connection add type ethernet con-name "my-eth1" ifname "*"
Note that you have to use the ifname argument even if you do not want to set a specific interface. Use the wildcard character * to specify that the profile can be used with any compatible device.
To lock a profile to a specific MAC address, issue a command as follows:
~]$ nmcli connection add type ethernet con-name "my-eth1" ifname "*" mac 00:00:5E:00:53:00

Adding a Wi-Fi Connection

To view the available Wi-Fi access points, issue a command as follows:
~]$ nmcli dev wifi list
  SSID            MODE  CHAN  RATE     SIGNAL  BARS  SECURITY
  FedoraTest     Infra  11    54 MB/s  98      ▂▄▆█  WPA1
  Red Hat Guest  Infra  6     54 MB/s  97      ▂▄▆█  WPA2       
  Red Hat        Infra  6     54 MB/s  77      ▂▄▆_  WPA2 802.1X
* Red Hat        Infra  40    54 MB/s  66      ▂▄▆_  WPA2 802.1X
  VoIP           Infra  1     54 MB/s  32      ▂▄__  WEP
  MyCafe         Infra  11    54 MB/s  39      ▂▄__  WPA2
To create a Wi-Fi connection profile with manual IP configuration, but allowing automatic DNS address assignment, issue a command as follows:
~]$ nmcli con add con-name MyCafe ifname wlan0 type wifi ssid MyCafe \
      p4 192.168.100.101/24 gw4 192.168.100.1
To set a WPA2 password, for example caffeine, issue commands as follows:
~]$ nmcli con modify MyCafe wifi-sec.key-mgmt wpa-psk
~]$ nmcli con modify MyCafe wifi-sec.psk caffeine
To change Wi-Fi state, issue a command in the following format:
~]$ nmcli radio wifi [on | off ]

Changing a Specific Property

To check a specific property, for example mtu, issue a command as follows:
~]$ nmcli connection show id 'MyCafe' | grep mtu
802-11-wireless.mtu:                     auto
To change the property of a setting, issue a command as follows:
~]$ nmcli connection modify id 'MyCafe' 802-11-wireless.mtu 1350
To verify the change, issue a command as follows:
~]$ nmcli connection show id 'MyCafe' | grep mtu
802-11-wireless.mtu:                     1350
Note that NetworkManager refers to parameters such as 802-3-ethernet and 802-11-wireless as the setting, and mtu as a property of the setting. See the nm-settings(5) man page for more information on properties and their settings.