Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 69

How to configure and Manage Network Connections using nmcli

NetworkManager includes a command-line tool, nmcli, which is used to control


NetworkManager. You can use nmcli to create, display, edit, delete, activate, and
deactivate network connections, as well as control and display network device status.
The syntax is:

# nmlci OPTIONS OBJECT { COMMAND | help }

There are five different objects on which most of the operations are performed using
nmcli command:
1. general
2. networking
3. radio
4. connection
5. device.

Use the help argument to display the options and information about the five different
objects:

Use the help argument to display the options and information about the five different
objects:

# nmcli --help
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }

OPTIONS
-t[erse] terse output
-p[retty] pretty output
-m[ode] tabular|multiline output mode
-c[olors] auto|yes|no whether to use colors in
output
-f[ields] [field1,field2,...]|all|common specify fields to output
-e[scape] yes|no escape columns separators in
values
-a[sk] ask for missing parameters
-s[how-secrets] allow displaying passwords
-w[ait] [seconds> set timeout waiting for
finishing operations
-v[ersion] show program version
-h[elp] print this help

OBJECT
g[eneral] NetworkManager's general status and operations
n[etworking] overall networking control
r[adio] NetworkManager radio switches
c[onnection] NetworkManager's connections
d[evice] devices managed by NetworkManager
a[gent] NetworkManager secret agent or polkit agent
m[onitor] monitor NetworkManager changes

The ‘nmcli general’ sub-command

Use the nmcli general object to show NetworkManager status and permissions. This
command also allows you view and change the system hostname and the
NetworkManager logging level. The following command provides help on the nmcli
general object:

# nmcli general help


Usage: nmcli general { COMMAND | help }

COMMAND := { status | hostname | permissions | logging }

status

hostname [[hostname]]

permissions

logging [level [log level]] [domains [log domains]]


Some examples of using this command follow.
Example 1 : Overall status of NetworkManager

Use the following command to display the overall status of NetworkManager. The
status argument is the default and can be omitted.

# nmcli general status


STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
connected full enabled enabled enabled enabled
Example 2 : Changing the hostname

The hostname argument is used to display or change the system hostname. The
hostname is stored in the /etc/hostname file. The following example changes the
hostname to geeklab.example.com and updates the /etc/hostname file:

# nmcli general hostname geeklab.example.com


Example 3 : View permissions a caller has for various operations

The permissions argument shows the permissions a caller has for the various
authenticated operations that NetworkManager provides. The following example
shows permissions for enabling and disabling networking, changing Wi-Fi and
WWAN state, modifying connections, and other operations:

# nmcli general permissions


PERMISSION VALUE
org.freedesktop.NetworkManager.enable-disable-network yes
org.freedesktop.NetworkManager.enable-disable-wifi yes
org.freedesktop.NetworkManager.enable-disable-wwan yes
org.freedesktop.NetworkManager.enable-disable-wimax yes
org.freedesktop.NetworkManager.sleep-wake yes
org.freedesktop.NetworkManager.network-control yes
org.freedesktop.NetworkManager.wifi.share.protected yes
org.freedesktop.NetworkManager.wifi.share.open yes
org.freedesktop.NetworkManager.settings.modify.system yes
org.freedesktop.NetworkManager.settings.modify.own yes
org.freedesktop.NetworkManager.settings.modify.hostname yes
org.freedesktop.NetworkManager.settings.modify.global-dns yes
org.freedesktop.NetworkManager.reload yes
org.freedesktop.NetworkManager.checkpoint-rollback yes
org.freedesktop.NetworkManager.enable-disable-statistics yes
Example 4 : Change NetworkManager logging level

The logging argument is used to get and change NetworkManager logging level for
domains. Without any argument, the current logging level and domains are shown as
follows:

# nmcli general logging


LEVEL DOMAINS

INFO
PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6,AUTOIP4,DNS,VPN,S
HARING,SUPPLICANT,AGENTS,SETTINGS,SUSPEND,CORE,DEVICE,OLPC,INFINIBAND,FIRE
WALL
,ADSL,BOND,VLAN,BRIDGE,TEAM,CONCHECK,DCB,DISPATCH,AUDIT,SYSTEMD,PROXY

To change logging state, provide the level and/or domain parameters using the
following syntax:

# nmcli general logging [level [log level]] [domains [log domains]]


The logging level can be one of the following (listed in order of verbosity):

Log Description
Level

ERR Logs only critical errors

WARN Logs warnings that might reflect operation

INFO Logs various informational messages that are useful for tracking
state and operations

DEBUG Enables verbose logging for debugging purposes


The following example sets the logging level to DEBUG for the IPv4 domain:

# nmcli general logging level DEBUG domains IP4


The following example sets the logging level to INFO for all domains:

# nmcli general logging level INFO domains ALL


For information on configuring NetworkManager logging and for domain
descriptions, see the NetworkManager.conf man page.

# man NetworkManager.conf

The ‘nmcli networking’ sub-command

Use the nmcli networking object to show NetworkManager networking status, or to


enable and disable networking. Disabling networking removes the configuration from
all devices and changes them to the “unmanaged“” state. The following command
provides help on the nmcli networking object:

# nmcli networking help


Usage: nmcli networking { COMMAND | help }
COMMAND := { [ on | off | connectivity ] }
on
off
connectivity [check]
Some examples of using this command are given.

Example 1 : Check networking status and enable/disable it

The following sequence of commands displays the networking status and then
disables and enables networking:

# nmcli networking
enabled
# nmcli networking off
# nmcli networking
disabled
# nmcli networking on
Example 2 : Check the network connectivity state

The connectivity argument shows the network connectivity state. An optional check
argument tells NetworkManager to recheck the connectivity. Without the check
argument, the command displays the most recent known connectivity state without
rechecking. The following example includes the check argument:

# nmcli networking connectivity check


full
Possible states are:

State Description

none The host is not connected to any network.

portal The host is behind a captive portal and cannot reach the full
Internet.

limited The host is connected to a network, but it has no access to the


Internet.

full The host is connected to a network and has full access to the
Internet.

unknown The connectivity status cannot be determined.


The ‘nmcli radio’ sub-command

Use the nmcli radio object to show radio switch status, or to enable and disable the
switches. The following command provides help on the nmcli radio object:

# nmcli radio help


Usage: nmcli radio { COMMAND | help }
COMMAND := { all | wifi | wwan }
all | wifi | wwan [ on | off ]
Some examples of using this command are given.

Example 1 : Check Radion Switch status

The following command displays the radio switch status.

# nmcli radio
WIFI-HW WIFI WWAN-HW WWAN
enabled enabled enabled enabled
Example 2: Disable Wi-Fi in NetworkManager

Following Example disable the Wi-Fi in NetworkManager.

# nmcli radio wifi off


# nmcli radio
WIFI-HW WIFI WWAN-HW WWAN
enabled disabled enabled enabled

The nmcli connection sub-command

Use the nmcli connection object to start, stop, and manage network connections.
NetworkManager stores all network configuration information as connections.
Connections contain all the information, such as MAC address and IP address,
required to create or connect to a network. A connection is active when a device uses
that connection’s configuration to create or connect to a network.

There can be multiple connections for a given device but only one of them can be
active on that device at any given time. The additional connections can be used to
allow quick switching between different networks and configurations. For example,
you can have a connection defined for a network interface that uses static IP
addressing. You could have a second connection defined for the same network
interface that uses DHCP.
The following command provides help on the nmcli connection object:

# nmcli connection help


Usage: nmcli connection { COMMAND | help }
COMMAND := { show | up | down | add | modify | clone | edit | delete |
monitor | reload | load | import | export }
....
Example 1 : View connection profiles

Use the show argument to list connection profiles. Include the –active option to list


only the active profiles. Example:

# nmcli connection show --active


NAME UUID TYPE
DEVICE
ens33 bbe539aa-5042-4d28-a0e6-2a4d4f5dd744 802-3-ethernet
ens33
You can also view detailed information for a specific connection by specifying an
optional [ID] keyword followed by an associated value. The [ID] can
be id, uuid, path, or apath. The following example uses the id keyword to show
detailed information for the enp134s1f0 connection. Only partial output is shown:

# nmcli connection show id ens33


connection.id: ens33
connection.uuid: bbe539aa-5042-4d28-a0e6-
2a4d4f5dd744
connection.stable-id: --
connection.interface-name: ens33
connection.type: 802-3-ethernet
connection.autoconnect: no
connection.autoconnect-priority: 0
connection.timestamp: 1511842397
connection.read-only: no
...
Example 2 : The nmcli connection up|down Commands

Use the up argument to activate a connection. The connection is specified by its


name, UUID, or D-Bus path. When requiring a particular device to activate the
connection on, use the ifname option with the interface name. The following example
activates the “ens33” connection. The show argument is issued before and after to
illustrate the result of the up argument:

# nmcli connection show


NAME UUID TYPE
DEVICE
Wired connection 1 dba7561b-dd02-3b58-92c0-07ce94b6250f 802-3-ethernet
ens36
ens33 bbe539aa-5042-4d28-a0e6-2a4d4f5dd744 802-3-ethernet
--
# nmcli connection up id ens33
Connection successfully activated (D-Bus active path:
/org/freedesktop/NetworkManager/ActiveConnection/5)
# nmcli connection show
NAME UUID TYPE
DEVICE
Wired connection 1 dba7561b-dd02-3b58-92c0-07ce94b6250f 802-3-ethernet
ens36
ens33 bbe539aa-5042-4d28-a0e6-2a4d4f5dd744 802-3-ethernet
ens33
Use the down argument to deactivate a specific active connection. The following
example deactivates the eth1 connection. The show argument is issued before and
after to illustrate the result of the down argument:

# nmcli connection show


NAME UUID TYPE DEVICE
System eth0 ..... 802-3-ethernet eth0
System eth1 ..... 802-3-ethernet eth1
# nmcli connection down id ens33
Connection 'ens33' successfully deactivated (D-Bus active path:
/org/freedesktop/NetworkManager/ActiveConnection/4
# nmcli connection show
NAME UUID TYPE
DEVICE
Wired connection 1 dba7561b-dd02-3b58-92c0-07ce94b6250f 802-3-ethernet
ens36
ens33 bbe539aa-5042-4d28-a0e6-2a4d4f5dd744 802-3-ethernet
--
If the connection has the “connection.autoconnect“” flag set to “yes“, the connection
automatically starts on the disconnected device again. In this case, use the nmcli
device disconnect command instead of the nmcli connection down command.

Example 3 : The nmcli connection add Command

Use the add argument to add a connection for NetworkManager. The syntax follows:

# nmcli connection add [COMMON_OPTIONS] [TYPE_SPECIFIC] [OPTIONS]


[IP_OPTIONS]
The COMMON_OPTIONS for the add argument are described:
 type [type]: Connection type. Valid types of connections are ethernet, wifi,
wimax, pppoe, gsm, cdma, infiniband, bluetooth, vlan, bond, bond-slave, team,
team-slave, bridge, bridge-slave, vpn, and olpc-mesh.
 ifname [ifname]: Interface to bind the connection to. A special value of “*”
can be used for interface-independent connections.
 con-name [connection_name]: Connection name. This is optional. When not
provided, a default name is generated, [type][-ifname][-num].
 autoconnect yes|no: Whether the connection profile can be automatically
activated. This is optional. The default is yes.
 save yes|no: Whether the connection is persistent. This is optional. The default
is yes.

Some of the TYPE_SPECIFIC OPTIONS for the add argument are given below.


The following lists the TYPE_SPECIFIC OPTIONS for Ethernet and WiFi
connections:

 ethernet TYPE_SPECIFIC OPTIONS:

o mac [MAC_address]: MAC address of the device this connection is


locked to
o cloned-mac [cloned_MAC_address]: Clone MAC address
o mtu [MTU]: MTU
 wifi TYPE_SPECIFIC OPTIONS:
o ssid [SSID]: SSID
o mac [MAC_address]: MAC address of the device this connection is
locked to
o cloned-mac [cloned_MAC_address]: Clone MAC address
o mtu [MTU]: MTU

The IP_OPTIONS for the add argument are described:

 ip4 [IPv4_address] gw4 [IPv4_address]: IPv4 addresses


 ip6 [IPv6_address] gw6 [IPv6_address]: IPv6 addresses

The following example adds an Ethernet connection. The nmcli connection show
command is issued afterwards to view the results. Only partial output is shown.

nmcli connection add con-name new-ens33 ifname ens33 type ethernet ip4
192.168.2.100/24 gw4 192.168.2.1
Connection 'new-ens33' (f0c23472-1aec-4e84-8f1b-be8a2ecbeade) successfully
added.
# nmcli connection show
NAME UUID TYPE
DEVICE
Wired connection 1 dba7561b-dd02-3b58-92c0-07ce94b6250f 802-3-
ethernet ens36
ens33 bbe539aa-5042-4d28-a0e6-2a4d4f5dd744 802-3-
ethernet ens33
new-ens33 f0c23472-1aec-4e84-8f1b-be8a2ecbeade 802-3-ethernet
--
Each new connection creates an associated network interface configuration file in
the /etc/sysconfig/network-scripts directory. For example:

# ls /etc/sysconfig/network-scripts/ifcfg*
/etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-
scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-new-ens33
Example 4 : The nmcli connection edit Command

Use the edit argument to edit an existing connection, identified by the connection ID,
UUID, or D-Bus path. The following example specifies editing of the new-ens33
connection:

# nmcli connection edit new-ens33

===| nmcli interactive connection editor |===

Editing existing '802-3-ethernet' connection: 'new-ens33'

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, dcb, ipv4, ipv6
nmcli>
Use the ‘?’ key or type ‘help’ to display the available commands.

nmcli> ?
--------------------------------------------------------------------------
----
---[ Main menu ]---
goto [[setting] | [prop]] :: go to a setting or property
remove [setting][.[prop]] | [prop] :: remove setting or reset property
value
set [[setting].[prop] [value]] :: set property value
describe [[setting].[prop]] :: describe property
print [all | [setting][.[prop]]] :: print the connection
verify [all | fix] :: verify the connection
save [persistent|temporary] :: save the connection
activate [[ifname]] [/[ap]|[nsp]] :: activate the connection
back :: go one level up (back)
help/? [[command]] :: print this help
nmcli [conf-option] [value] :: nmcli configuration
quit :: exit nmcli
--------------------------------------------------------------------------
----
nmcli>
Use the edit argument without specifying a connection identifier to add a new
connection. The interactive editor guides you through the connection editing. The
following example adds a new Ethernet connection:

# nmcli connection edit


Valid connection types: generic, 802-3-ethernet (ethernet), pppoe, 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, no-slave, tun, ip-tunnel, macvlan, vxlan
Enter connection 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, dcb, ipv4, ipv6
nmcli> set connection.id new-eth1
nmcli> set connection.interface-name eth1
nmcli> set connection.autoconnect yes
nmcli> set 802-3-ethernet.mtu auto
nmcli> set ipv4.method manual
nmcli> set ipv4.addresses 192.168.2.101/24
nmcli> set ipv6.method auto
nmcli> save
Saving the connection with 'autoconnect=yes'. That might result in an
immediate activation of the connection.
Do you still want to save? (yes/no) [yes] yes
Connection 'new-eth1' (817e285b-60f0-42d8-b259-4b62e21d823d) successfully
saved.
nmcli> quit
A new network interface configuration file is created in the /etc/sysconfig/network-
scripts directory:

# ls -lrt /etc/sysconfig/network-scripts/ifcfg*
-rw-r--r--. 1 root root 254 Sep 12 2016 /etc/sysconfig/network-
scripts/ifcfg-lo
-rw-r--r--. 1 root root 309 Oct 19 18:44 /etc/sysconfig/network-
scripts/ifcfg-ens33
-rw-r--r--. 1 root root 338 Nov 28 09:51 /etc/sysconfig/network-
scripts/ifcfg-new-ens33
-rw-r--r--. 1 root root 316 Nov 28 10:00 /etc/sysconfig/network-
scripts/ifcfg-new-eth1
Example 5 : The nmcli connection modify Command

Use the modify argument to modify one or more properties in the connection profile.


Identify the connection to modify by its ID, UUID, or D-Bus path. The provided value
overwrites the existing property value.

Use an empty value (“”) to set the property value to the default. You can use the +
prefix for the property name to append an item to the existing value, or use the –
prefix to remove a specified value. The following example modifies the IPv4 DNS
server address. The show argument displays the values before and after the
modification:
Before

# nmcli connection show new-eth1 ...


ipv4.dns:
...
# nmcli connection modify new-eth1 ipv4.dns 192.168.134.21
After

# nmcli connection show new-eth1


...
ipv4.dns: 192.168.134.21
...
Example 6 : The nmcli connection delete | reload | load Command

1. Use the delete argument to delete a configured connection. For example:

# nmcli connection delete new-eth1


2. Use the reload argument to reload all connection files from disk. Use this
command to tell NetworkManager to re-read the connection profiles from disk
whenever a change was made to them. Set the monitor-connection-files to true to
enable the auto-loading feature. In this case, NetworkManager reloads connection
files any time they change. For example:

# nmcli connection reload


3. Use the load argument to load or reload one or more specific configuration files
from disk. This is not needed if the auto-loading feature is enabled for the connection.
For example :
# nmcli connection load /etc/sysconfig/network- scripts/ifcfg-new-eth0

The nmcli device Sub-Command

The nmcli device object provides the following commands:

 status: Display the status of all devices.


 show [ifname]: Show detailed information about devices.
 connect [ifname]: Connect the device.
 disconnect [ifname]: Disconnect the device.
 wifi list | connect | rescan: List Wi-Fi access points. Connect to a Wi-Fi
network. Rescan for available access points.

Use the nmcli device object to show and manage network interfaces. The following
command provides help on the nmcli device object:

# nmcli device help


Usage: nmcli device { COMMAND | help }

COMMAND := { status | show | set | connect | reapply | modify | disconnect


| delete | monitor | wifi | lldp }

status

show [[ifname]]

set [ifname] [ifname] [autoconnect yes|no] [managed yes|no]

connect [ifname]

reapply [ifname]

modify [ifname] ([+|-][setting].[property] [value])+

disconnect [ifname] ...

delete [ifname] ...

monitor [ifname] ...

wifi [list [ifname [ifname]] [bssid [BSSID]]]

wifi connect [(B)SSID] [password [password]] [wep-key-type key|phrase]


[ifname [ifname]]
[bssid [BSSID]] [name [name]] [private yes|no]
[hidden yes|no]
wifi hotspot [ifname [ifname]] [con-name [name]] [ssid [SSID]] [band a|
bg] [channel [channel]] [password [password]]

wifi rescan [ifname [ifname]] [[ssid [SSID to scan]] ...]

lldp [list [ifname [ifname]]]


Some examples of using this command are given.

Example 1 : Display status of all the devices

The following sequence of commands displays the status of all devices.


The status argument is the default.

# nmcli device
DEVICE TYPE STATE CONNECTION
ens33 ethernet connected ens33
ens36 ethernet connected Wired connection 1
lo loopback unmanaged --
Example 2 : Display information oabout devices

The following example displays detailed information about a device:

# nmcli device show


GENERAL.DEVICE: ens33
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:0C:29:54:F7:20
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: ens33
GENERAL.CON-PATH:
/org/freedesktop/NetworkManager/ActiveConnection/5
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 192.168.219.150/24
IP4.GATEWAY: 192.168.219.2
IP4.DNS[1]: 192.168.219.2
IP4.DOMAIN[1]: localdomain
IP6.ADDRESS[1]: fe80::3442:365:1982:aa4b/64
IP6.GATEWAY:

GENERAL.DEVICE: ens36
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:0C:29:54:F7:2A
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: Wired connection 1
GENERAL.CON-PATH:
/org/freedesktop/NetworkManager/ActiveConnection/0
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 192.168.219.155/24
IP4.GATEWAY: 192.168.219.2
IP4.DNS[1]: 192.168.219.2
IP4.DOMAIN[1]: localdomain
IP6.ADDRESS[1]: fe80::e87:3cb9:edf5:1084/64
IP6.GATEWAY:

GENERAL.DEVICE: lo
GENERAL.TYPE: loopback
GENERAL.HWADDR: 00:00:00:00:00:00
GENERAL.MTU: 65536
GENERAL.STATE: 10 (unmanaged)
GENERAL.CONNECTION: --
GENERAL.CON-PATH: --
IP4.ADDRESS[1]: 127.0.0.1/8
IP4.GATEWAY:
IP6.ADDRESS[1]: ::1/128
IP6.GATEWAY:
Example 3 : Connect and disconect a device

The following example shows the effect of using the disconnect and connect
arguments:

# nmcli device disconnect ens33


Device 'ens33' successfully disconnected.
# nmcli device
DEVICE TYPE STATE CONNECTION
ens36 ethernet connected Wired connection 1
ens33 ethernet disconnected --
lo loopback unmanaged --
# nmcli device connect ens33
Device 'ens33' successfully activated with 'bbe539aa-5042-4d28-a0e6-
2a4d4f5dd744'.
# nmcli device
DEVICE TYPE STATE CONNECTION
ens33 ethernet connected ens33
ens36 ethernet connected Wired connection 1
lo loopback unmanaged --
The “nmcli device wifi“” command provides the following arguments:

 list: List available Wi-Fi access points.


 connect [(B)SSID]: Connect to a Wi-Fi network specified by Service Set
Identifier (SSID) or Basic Service Set Identifier (BSSID).
 rescan: Request that NetworkManager re-scan for available Wi-Fi access
points.
I have seen many administrators using nmtui for simplicity. However
using nmcli saves your time, gives you confidence, can use it in scripts and it’s
the first tool to use in order to troubleshoot your Linux server networking and
bring back rapidly its functionality.
Seeing many comments asking help about nmcli, I decided to write this article.
Of course you should always read carefully man pages (its the No1 help for you).
My aim is to save your time and show you some hints.
The syntax of nmcli is:

# nmcli [OPTIONS] OBJECT {COMMAND | help}

Where OBJECT is one of: general, networking, radio, connection, device, agent.


A good starting point would be to check our devices:

# nmcli dev status

DEVICE TYPE STATE CONNECTION


docker0 bridge connected docker0
virbr0 bridge connected virbr0
enp0s3 ethernet connected enp0s3
virbr0-nic ethernet disconnected --
lo loopback unmanaged --

As we can see in the first column is a list of our network devices. We have one
network cards with name enp0s3. In your machine you could see other names.
Naming depends on the type of the network card (if it is onboard, pci card , etc).
In the last column we see our configuration files which is used by our devices in
order to connect to the network.

It is simple to understand that our devices by themselves can do nothing. They


need us to make a configuration file to tell them how to achieve network
connectivity. We call these files also as “connection profiles”. We find them
in /etc/sysconfig/network-scripts directory.
# cd /etc/sysconfig/network-scripts/

# ls

Sample Output

ifcfg-enp0s3 ifdown-isdn ifup ifup-plip


ifup-tunnel

ifcfg-lo ifdown-post ifup-aliases ifup-plusb


ifup-wireless

ifdown ifdown-ppp ifup-bnep ifup-post


init.ipv6-global

ifdown-bnep ifdown-routes ifup-eth ifup-ppp


network-functions

ifdown-eth ifdown-sit ifup-ib ifup-routes


network-functions-ipv6

ifdown-ib ifdown-Team ifup-ippp ifup-sit

ifdown-ippp ifdown-TeamPort ifup-ipv6 ifup-Team

ifdown-ipv6 ifdown-tunnel ifup-isdn ifup-TeamPort

As you can see here the files with name starting with ifcfg- (interface
configuration) are connection profiles. When we create a new connection or
modify an existing one with nmcli or nmtui, the results are saved here as
connection profiles.
Ι ‘ll show you two of them from my machine, one with a dhcp configuration and
one with static ip.
# cat ifcfg-static1

# cat ifcfg-Myoffice1

Check Network Configuration

We realize that some properties have different values and some others don’t
exist if it isn’t necessary. Let’s have a quick look to most important of them.

 TYPE, we have ethernet type here. We could have wifi, team, bond and
others.
 DEVICE, the name of the network device which is associated with this
profile.
 BOOTPROTO, if it has value “dhcp” then our connection profile takes dynamic
IP from dhcp server, if it has value “none” then it takes no dynamic IP and
probably whe assign a static IP.
 IPADDR, is the static IP we assign to our profile.
 PREFIX, the subnet mask. A value of 24 means 255.255.255.0. You can
understand better the subnet mask if you write down its binary format. For
example values of 16, 24, 26 means that the first 16, 24 or 26 bits
respectively are 1 and the rest 0, defining exactly what the network
address is and what is the range of ip which can be assigned.
 GATEWAY, the gateway IP.
 DNS1, DNS2, two dns servers we want to use.
 ONBOOT, if it has value “yes” it means, that on boot our computer will read
this profile and try to assign it to its device.
Now, let’s move on and check our connections:

# nmcli con show

Show Active Network Connections

The last column of devices helps us understand which connection is “UP” and


running and which is not. In the above image you can see the two connections
which are active: Myoffice1 and enp0s8.
Hint: If you want to see only the active connections, type:

# nmcli con show -a

Hint: You can use the auto-complete hitting Tab when you use nmcli, but is
better to use minimal format of the command. Thus, the following commands are
equal:

# nmcli connection show

# nmcli con show

# nmcli c s

If I check the ip addresses of my devices:


# ip a

Check Server IP Address

I see that my device enp0s3 took the 192.168.1.6 IP from dhcp server, because


the connection profile Myoffice1 which is up has a dhcp configuration. If I
bring “up” my connection profile with name static1 then my device will take the
static IP 192.168.1.40 as it is defined in the connection profile.

# nmcli con down Myoffice1 ; nmcli con up static1

# nmcli con show

Let’s see the IP address again:


# ip a

Check Network Static IP Address

We can make our first connection profile. The minimum properties we must
define are type, ifname and con-name:
 type – for the type of connection.
 ifname – for the device name which is assigned our connection.
 con-name – for the connection name.
Let’s make a new ethernet connection with name Myhome1, assigned to
device enp0s3:

# nmcli con add type ethernet con-name Myhome1 ifname enp0s3

Check its configuration:


# cat ifcfg-Myhome1

Create New Network Connection

As you can see it has BOOTPROTO=dhcp, because we didn’t give any static ip


address.
Hint: We can modify any connection with the “nmcli con mod“ command.
However if you modify a dhcp connection and change it to static don’t forget to
change its “ipv4.method” from “auto” to “manual”. Otherwise you will end up with
two IP addresses: one from dhcp server and the static one.
Let’s make a new Ethernet connection profile with name static2, which will be
assigned to device enp0s3, with static IP 192.168.1.50, subnet
mask 255.255.255.0=24 and gateway 192.168.1.1.

# nmcli con add type ethernet con-name static2 ifname enp0s3


ip4 192.168.1.50/24 gw4 192.168.1.1

Check its configuration:


# cat ifcfg-static2

Create New Ethernet Connection

Let’s modify the last connection profile and add two dns servers.

# nmcli con mod static2 ipv4.dns “8.8.8.8 8.8.4.4”

Hint: There is something here you must pay attention: the properties for IP
address and gateway have different names when you add and when you modify
a connection. When you add connections you use “ip4” and “gw4”, while when
you modify them you use “ipv4” and “gwv4”.
Now let’s bring up this connection profile:

# nmcli con down static1 ; nmcli con up static2


As you can see, the device enp0s3 has now IP address 192.168.1.50.

# ip a

Verify IP Address of New Network Connection

Hint: There are a lot of properties you can modify. If you don’t remember them by
heart you can help yourself by typing “nmcli con show” and after that the
connection name:

# nmcli con show static2


Verify IP Address of New Network Connection

You can modify all these properties written in lowercase.

For example: when you bring down a connection profile,


the NetworkManager searches for another connection profile and brings it up
automatically. (I leave it as exercise to check it). If you don’t want your
connection profile to autoconnect:

# nmcli con mod static2 connection.autoconnect no

The last exercise is very usefull: you made a connection profile but you want it to
be used by specific users. It’s good to classify your users!

We let only user stella to use this profile:


# nmcli con mod static2 connection.permissions stella

Hint: If you want to give permissions to more than one users, you must
type user:user1,user2 without blank space between them:

# nmcli con mod static2 connection.permissions


user:stella,john
Allow Network Connections to Users

If you login as another user you can’t bring “up” this connection profile:

# nmcli con show

# nmcli con up static2

# ls /etc/sysconfig/network-scripts
Enable Network Connection

An error message says that connection ‘static2’ does not exist, even if we see
that it exists. That’s because current user has no permissions to bring up this
connection.
Conclusion: don’t hesitate to use nmcli. It’s easy and helpful.

Showing  IP Addresses Information

IP command will be used to show device and network address information.


List of below commands will generate different type of customize output of
address information.

 Show all interfaces IP address and Netmask information.

# ip addr
Some option of ip addr command as below, execute below command and get
specific interface information.
# ip addr show
# ip addr show [Device Name ]

Device Name  :   Network interfaces in Linux can be named as eth0,eth1 and


enp2s0.The interface name is based on device topology , firmware and device
type like Ethernet  interface begin with en and WLAN interface will begin with
wl name.

The above command will show all interface device information.

(a)  UP showing as active interface.

(b)  MAC address of device.

(c)  Inet line shows the IPv4 and Netmaks or Prefix information.

(d)  Broadcast address

(e)  Scope and device name are also on the same line.

(f)  This will show IPv6 information.


 Display Routing Information

# ip  route

 Network Device Configuration with nmcli  and

Network Manager

NMCLI  General Command and its usages.

(a) Below command wil list all connections .

# nmcli con show

(b) Active connection will show with  –active option.

# nmcli con show  --active

(c) You can check device status and details.

# nmcli  dev status


(d) It will show general status of Network Manager.

# nmcli general status

(e) Now nmcli  will show configuration of connection through below


command.

# nmcli con show  “CONNECTION NAME or UUID”

The output of below command is completed. some of content screecast image


is below.
 
Add  new IP or update Network interface

information on existing interface with nmcli

Here we are going to update or change IP address on existing active interface.


Be careful with live servers before doing this , you should aware what you are
doing, it can be lost network connection and lost remote server , you should
have good system administrator knowledge.
Turn on autoconnect 
Below command will  be enable  network device on boot .

# nmcli con mod  “CONNECTION NAME ” connection.autoconnect yes

Add a DNS Server 

# nmcli con mod  “CONNECTION NAME” ipv4.dns [DNS IP]

If you want to add one more DNS as a secondary DNS, you can use +/-
operator in the argument ,like below command.

# nmcli con mod “CONNECTION NAME”  +ipv4.dns [DNS IP]


Add manual static IP address and gateway

# nmcli con mod "CONNECTION NAME” ipv4.addresses [IP ADDRESS/PREFIX  GATEWAY]

Here 192.168.0.10 is IP Address and 24 is Prefix or net mask and 192.168.0.2


is gateway  which I have set .

If you want to add a secondary IP address without a gateway , you can use as
below.

# nmcli con mod “CONNECTION NAME”  +ipv4.addresses [IP ADDRESS/PREFIX]

Now if your connection  has been done , these command will save your
command setting to the configuration , it will reflect and worked after
activated or deactivated connection. Here are reload configuration and
activated and deactivated connection command below.
nmcli-examples
nmcli-examples — usage examples of nmcli
Synopsis

nmcli [OPTIONS...]

Description

nmcli is a command-line client for NetworkManager. It allows controlling


NetworkManager and reporting its status. For more information please refer
to nmcli(1) manual page.

The purpose of this manual page is to provide you with various examples and
usage scenarios of nmcli.

Examples

Example 1. Listing available Wi-Fi APs


$ nmcli device wifi list
* SSID MODE CHAN RATE SIGNAL BARS SECURITY
netdatacomm_local Infra 6 54 Mbit/s 37 ▂▄__ WEP
* F1 Infra 11 54 Mbit/s 98 ▂▄▆█ WPA1
LoremCorp Infra 1 54 Mbit/s 62 ▂▄▆_ WPA2 802.1X
Internet Infra 6 54 Mbit/s 29 ▂___ WPA1
HPB110a.F2672A Ad-Hoc 6 54 Mbit/s 22 ▂___ --
Jozinet Infra 1 54 Mbit/s 19 ▂___ WEP
VOIP Infra 1 54 Mbit/s 20 ▂___ WEP
MARTINA Infra 4 54 Mbit/s 32 ▂▄__ WPA2
N24PU1 Infra 7 11 Mbit/s 22 ▂___ --
alfa Infra 1 54 Mbit/s 67 ▂▄▆_ WPA2
bertnet Infra 5 54 Mbit/s 20 ▂___ WPA1 WPA2

This command shows how to list available Wi-Fi networks (APs). You can also
use --fields option for displaying different columns. nmcli -f all dev wifi
list will show all of them.

Example 2. Showing general information and properties for a Wi-Fi


interface
$ nmcli -p -f general,wifi-properties device show wlan0
===========================================================================
Device details (wlan0)
===========================================================================
GENERAL.DEVICE: wlan0
GENERAL.TYPE: wifi
GENERAL.VENDOR: Intel Corporation
GENERAL.PRODUCT: PRO/Wireless 5100 AGN [Shiloh] Network Connection
GENERAL.DRIVER: iwlwifi
GENERAL.DRIVER-VERSION: 3.8.13-100.fc17.x86_64
GENERAL.FIRMWARE-VERSION: 8.83.5.1 build 33692
GENERAL.HWADDR: 00:1E:65:37:A1:D3
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.REASON: 0 (No reason given)
GENERAL.UDI: /sys/devices/pci0000:00/0000:00:1c.1/net/wlan0
GENERAL.IP-IFACE: wlan0
GENERAL.IS-SOFTWARE: no
GENERAL.NM-MANAGED: yes
GENERAL.AUTOCONNECT: yes
GENERAL.FIRMWARE-MISSING: no
GENERAL.CONNECTION: My Alfa WiFi
GENERAL.CON-UUID: 85194f4c-d496-4eec-bae0-d880b4cbcf26
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/
10
---------------------------------------------------------------------------
WIFI-PROPERTIES.WEP: yes
WIFI-PROPERTIES.WPA: yes
WIFI-PROPERTIES.WPA2: yes
WIFI-PROPERTIES.TKIP: yes
WIFI-PROPERTIES.CCMP: yes
WIFI-PROPERTIES.AP: no
WIFI-PROPERTIES.ADHOC: yes
---------------------------------------------------------------------------

This command shows information about a Wi-Fi device.

Example 3. Listing NetworkManager polkit permissions


$ nmcli general permissions
PERMISSION VALUE
org.freedesktop.NetworkManager.enable-disable-network yes
org.freedesktop.NetworkManager.enable-disable-wifi yes
org.freedesktop.NetworkManager.enable-disable-wwan yes
org.freedesktop.NetworkManager.enable-disable-wimax yes
org.freedesktop.NetworkManager.sleep-wake no
org.freedesktop.NetworkManager.network-control yes
org.freedesktop.NetworkManager.wifi.share.protected yes
org.freedesktop.NetworkManager.wifi.share.open yes
org.freedesktop.NetworkManager.settings.modify.system yes
org.freedesktop.NetworkManager.settings.modify.own yes
org.freedesktop.NetworkManager.settings.modify.hostname auth

This command shows configured polkit permissions for various


NetworkManager operations. These permissions or actions (using polkit
language) are configured by a system administrator and are not meant to be
changed by users. The usual place for the polkit configuration is
/usr/share/polkit-1/actions/org.freedesktop.NetworkManager.policy. pkaction c
ommand can display description for polkit actions.

pkaction --action-id org.freedesktop.NetworkManager.network-control


--verbose

More information about polkit can be found at


http://www.freedesktop.org/wiki/Software/polkit.

Example 4. Listing NetworkManager log level and domains


$ nmcli general logging
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,WIFI_SCAN,IP4,IP6,A
UTOIP4,DNS,VPN,SHARING,SUPPLICANT,AGENTS,SETTINGS,SUSPEND,CORE,DEVICE,OLPC,
WIMAX,INFINIBAND,FIREWALL,ADSL,BOND,VLAN,BRIDGE,DBUS_PROPS,TEAM,CONCHECK,DC
B,DISPATCH

This command shows current NetworkManager logging status.

Example 5. Changing NetworkManager logging


$ nmcli g log level DEBUG domains CORE,ETHER,IP
$ nmcli g log level INFO domains DEFAULT
The first command makes NetworkManager log in DEBUG level, and only for
CORE, ETHER and IP domains. The second command restores the default
logging state. Please refer to the NetworkManager.conf(5) manual page for
available logging levels and domains.

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

This example demonstrates adding a bond master connection and two slaves.
The first command adds a master bond connection, naming the bonding
interface mybond0 and using active-backup mode. The next two commands
add slaves connections, both enslaved to mybond0. The first slave will be
bound to eth1 interface, the second to eth2.

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

This example demonstrates adding a team master connection profile and two
slaves. It is very similar to the bonding example. The first command adds a
master team profile, naming the team interface and the profile Team1. The
team configuration for the master is read from team1-master-json.conf file.
Later, you can change the configuration with modify command (nmcli con
modify Team1 team.config team1-master-another-json.conf). The last two
commands add slaves profiles, both enslaved to Team1. The first slave will be
bound to em1 interface, the second to em2. The slaves don't
specify config and thus teamd will use its default configuration. You will
activate the whole setup by activating both slaves:
$ nmcli con up Team1-slave1
$ nmcli con up Team1-slave2
By default, the created profiles are marked for auto-activation. But if another
connection has been activated on the device, the new profile won't activate
automatically and you need to activate it manually.

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

This example demonstrates adding a bridge master connection and two


slaves. The first command adds a master bridge connection, naming the
bridge interface and the profile as TowerBridge. The next two commands add
slaves profiles, both will be enslaved to TowerBridge. The first slave will be
tied to ens3 interface, the second to ens4. The last command will disable
802.1D STP for the TowerBridge profile.

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

The first command adds an Ethernet connection profile named my-con-


em1 that is bound to interface name em1. The profile is configured with static
IP addresses. Three addresses are added, two IPv4 addresses and one IPv6.
The first IP 192.168.100.100 has a prefix of 24 (netmask equivalent of
255.255.255.0). Gateway entry will become the default route if this profile is
activated on em1 interface (and there is no connection with higher priority).
The next two addresses do not specify a prefix, so a default prefix will be
used, i.e. 32 for IPv4 and 128 for IPv6. The second, third and fourth
commands modify DNS parameters of the new connection profile. The
last con show command displays the profile so that all parameters can be
reviewed.

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/NetworkMa
nager/ActiveConnection/9

This example shows escaping colon characters in tabular mode. It may be


useful for script processing, because ':' is used as a field separator.

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 [ "$2" = "up" ]; then


enable_disable_wifi
fi

if [ "$2" = "down" ]; then


enable_disable_wifi
fi

This dispatcher script makes Wi-Fi mutually exclusive with wired networking.
When a wired interface is connected, Wi-Fi will be set to airplane mode
(rfkilled). When the wired interface is disconnected, Wi-Fi will be turned back
on. Name this script e.g. 70-wifi-wired-exclusive.sh and put it into
/etc/NetworkManager/dispatcher.d/ directory. See NetworkManager(8) manual
page for more information about NetworkManager dispatcher scripts.

Example sessions of interactive connection editor

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

Introduction
It is essential to know how to configure your network connections after installing
CentOS. There are two ways to do so – via command line or the GUI. You can change
network specifications and set up a static IP or configure the network interface for
DHCP.

This tutorial shows you how to configure network settings on CentOS using a
command line or the Network Manager TUI. 

How Network Interface Naming Works?


RHEL introduced its new naming convention for network interfaces in version RHEL 6.
However, the feature was enabled by default only with version 7, which meant
that eth0 and eth1 were no more.

The names are now defined by a group of factors (device type, adapter, port/ID, and so
on).

Based on the device type, the network interface name can start with:

 en – Ethernet interface


 wl – Wlan interface
 ww – Wwam interface
 sl – Serial line IP (slip)
Configuring a Static IP
You can set up a static IP via command line by modifying the network script of the
interface.

1. First, find the name of the network interface you want to change using the network
manager command-line tool. Prompt the system to list all network devices, along with
network details:

nmcli d

In our example, we will change the configuration for the first network.

2. To do so, open the network’s configuration file by typing the following:

vi /etc/sysconf ig/network-scripts/ifcfg-[network_device_name]

3. A text editor with the network configuration opens.

4. To set a static IP for your network, you need to change the BOOTPROTO line to have
the value "static". Also, modify the ONBOOT option to "yes" to enable the network
when starting the system.

5. Then, add the following information about your network under the already existing
text:

IPADDR=...
NETMASK=...

GATEWAY=...

DNS1=...

DNS2=...

The configuration file should be similar to the example below:

6. Save the file and exit the text editor, returning to the command line.

7. For these changes to take effect, you must restart the network with the command:

systemctl restart
Configuring Network Interface for DHCP
You can configure a network for DHCP (Dynamic Host Configuration Protocol) via
command line by changing the network configuration.

1. Instruct the system to list your network devices with the command:

nmcli d

Find the network you want to configure for DHCP and copy its name.

2. Then, open the appropriate configuration file. Use the following command and paste
the device name at the end:

vi /etc/sysconf ig/network-scripts/ifcfg-[network_device_name]

3. A text editor with the network configuration opens.

4. The BOOTPROTO line should have the value "dhcp" and change the ONBOOT line


to "yes" to enable the network. Also, add network details such
as IPADDR, NETMASK, GATEWAY, and DNS.
5. Save the file and exit to return to the command line.

6. Finally, restart the network with:

systemctl restart

How to Configure Network Settings on CentOS


7 Using GUI
To configure your CentOS network interface via GUI, you need to open the Network
Manager and modify the configuration according to your needs.

1. Open the Network Manager by running the following command in the command line:

nmtui
2. The command prompts the NetworkManager TUI window, which appears as in the
image below. Select Edit a connection to view configuration settings.

3. Next, choose the network you want to configure.

You can now edit the given connection.


Configuring a Static IP
If you want to set the connection to have a static IP address, you can modify the
configuration with the Network Manager.

1. First, open the required connection settings. If you have followed the steps outlined in
the section above, you should already have the Edit a connection window in front of
you.

2. To set a static IP address for the IPv4 configuration, open the drop-down menu next
to the name of the appropriate connection.

3. By default, it is set to Automatic. Change the settings to Manual.

4. Then, select the Show option for the given network to add the necessary information.

5. Now you can add information related to your connection. This includes
the addresses, gateways, DNS servers, and search domains. You don’t have to fill out all
the fields.

6. Finally, make sure to enable the option for requiring IPv4 addressing for this
connection and automatic connection.
7. Select OK and Back to return to the main menu.

Configuring Network for Using DHCP


1. To configure a network as DHCP (Dynamic Host Configuration Protocol), you need to
set the IPv4 configuration settings to Automatic.

2. Before you exit out of the Network Manager, make sure to enable automatic
connection for the network interface.
3. Select OK to save the changes.

4. Then, exit out of the Network Manages by selecting Back and then Quit.

5. To enable the new configuration, you need to restart the service network by typing
the following command in the terminal:

service network restart

Set a System Hostname


You can also change your hostname using the Network Manager by selecting the Set
system hostname option in the main menu.

Type in the new hostname and select OK.


Validating Your Network Settings
Verify your network is now working with the new settings with the command:

ip a show [network_device_name]

The output will display interface information based on which you can verify if the
changes are live.

Conclusion
After reading this article, you should have successfully configured the network settings
on your CentOS system. If one method seems too difficult, try another method
explained in this article.
Methods 1 – Configure Static IP in CentOS 8 / RHEL 8 using
NetworkManager
 1.1 – Using the text user interface tool, nmtui.
 1.2 – Using the command-line tool, nmcli.
1.1 – Configure a network interface using the NetworkManager’s tool, nmtui

nmtui is curser-based text user interface tool (TUI) for NetworkManager.


Installation:

Note:-

This tool is used in command line window. It comes with NetworkManager-tui package,
which is not coming by default with NetworkManager package. But you can install it using
following command.

# yum install NetworkManager-tui

The process to change IP using nmtui:

Launch the nmtui tool
# nmtui

You will see NetworkManager text user interface starting menu will appear.


1. To navigate options, use the arrow keys or press Tab key to step forwards. Once you
select desire option then press Enter.
2. Chose Edit a connection option to edit a connection and then using Tab key bring
selection on OK button at bottom right side then press enter
3. Then on next screen chose your interface, in my case its eno1. See picture below.
After you chose to edit your interface, now here on next screen specify
IP Address, prefix, Gateway and DNS Server. Then using tab key navigates to ok then
press enter.
In next window chose your network interfaces which is eno1 and deactivate.
Then chose connection again and click activate button.
Select Back and then select Quit.
Use ifconfig command to verify whether ip address has been assigned to interface eno1
Above output is showing we have successfully assigned a static IP address
to eno1 interface using nmtui tool.
The following commands are also available:

# nmtui edit eno1

Above command will open edit connection window directly see below picture.
1.2 – Configure a network interface Using the command-line tool, nmcli.

What is nmcli?

nmcli (NetworkManager Command Line Interface) is the command-line utility to configure


IP settings through NetworkManager. Using nmcli command line tool you can create,
display, edit, delete, activate, and deactivate network connections, as well as control and
display network device status.
To display available network devices

# nmcli device

Above output showing nmcli device command list all available network devices in system.
Also you can see highlighted device state showing unmanaged there is connected also in
green color. A device state can be:
Managed

 i) It means it’s under the NetworkManager control, and a managed device may be


connected, meaning its configured and activated, or disconnected, it means not
configured but it is ready to be activated again.
Unmanaged

 i) This state mean this device is not under the control


