Lab: Creating a New Network Connection (nmcli)

Use NetworkManager CLI to create and manage network profiles on Linux.

← Back to Lab Main

Prerequisites

This guide requires:

1. Identify Network Interfaces

Check which network interfaces are available:

nmcli device status

Example output:


DEVICE   TYPE      STATE      CONNECTION
ens160   ethernet  connected  Wired connection 1
            

2. Create a New Static Connection

Create a new connection profile named static-prod with a static IP:


sudo nmcli connection add \
type ethernet \
ifname ens160 \
con-name static-prod \
ipv4.method manual \
ipv4.addresses 192.168.1.50/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns 192.168.1.10
            

Explanation:

3. Activate the New Connection


sudo nmcli connection up static-prod
            

This applies the profile to the interface and assigns the static IP.

4. Verify the Connection


ip addr show ens160
nmcli connection show --active
            

You should see static-prod active with the correct IP.

5. Manage Existing Profiles (Optional)

Disable autoconnect for old profiles to avoid conflicts:


sudo nmcli connection modify "Wired connection 1" connection.autoconnect no
sudo nmcli connection up "Wired connection 1"  # To switch back if needed
            

This allows safe switching between multiple profiles on the same interface.