Configuring network using NetworkManager
- WHAT?
The article covers the basics of NetworkManager and the usage of the CLI tool to configure the network.
- WHY?
You are using NetworkManager, and you want to configure your network.
- EFFORT
It takes approx. 15 minutes to go through this article.
- GOAL
You will have a better understanding of how NetworkManager works and how network connections can be configured.
1 About NetworkManager #
NetworkManager is a program that manages the primary network connection and other
connection interfaces. NetworkManager has been designed to be fully automatic by
default. NetworkManager is handled by systemd
and is shipped with all necessary
service unit files.
NetworkManager stores all network configurations as a connection, which is a
collection of data that describes how to create or connect to a network.
These connections are stored as files in the
/etc/NetworkManager/system-connections/
directory.
A connection is active when a particular device uses the connection. The device may have more than one connection configured, but only one can be active at a given time. The other connections can be used to fast switch from one connection to another. For example, if the active connection is not available, NetworkManager tries to connect the device to another configured connection.
To manage connections, use the nmcli
command, described
in the Section 4, “Managing the network using NetworkManager”.
2 The NetworkManager.conf
configuration file #
The main configuration file for the NetworkManager is
/etc/NetworkManager/NetworkManager.conf
. This file can
be used to configure the behavior of NetworkManager.
The file consists of sections of key-value pairs. Each key-value pair must
belong to a section. A section starts with a name enclosed in
[]. Lines beginning with a # are
considered comments. The minimal configuration needs to include the
[main]
section with the plugins
value:
[main] plugins=keyfile
The keyfile
plug-in supports all the connection types and
capabilities of NetworkManager.
The default configuration file contains the connectivity
section that specifies the URI to check the network connection.
On SUSE Linux Enterprise Micro, you can also use other sections. For details, refer to networkmanager.conf(5) or Gnome's developer guide.
3 Starting and stopping NetworkManager #
As NetworkManager is a systemd
service, you can use common systemd
commands to
start, stop, or restart NetworkManager.
To start NetworkManager:
#
systemctl start network
To restart NetworkManager:
#
systemctl restart network
To stop NetworkManager:
#
systemctl stop network
4 Managing the network using NetworkManager #
4.1 The nmcli
command #
NetworkManager provides a CLI interface to manage your connections. By using the
nmcli
interface, you can connect to a particular
network, edit a connection, edit a device, etc. The generic syntax of the
nmcli
is as follows:
#
nmcli OPTIONS SUBCOMMAND SUBCOMMAND_ARGUMENTS
where OPTIONS are described in
Section 4.1.1, “The nmcli
command options” and
SUBCOMMAND can be any of the following:
connection
enables you to configure your network connection. For details, refer to Section 4.1.2, “The
connection
subcommand”.device
For details, refer to Section 4.1.3, “The
device
subcommand”.general
shows status and permissions. For details refer to Section 4.1.4, “The
general
subcommand”.monitor
monitors activity of NetworkManager and watches for changes in the state of connectivity and devices. This subcommand does not take any arguments.
networking
queries the networking status. For details, refer to Section 4.1.5, “The
networking
subcommand”.
4.1.1 The nmcli
command options #
Besides the subcommands and their arguments, the
nmcli
command can take the following options:
-a|--ask
The command stops its run to ask for any missing arguments, for example, for a password to connect to a network.
-c|--color {yes|no|auto}
controls the color output:
yes
to enable the colors,no
to disable them, andauto
creates color output only when the standard output is directed to a terminal.-m|--mode {tabular|multiline}
switches between
table
(each line describes a single entry, columns define particular properties of the entry) andmultiline
(each entry comprises more lines, each property is on its own line).tabular
is the default value.-h|--help
prints help.
-w|--wait seconds
sets a time-out period for which to wait for NetworkManager to finish operations. Using this option is recommended for commands that might take longer to complete, for example, connection activation.
4.1.2 The connection
subcommand #
The connection
command enables you to manage
connections or view any information about particular connections. The
nmcli connection
provides the following commands to
manage your network connections:
show
to list connections:
#
nmcli connection showYou can also use this command to show details about a specified connection:
#
nmcli connection show CONNECTION_IDwhere CONNECTION_ID is any of the identifiers: a connection name, UUID or a path
up
to activate the provided connection. Use the command to reload a connection. Also run this command after you perform any change to the connection.
#
nmcli connection up [--active] [CONNECTION_ID]When
--active
is specified, only the active profiles are displayed. The default is to display both active connections and static configuration.down
to deactivate a connection.
#
nmcli connection down CONNECTION_IDwhere: CONNECTION_ID is any of the identifiers: a connection name, UUID or a path
If you deactivate the connection, it will not reconnect later even if it has the
autoconnect
flag.modify
to change or delete a property of a connection.
#
nmcli connection modify CONNECTION_ID SETTING.PROPERTY PROPERTY_VALUEwhere:
CONNECTION_ID is any of the identifiers: a connection name, UUID, or a path
SETTING.PROPERTY is the name of the property, for example,
ipv4.addresses
PROPERTY_VALUE is the desired value of SETTING.PROPERTY
The following example deactivates the
autoconnect
option on theethernet1
connection:#
nmcli connection modify ethernet1 connection.autoconnect noadd
to add a connection with the provided details. The command syntax is similar to the
modify
command:#
nmcli connection add CONNECTION_ID save YES|NO SETTING.PROPERTY PROPERTY_VALUEYou should at least specify a
connection.type
or usetype
. The following example adds an Ethernet connection tied to theeth0
interface with DHCP, and disables the connection'sautoconnect
flag:#
nmcli connection add type ethernet autoconnect no ifname eth0edit
to edit an existing connection using an interactive editor.
#
nmcli connection edit CONNECTION_IDclone
to clone an existing connection. The minimal syntax follows:
#
nmcli connection clone CONNECTION_ID NEW_NAMEwhere CONNECTION_ID is the connection to be cloned.
delete
to delete an existing connection:
#
nmcli connection delete CONNECTION_IDmonitor
to monitor the provided connection. Each time the connection changes, NetworkManager prints a line.
#
nmcli connection monitor CONNECTION_IDreload
to reload all connection files from the disk. As NetworkManager does not monitor changes performed to the connection files, you need to use this command whenever you make changes to the files. This command does not take any further subcommands.
load
to load/reload a particular connection file, run:
#
nmcli connection load CONNECTION_FILE
For details about the above-mentioned commands, refer to the
nmcli
documentation.
4.1.3 The device
subcommand #
The device
subcommand enables you to show and manage
network interfaces. The nmcli device
command
recognizes the following commands:
status
to print the status of all devices.
#
nmcli device statusshow
shows detailed information about a device. If no device is specified, all devices are displayed.
#
mcli device show [DEVICE_NAME]connect
to connect a device. NetworkManager tries to find a suitable connection that will be activated. If there is no compatible connection, a new profile is created.
#
nmcli device connect DEVICE_NAMEmodify
performs temporary changes to the configuration that is active on the particular device. The changes are not stored in the connection profile.
#
nmcli device modify DEVICE_NAME [+|-] SETTING.PROPERTY VALUEFor possible SETTING.PROPERTY values, refer to nm-settings-nmcli(5).
The example below starts the IPv4 shared connection sharing on the device
con1
.#
nmcli dev modify con1 ipv4.method shareddisconnect
disconnects a device and prevents the device from automatically activating further connections without manual intervention.
#
nmcli device disconnect DEVICE_NAMEdelete
to delete the interface from the system. You can use the command to delete only software devices like bonds and bridges. You cannot delete hardware devices with this command.
#
nmcli device DEVICE_NAMEwifi
lists all available access points.
#
nmcli device wifiwifi connect
connects to a Wi-Fi network specified by its SSID or BSSID. The command takes the following options:
password
- password for secured networksifname
- interface used for activationname
- you can give the connection a name
#
nmcli device wifi connect SSID [password PASSWORD_VALUE] [ifname INTERFACE_NAME]To connect to a Wi-Fi GUESTWiFi with a password
pass$word2#@@
, run:#
nmcli device wifi connect GUESTWiFi password pass$word2#@@
4.1.4 The general
subcommand #
You can use this command to view NetworkManager status and permissions, and
change the host name and logging level. The nmcli
general
recognizes the following commands:
status
displays the overall status of NetworkManager. Whenever you do not specify a command to the
nmcli general
command, status is used by default.#
nmcli general statushostname
if you do not provide a new host name as an argument, the current host name is displayed. If you specify a new host name, the value is used to set a new host name.
#
nmcli general hostname [HOSTNAME]For example, to set
MyHostname
, run:#
nmcli general hostname MyHostnamepermissions
shows your permission for NetworkManager operations like enabling or disabling networking, modifying connections, etc.
#
nmcli general permissionslogging
shows and changes NetworkManager logging levels and domains. Without any arguments, the command displays current logging levels and domains.
#
nmcli general logging [level LEVEL domains DOMAIN]LEVEL is any of the values:
OFF
,ERR
,WARN
,INFO
,DEBUG
, orTRACE
.DOMAIN is a list of values that can be as follows:
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, AUDIT, SYSTEMD, VPN_PLUGIN, PROXY
.
4.1.5 The networking
subcommand #
The subcommand enables you to query the status of the network. Also, by
using this command, you can enable or disable networking. The
nmcli networking
command takes the following
commands:
on/off
enables or disables networking. The
off
command deactivates all interfaces managed by NetworkManager.#
nmcli networking on- connectivity
displays the network connectivity state. If
check
is used, NetworkManager performs a new check of the state. Otherwise, the last detected state is displayed.#
nmcli networking connectivityPossible states are the following:
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 - NetworkManager could not determine the network state.
5 Legal Notice #
Copyright© 2006–2024 SUSE LLC and contributors. All rights reserved.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or (at your option) version 1.3; with the Invariant Section being this copyright notice and license. A copy of the license version 1.2 is included in the section entitled “GNU Free Documentation License”.
For SUSE trademarks, see https://www.suse.com/company/legal/. All other third-party trademarks are the property of their respective owners. Trademark symbols (®, ™ etc.) denote trademarks of SUSE and its affiliates. Asterisks (*) denote third-party trademarks.
All information found in this book has been compiled with utmost attention to detail. However, this does not guarantee complete accuracy. Neither SUSE LLC, its affiliates, the authors, nor the translators shall be held liable for possible errors or the consequences thereof.