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:
Your instance runs Alibaba Cloud Linux 3
You have
sudoprivileges
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), use the following prefixes:
| 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 persistent. After each modify command, activate the connection to apply changes.
List connections
List all connection profiles with their associated configuration files:
nmcli -f NAME,FILENAME,TYPE,DEVICE connectionSample output:
NAME FILENAME TYPE DEVICE
eth0 /etc/NetworkManager/system-connections/eth0.nmconnection ethernet eth0Use 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
Set a new MTU value: Replace
<mtu-value>with the desired MTU, for example,9000for jumbo frames.sudo nmcli connection modify "<connection-name>" 802-3-ethernet.mtu <mtu-value>Activate the connection to apply the change:
sudo nmcli connection up "<connection-name>"Verify the new MTU:
ip link show "<device-name>"
Add, replace, or remove an IP address
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/24Activate the connection:
sudo nmcli connection up "<connection-name>"Verify:
ip address show "<device-name>"
Change MAC address
Set a cloned MAC address: Replace
<new-mac-address>with the MAC 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>Activate the connection:
sudo nmcli connection up "<connection-name>"
Add, replace, or remove a route
Modify the route: The format is
<destination> <gateway>. This example routes traffic for198.51.100.0/24through gateway192.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"Activate the connection:
sudo nmcli connection up "<connection-name>"Verify:
ip route show
Add, replace, or remove a routing rule
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"Activate the connection:
sudo nmcli connection up "<connection-name>"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.
View device status
nmcli device statusSample 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/24Add, 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
Monitor real-time network events such as connection state changes and device status updates:
nmcli monitorPress Ctrl+C to stop monitoring.