Skip to main content
RunBook Academy

← All labs in Linux

Lab · intermediate · ~45 min

Lab: Configure a static connection with nmcli and verify it

B · Nested virtualisationC · Simulation

Objectives

  • Create a static connection profile with nmcli
  • Modify the profile to add a secondary IP and route
  • Switch between static and DHCP without losing the profile
  • Verify the result with nmcli and ip

Prerequisites

This lab creates and tunes a NetworkManager connection profile from the command line. It is the canonical exercise for managing network state on RHEL-family hosts.

Objective

By the end of this lab, you can:

  • Create a static Ethernet profile with nmcli.
  • Add a secondary IP and a custom route to the profile.
  • Switch the profile between static and DHCP.
  • Verify the result with nmcli and ip.
  • Revert the change cleanly.

Architecture

The host has:

  • One Ethernet interface eth0 currently managed by NetworkManager.
  • One active connection profile (typically “Wired connection 1” or similar).

You will replace the existing profile with a static profile called eth0-static, modify it, and verify each step.

Tasks

Task 1: Read the current state

nmcli general status
nmcli device status
nmcli -t -f NAME,UUID,TYPE,DEVICE connection show
nmcli connection show "Wired connection 1"   # or the active name
ip addr show eth0
ip route show

Write down the active connection’s name and UUID. You will need the UUID when removing or modifying.

Task 2: Create the static profile

sudo nmcli connection add \
  type ethernet \
  con-name eth0-static \
  ifname eth0 \
  ipv4.method manual \
  ipv4.addresses 10.20.0.50/24 \
  ipv4.gateway 10.20.0.1 \
  ipv4.dns "1.1.1.1,8.8.8.8" \
  ipv4.dns-search lab.local \
  ipv6.method manual \
  ipv6.addresses "2001:db8:20:20::50/64" \
  ipv6.gateway "fe80::1" \
  ipv6.dns "2001:4860:4860::8888" \
  connection.autoconnect yes \
  connection.autoconnect-priority 10

Note connection.autoconnect-priority 10 - higher than the default. The static profile will win on boot even if a DHCP profile also exists.

Activate it:

sudo nmcli connection up eth0-static

Task 3: Verify

nmcli connection show eth0-static
nmcli -f all connection show eth0-static
ip addr show eth0
ip route show
ip -6 route show
cat /etc/resolv.conf

Confirm:

  • IPv4: 10.20.0.50/24 on eth0.
  • IPv6: 2001:db8:20:20::50/64 on eth0.
  • Default routes via both gateways.
  • DNS servers present.

Task 4: Add a secondary IP and route

sudo nmcli connection modify eth0-static \
  +ipv4.addresses 10.20.0.51/24

sudo nmcli connection modify eth0-static \
  +ipv4.routes "10.30.0.0/24 10.20.0.1"

sudo nmcli connection down eth0-static
sudo nmcli connection up eth0-static

Verify:

ip addr show eth0
ip route show 10.30.0.0/24

The secondary IP and the custom route should both be present.

Task 5: Test end-to-end

ping 10.20.0.1            # gateway
ping 1.1.1.1              # public IP
ping google.com            # DNS + public IP
dig example.com            # explicit DNS test

All four should succeed.

Task 6: Switch to DHCP temporarily

sudo nmcli connection modify eth0-static \
  ipv4.method auto \
  -ipv4.addresses \
  -ipv4.gateway \
  -ipv4.dns \
  -ipv4.dns-search

sudo nmcli connection down eth0-static
sudo nmcli connection up eth0-static

ip addr show eth0

The IP should change to whatever DHCP assigns. The profile is still there, just empty.

Task 7: Switch back to static

sudo nmcli connection modify eth0-static \
  ipv4.method manual \
  ipv4.addresses 10.20.0.50/24 \
  ipv4.gateway 10.20.0.1 \
  ipv4.dns "1.1.1.1,8.8.8.8" \
  ipv4.dns-search lab.local

sudo nmcli connection down eth0-static
sudo nmcli connection up eth0-static

ip addr show eth0

Confirm the static IP is back. The profile survived the DHCP round-trip.

Task 8: Make the static profile win on boot

If there is still a DHCP profile that might activate on boot:

sudo nmcli connection modify "Wired connection 1" \
  connection.autoconnect no

Or remove it entirely:

sudo nmcli connection delete "Wired connection 1"

The eth0-static profile is now the only one that can activate on eth0.

Validation

  • The eth0-static profile exists and is the active profile on eth0.
  • The static IPs, routes, and DNS are in place.
  • The profile survived a switch to DHCP and back.
  • The DHCP profile cannot win on boot (autoconnect disabled or profile removed).

Cleanup

Restore the DHCP profile and remove the static one (or keep both, your choice):

sudo nmcli connection modify "Wired connection 1" \
  connection.autoconnect yes   # if it exists
sudo nmcli connection delete eth0-static

What you learned

  • nmcli connection add creates a profile; nmcli connection modify changes it; nmcli connection up activates it.
  • + adds to a list (+ipv4.addresses); - removes from a list (-ipv4.dns).
  • Emptying fields before changing the method prevents stale values from confusing the new configuration.
  • NetworkManager profiles persist across DHCP/static switches.

Deliverables

  • · A working NetworkManager connection profile
  • · Output of nmcli and ip before and after each change
  • · Documentation of how to roll back to DHCP

Verification status

Last reviewed
2026-08-09
Executed end to end
not yet run on hardware

The commands and configuration here have been reviewed against the verified software versions, but nobody has run this lab start to finish on a system meeting its prerequisites. Treat the Expected Outcome as the intended result rather than an observed one, and keep the Cleanup section to hand.