7 NetworkManager configuration and usage #
NetworkManager is shipped so it can run out of the box, but you might need to reconfigure or restart the tool. This chapter focuses on these tasks.
NetworkManager stores all network configuration 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
, described in the
section below.
To change how NetworkManager behaves, change or add values to the configuration file
described in Section 7.3, “The NetworkManager.conf
configuration file”.
7.1 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
7.2 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 7.2.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 7.2.2, “The
connection
subcommand”.device
For details, refer to Section 7.2.3, “The
device
subcommand”.general
shows status and permissions. For details refer to Section 7.2.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 7.2.5, “The
networking
subcommand”.
7.2.1 The nmcli
command options #
Besides the subcommands and their arguments, the nmcli
command can take the following options:
-a|--ask
the command will stop 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.
7.2.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 already 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 abovementioned commands, refer to the
nmcli
documentation.
7.2.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 that will be 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#@@
7.2.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 will be used to set a new value.
#
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
.
7.2.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.
7.3 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
plugin 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 SLE Micro, you can also use other sections. For details, refer to networkmanager.conf(5) or Gnome's developer guide.