You are on page 1of 5

26/8/23, 18:13 RH124 - ch11s05

Configure Networking from the Command Line


Objectives
Manage network settings and devices with the nmcli command.

Describe the NetworkManager Service


The NetworkManager service monitors and manages a system's network settings. In the GNOME graphical environment, a Notification Area applet
displays network configuration and status information that is received from the NetworkManager daemon. You can interact with
the NetworkManager service via the command line or with graphical tools. Service configuration files are stored in the /etc/NetworkManager/system-
connections/ directory.

The NetworkManager service manages network devices and connections. A device is a physical or virtual network interface that provides for network
traffic. A connection has related configuration settings for a single network device. A connection can also be known as a network profile. Each
connection must have a unique name or ID, which can match the device name that it configures.

A single device can have multiple connection configurations and switch between them, but only one connection can be active per device. For example,
a laptop wireless device might configure a fixed IP address for use at a secure work site in a connection, but might configure a second connection with
an automated address and a virtual private network (VPN) to access the same company network from home.

Important
Starting in Red Hat Enterprise Linux 8, ifcfg format configuration files and the /etc/sysconfig/network-scripts/ directory are
deprecated. NetworkManager now uses an INI-style key file format, which is a key-value pair structure to organize properties.
NetworkManager stores network profiles in the /etc/NetworkManager/system-connections/ directory. For compatibility with earlier
versions, ifcfg format connections in the /etc/sysconfig/network-scripts/ directory are still recognized and loaded.

View Network Information


Use the nmcli utility to create and edit connection files from the command line. The nmcli device status command displays the status of all network
devices:

[user@host ~]$ nmcli dev status


DEVICE TYPE STATE CONNECTION
eno1 ethernet connected eno1
ens3 ethernet connected static-ens3
eno2 ethernet disconnected --
lo loopback unmanaged --
https://rha.ole.redhat.com/rha/app/courses/rh124-9.0/pages/ch11s05/85223ae4-a208-4a0c-8807-f8580dad018f 1/5
26/8/23, 18:13 RH124 - ch11s05

[root@host ~]# nmcli con add con-name eno4 type ethernet ifname eno4 \
ipv6.addresses 2001:db8:0:1::c000:207/64 ipv6.gateway 2001:db8:0:1::1 \
ipv6.method manual ipv4.addresses 192.0.2.7/24 ipv4.gateway 192.0.2.1 \
ipv4.method manual

Manage Network Connections


The nmcli connection up command activates a network connection on the device that it is bound to. Activating a network connection requires the
connection name, not the device name.

[user@host ~]$ nmcli con show


NAME UUID TYPE DEVICE
static-ens3 72ca57a2-f780-40da-b146-99f71c431e2b 802-3-ethernet --
static-ens5 87b53c56-1f5d-4a29-a869-8a7bdaf56dfa 802-3-ethernet --
[root@host ~]# nmcli con up static-ens3
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)

The nmcli device disconnect command disconnects the network device and brings down the connection.

[root@host ~]# nmcli dev disconnect ens3

Important
Use nmcli device disconnect to stop traffic on a network interface and deactivate the connection.

Because most connections enable the autoconnect parameter, the nmcli connection down command is ineffective for stopping traffic.
Although the connection deactivates, autoconnect immediately reactivates the connection if the device is up and available. Autoconnect is
a desired behavior, because it maintains connections through temporary network outages.

By disconnecting the device under the connection, the connection is forced to be down until the device is connected again.

Update Network Connection Settings