of NetworkManager
Some useful nmcli device commands switches:

-f, field This option specifies what fields can be displayed in output.


Example: Specify which field you want to see in output.
# nmcli –f DEVICE,TYPE,CONNECTION device

-p, prettyThis option print output in human-readable format


See Example below

# nmcli –p device

nmcli device command takes many arguments but most commonly used


are: show, status, connect, set, disconnect, modify, edit and wifi. You can see further
details by entering nmcli device help command.
Assign Static IP Using nmcli.

Bellow command will assign a static ip address to our interface eno1


# nmcli con mod eno1 ipv4.addresses 192.168.2.88/24
Note:-

we used shorter version of nmcli connection modify command by


replacing connection keyword with con and modifiy with mod.

Assign gateway using below command.

# nmcli con mod eno1 ipv4.gateway 192.168.2.100

Set method of interface eno1 from dhcp to static using below command.

# nmcli con mod eno1 ipv4.method manual

Setting up DNS server IP

# nmcli con mod eno1 ipv4.dns “8.8.8.8”

Now to save all changes we have made, use following nmcli command.


# nmcli con up eno1

To confirm changes use below IP command

# ip addr show eno1

We can see above output shows, Static ip address is configured successfully


on eno1 interface.
Methods 2 – configure static IP in CentOS 8 / RHEL8 without using
NetworkManager.
 2.1 – Edit network configuration script file ifcfg-
