Common NetworkManager operations

Updated at:

NetworkManager manages network interface controller (NIC) configurations and connection status on Alibaba Cloud Linux. It detects available networks, switches connections on demand, and provides the nmcli command-line tool to configure IP addresses, gateways, DNS settings, routes, and more.

Prerequisites

Before you begin, make sure that you have:

  • An instance running Alibaba Cloud Linux 3

  • sudo privileges

Tip: For an interactive text-based interface, use nmtui instead of nmcli.

Connection-based and device-based configuration

NetworkManager supports two configuration modes:

Mode

Persistence

When changes take effect

Use case

Connection-based

Persistent across reboots

After you activate the connection

Permanent network changes

Device-based

Lost after reboot

Immediately

Temporary changes for testing or troubleshooting

Multi-value property syntax

For properties that accept multiple values (addresses, routes, routing rules), prefix the property name to control how the value is applied:

Prefix

Action

Example

+

Add a value

+ipv4.addresses 192.0.2.10/24

_(none)_

Replace all values

ipv4.addresses 192.0.2.10/24

-

Remove a specific value

-ipv4.addresses 192.0.2.10/24

Connection-based operations

Connection-based changes are saved to /etc/NetworkManager/system-connections/ and persist across reboots. After each modify command, run connection up to apply the change.

List connections

List all connection profiles with their associated configuration files:

nmcli -f NAME,FILENAME,TYPE,DEVICE connection

Sample output:

NAME   FILENAME                                                  TYPE      DEVICE
eth0   /etc/NetworkManager/system-connections/eth0.nmconnection   ethernet  eth0

Use the value from the NAME column as <connection-name> in the commands below.

View connection details

nmcli connection show "<connection-name>"

Activate and deactivate connections

Activate a connection:

sudo nmcli connection up "<connection-name>"

Deactivate a connection:

sudo nmcli connection down "<connection-name>"

Change MTU

  1. Set the maximum transmission unit (MTU). Replace <mtu-value> with the desired value, for example, 9000 for jumbo frames.

    sudo nmcli connection modify "<connection-name>" 802-3-ethernet.mtu <mtu-value>
  2. Activate the connection to apply the change:

    sudo nmcli connection up "<connection-name>"
  3. Verify the new MTU:

    ip link show "<device-name>"

Add, replace, or remove an IP address

  1. Modify the IP address:

    # Add an IP address
    sudo nmcli connection modify "<connection-name>" +ipv4.addresses 192.0.2.10/24
    
    # Replace all IP addresses
    sudo nmcli connection modify "<connection-name>" ipv4.addresses 192.0.2.20/24
    
    # Remove a specific IP address
    sudo nmcli connection modify "<connection-name>" -ipv4.addresses 192.0.2.10/24
  2. Activate the connection:

    sudo nmcli connection up "<connection-name>"
  3. Verify:

    ip address show "<device-name>"

Change MAC address

  1. Set a cloned media access control (MAC) address. Replace <new-mac-address> with the address in colon-separated format, for example, AA:BB:CC:DD:EE:FF.

    sudo nmcli connection modify "<connection-name>" 802-3-ethernet.cloned-mac-address <new-mac-address>
  2. Activate the connection:

    sudo nmcli connection up "<connection-name>"

Add, replace, or remove a route

  1. Modify the route. The format is <destination> <gateway>. The example below routes traffic for 198.51.100.0/24 through gateway 192.0.2.1.

    # Add a route
    sudo nmcli connection modify "<connection-name>" +ipv4.routes "198.51.100.0/24 192.0.2.1"
    
    # Replace all routes
    sudo nmcli connection modify "<connection-name>" ipv4.routes "198.51.100.0/24 192.0.2.1"
    
    # Remove a specific route
    sudo nmcli connection modify "<connection-name>" -ipv4.routes "198.51.100.0/24 192.0.2.1"
  2. Activate the connection:

    sudo nmcli connection up "<connection-name>"
  3. Verify:

    ip route show

Add, replace, or remove a routing rule

  1. Modify the routing rule:

    # Add a routing rule
    sudo nmcli connection modify "<connection-name>" +ipv4.routing-rules "priority 100 from 192.0.2.0/24 table 100"
    
    # Replace all routing rules
    sudo nmcli connection modify "<connection-name>" ipv4.routing-rules "priority 100 from 192.0.2.0/24 table 100"
    
    # Remove a specific routing rule
    sudo nmcli connection modify "<connection-name>" -ipv4.routing-rules "priority 100 from 192.0.2.0/24 table 100"
  2. Activate the connection:

    sudo nmcli connection up "<connection-name>"
  3. Verify:

    ip rule show

Device-based operations

Device-based changes take effect immediately but are lost after reboot. Use this mode for temporary configurations or quick testing without modifying persistent connection profiles.

View device status

nmcli device status

Sample output:

DEVICE  TYPE      STATE      CONNECTION
eth0    ethernet  connected  eth0
lo      loopback  unmanaged  --

Use the value from the DEVICE column as <device-name> in the commands below.

Enable or disable a NIC

Enable a NIC:

sudo nmcli device up "<device-name>"

Disable a NIC:

sudo nmcli device down "<device-name>"

Change MTU

sudo nmcli device modify "<device-name>" 802-3-ethernet.mtu <mtu-value>

Add, replace, or remove an IP address

# Add an IP address
sudo nmcli device modify "<device-name>" +ipv4.addresses 192.0.2.10/24

# Replace all IP addresses
sudo nmcli device modify "<device-name>" ipv4.addresses 192.0.2.10/24

# Remove a specific IP address
sudo nmcli device modify "<device-name>" -ipv4.addresses 192.0.2.10/24

Add, replace, or remove a route

# Add a route
sudo nmcli device modify "<device-name>" +ipv4.routes "198.51.100.0/24 192.0.2.1"

# Replace all routes
sudo nmcli device modify "<device-name>" ipv4.routes "198.51.100.0/24 192.0.2.1"

# Remove a specific route
sudo nmcli device modify "<device-name>" -ipv4.routes "198.51.100.0/24 192.0.2.1"

Add, replace, or remove a routing rule

# Add a routing rule
sudo nmcli device modify "<device-name>" +ipv4.routing-rules "priority 100 from 192.0.2.0/24 table 100"

# Replace all routing rules
sudo nmcli device modify "<device-name>" ipv4.routing-rules "priority 100 from 192.0.2.0/24 table 100"

# Remove a specific routing rule
sudo nmcli device modify "<device-name>" -ipv4.routing-rules "priority 100 from 192.0.2.0/24 table 100"

Monitor network status

Watch real-time network events — connection state changes and device status updates:

nmcli monitor

Press Ctrl+C to stop monitoring.

Related topics