NetworkManager service connections have two setting types. Static connection properties are configured by the administrator and stored in
the /etc/NetworkManager/system-connections/*.nmconnection configuration files. Dynamic connection properties are requested from a DHCP
server and are not stored persistently.

To list the current settings for a connection, use the nmcli connection show command. Settings in lowercase are static properties that the
https://rha.ole.redhat.com/rha/app/courses/rh124-9.0/pages/ch11s05/85223ae4-a208-4a0c-8807-f8580dad018f 2/5
administrator can change. Settings in uppercase are active settings in temporary use for this connection instance.
26/8/23, 18:13 RH124 - ch11s05

[root@host ~]# nmcli con show static-ens3


connection.id: static-ens3
connection.uuid: 87b53c56-1f5d-4a29-a869-8a7bdaf56dfa
connection.interface-name: --
connection.type: 802-3-ethernet
connection.autoconnect: yes
connection.timestamp: 1401803453
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: CA:9D:E9:2A:CE:F0
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: manual
ipv4.dns: 192.168.0.254
ipv4.dns-search: example.com
ipv4.addresses: { ip = 192.168.0.2/24,
gw = 192.168.0.254 }
ipv4.routes:
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: manual
ipv6.dns: 2001:4860:4860::8888
https://rha.ole.redhat.com/rha/app/courses/rh124-9.0/pages/ch11s05/85223ae4-a208-4a0c-8807-f8580dad018f 3/5
ipv6.dns-search: example.com
26/8/23, 18:13 RH124 - ch11s05

then load the final configuration when ready. The following example loads all connection profiles.

[root@host ~]# nmcli con reload

The next example loads only the eno2 connection profile at /etc/NetworkManager/system-connections/eno2.nmconnection.

[root@host ~]# nmcli con reload eno2

Delete a Network Connection


The nmcli connection delete command deletes a connection from the system. This command disconnects the device and removes the connection
configuration file.

[root@host ~]# nmcli con del static-ens3

Permissions to Modify NetworkManager Settings


The root user can use the nmcli command to change the network configuration.

Non-privileged users that are logged in on the physical or virtual console can also make most network configuration changes. If a person is on the
system's console, then the system is likely being used as a workstation or laptop where the user needs to configure, activate, and deactivate
connections. Non-privileged users that log in with ssh must switch to the root user to change network settings.

Use the nmcli general permissions command to view your current permissions. The following example lists the root user's NetworkManager
permissions.

[root@host ~]# nmcli gen permissions


PERMISSION VALUE
org.freedesktop.NetworkManager.checkpoint-rollback yes
org.freedesktop.NetworkManager.enable-disable-connectivity-check yes
org.freedesktop.NetworkManager.enable-disable-network yes
org.freedesktop.NetworkManager.enable-disable-statistics yes
org.freedesktop.NetworkManager.enable-disable-wifi yes
org.freedesktop.NetworkManager.enable-disable-wimax yes
org.freedesktop.NetworkManager.enable-disable-wwan yes
org.freedesktop.NetworkManager.network-control yes
org.freedesktop.NetworkManager.reload yes
org.freedesktop.NetworkManager.settings.modify.global-dns yes
https://rha.ole.redhat.com/rha/app/courses/rh124-9.0/pages/ch11s05/85223ae4-a208-4a0c-8807-f8580dad018f 4/5
org.freedesktop.NetworkManager.settings.modify.hostname yes
26/8/23, 18:13 RH124 - ch11s05

Command Purpose
nmcli con mod name Modify the connection name.
nmcli con reload Reload the configuration files, after manual file editing.
nmcli con up name Activate the connection name.
nmcli dev dis dev Disconnect the interface, which also deactivates the current connection.
nmcli con del name Delete the specified connection and its configuration file.

 
References
For more information, refer to the Getting Started with nmcli chapter at https://access.redhat.com/documentation/en-
us/red_hat_enterprise_linux/9/html-single/configuring_and_managing_networking/index#getting-started-with-nmcli_configuring-and-managing-
networking

NetworkManager(8), nmcli(1), nmcli-examples(5), nm-settings(5), hostnamectl(1), resolv.conf(5), hostname(5), ip(8), and ip-address(8) man


pages

https://rha.ole.redhat.com/rha/app/courses/rh124-9.0/pages/ch11s05/85223ae4-a208-4a0c-8807-f8580dad018f 5/5

You might also like