* manually.

2.1 – Edit network configuration script file ifcfg-* manually

A configuration script file is created for each network interface


inside /etec/sysconfig/network-scripts/ directory. All configuration script file name started
with ifcfg- plus the name of the interface. If I view my system interface eno1 script file, see
how it looks like.
# cat /etc/sysconfig/network-scripts/ifcfg-eno1

Above configuration showing static ip configuration where we use:


 1: BOOTPROTO – none option is specified, since we are
using static ip so we no protocol should be there. In case if you want to get ip from
DHCP server so BOOTPROTO should BOOTPROTO=dhcp.
 2: IPADDR – This option we used to specify IP address.
 3: PREFIX – Used to define network prefix in our case it
is /24 network.
 4: GATEWAY – used to define default gateway for this
network.
 5: DNS – Using this option we can define multiple DNS
server with progressive number, starting from 1. See point number 5, showing DNS1 &
DNS2.
After you finish editing your network configuration script file, you must put interface down
and up again to make our changes effective.

Note:-

Be aware that this will disrupt existent ssh connections via said interface:

# nmcli connection down eno1 && nmcli connection up eno1

You can verify changes using ip addr command.

# ip addr|grep eno1|grep inet

Conclusions

We learn three methods we can use to configure static IP on CentOS 8 / RHEL 8. We see
what options we should change and what we should add in the interface configuration file
when editing it manually, an

You might also like