Persistent Network Configuration - ip, nmcli, NetworkManager

Persistent Network Configuration - ip, nmcli, NetworkManager

What You Will Achieve

  • Set a temporary IP and route with ip, and explain why those settings disappear on reboot
  • Persistently set a static IP and default gateway with nmcli on NetworkManager systems
  • Write persistent configuration with netplan (Ubuntu) and ifcfg files (Red Hat family)
  • Persist the hostname with hostnamectl and /etc/hostname
  • Avoid the classic accidents caused by confusing "temporary" and "persistent" configuration

This is the core of LPIC-1 objective 109.2 "Basic network configuration" (exam 102, weight 4). The skill tested is configuring with a clear awareness of whether settings survive a reboot.

How Do Temporary and Persistent Config Differ?

A setting applied with ip only rewrites the kernel's live state directly, so it disappears on reboot. To persist it, you register it in a configuration file or a manager such as NetworkManager.

Mixing up the two leads to "I configured it but it vanished after reboot" or "I wrote it to a file but it does not take effect". Here is how the roles break down.

Type Means When it applies After reboot
Temporary ip addr / ip route / ip link Immediately Lost
Persistent (NM) nmcli connection modify + up On up Kept
Persistent (Ubuntu) /etc/netplan/*.yaml + netplan apply On apply Kept
Persistent (Red Hat) ifcfg-* + ifup / reboot On ifup Kept

A production rule of thumb: first set it temporarily with ip and verify connectivity, then copy the same content into the persistent configuration. Editing only the persistent file first means a mistake can lock you out after a reboot, making recovery hard.

Setting Temporarily with the ip Command

ip is the current standard tool provided by iproute2. In the form ip OBJECT COMMAND, it operates on address (IP), link (interface), and route (routing).

The legacy ifconfig / route are no longer maintained and have been replaced by ip. Learn ip as your baseline for both the exam and real work.

Check the current state

ip addr show
ip link show
ip route show
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
    inet 192.168.1.10/24 brd 192.168.1.255 scope global eth0
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10

ip addr show shows IP addresses and ip route show shows the routing table. addr is short for address and can be abbreviated to a.

Add and delete an IP address

ip address add 192.168.1.20/24 dev eth0
ip address del 192.168.1.20/24 dev eth0

The official syntax is ip address add IFADDR dev IFNAME, and to delete, ip address del IFADDR dev IFNAME. IFADDR is given as "address/prefix length", such as 192.168.1.20/24.

Bring an interface up / down

ip link set eth0 up
ip link set eth0 down

ip link set IFNAME up enables it and down disables it. Even if an IP is assigned, no traffic flows while the link is down.

Set the default gateway

ip route add default via 192.168.1.1 dev eth0
ip route del default via 192.168.1.1 dev eth0

This points the route to default (= 0.0.0.0/0) at the gateway given with via. That is what setting a default gateway means. ip route del deletes using the same arguments as add.

Everything done with ip so far is temporary. It disappears on reboot. In production, the persistence covered below is mandatory.

Persisting with nmcli

On NetworkManager systems, rewriting a connection profile with nmcli connection modify saves the content to disk and makes it persistent. Reactivate with nmcli connection up to apply it.

NetworkManager is the default on many desktop and server distributions. It manages settings per profile and operates on a different layer from the temporary ip settings.

Check connections and devices

nmcli connection show
nmcli device status
NAME                UUID                                  TYPE      DEVICE
Wired connection 1  abcd1234-...                          ethernet  eth0

DEVICE  TYPE      STATE      CONNECTION
eth0    ethernet  connected  Wired connection 1

nmcli connection show lists connection profiles and nmcli device status shows how they map to devices. connection can be shortened to con and device to dev.

Persist a static IP

nmcli connection modify "Wired connection 1" \
  ipv4.method manual \
  ipv4.addresses 192.168.1.10/24 \
  ipv4.gateway 192.168.1.1 \
  ipv4.dns 8.8.8.8
nmcli connection up "Wired connection 1"
Connection successfully activated ...

ipv4.method manual switches to static (manual), then ipv4.addresses, ipv4.gateway, and ipv4.dns set the values. The profile is saved at the modify step, and up applies the actual settings. To revert to DHCP, set ipv4.method auto.

Create a new profile

nmcli connection add type ethernet ifname eth0 \
  ipv4.method manual ipv4.addresses 192.168.1.10/24 \
  ipv4.gateway 192.168.1.1 ipv4.dns 8.8.8.8

nmcli connection add creates a new connection. Changes via connection add / modify are persistent (saved to disk) by default, and become temporary only when you add --temporary.

Persisting with netplan (Ubuntu)

Ubuntu writes configuration in YAML to /etc/netplan/*.yaml and applies it with netplan apply. netplan is a renderer that bridges settings to a backend (NetworkManager or systemd-networkd).

YAML is strict about indentation and forbids tabs (spaces only). Learn the structure of the configuration file.

A static IP YAML example

ls /etc/netplan/
01-netcfg.yaml
network:
    version: 2
    ethernets:
        eth0:
            addresses:
                - 192.168.1.10/24
            routes:
                - to: default
                  via: 192.168.1.1
            nameservers:
                addresses:
                    - 8.8.8.8
                    - 8.8.4.4

The default gateway is expressed with to: default + via under routes. addresses is a list of "address/prefix length".

Apply the configuration

netplan try
netplan apply

netplan apply applies the configuration. netplan try automatically rolls back after a timeout, preventing lockout accidents during remote work.

Red Hat Family ifcfg Files

In the traditional Red Hat method, configuration is written to /etc/sysconfig/network-scripts/ifcfg-<device> and applied with ifup / ifdown or a reboot.

In environments that also use NetworkManager, changes made via nmcli may be written to these ifcfg files. Know which one manages your interface.

A static IP ifcfg example

cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.10
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8

Key directives: BOOTPROTO=none (or static) for static, dhcp for DHCP. ONBOOT=yes enables it automatically at boot. IPADDR / PREFIX (or NETMASK) / GATEWAY / DNS1 set the address fields.

Apply with ifup / ifdown

ifdown eth0
ifup eth0

ifup <device> enables an interface and ifdown disables it. After editing an ifcfg file, reload it with ifdown then ifup.

Persisting the Hostname

Setting the static hostname with hostnamectl hostname <name> writes it to /etc/hostname, so it survives a reboot. hostnamectl status shows the current hostnames.

There are three hostname types: static, transient, and pretty. Persistence targets the static one, whose backing store is /etc/hostname.

hostnamectl status
hostnamectl hostname host01
hostnamectl status
   Static hostname: localhost
   Static hostname: host01

hostnamectl hostname host01 is the current systemd form. The older hostnamectl set-hostname host01 means the same thing and persists to /etc/hostname.

After changing the hostname, also add the new name to the 127.0.0.1 (or 127.0.1.1) line in /etc/hosts. Forgetting this causes name-resolution warnings or delays in some applications.

Common Mistakes and How to Avoid Them

Failed network configuration directly causes loss of connectivity. Keep these five frequent pitfalls in mind.

  • ip settings disappear on reboot: ip addr / ip route are temporary. To persist, copy them into nmcli, netplan, or ifcfg
  • Double management of nmcli and ifcfg: Editing an ifcfg file directly for an interface managed by NetworkManager causes conflicts. Standardize on one
  • Forgetting netplan apply: Editing the YAML alone does not apply it. Always run netplan apply (or netplan try when remote)
  • Still using ifconfig / route: These deprecated legacy tools are replaced by ip addr / ip route. Use ip as the baseline for exam and work
  • Forgetting to run up after nmcli modify: modify only saves the profile. Without nmcli connection up NAME to reactivate, it does not apply to the live settings

Troubleshooting

Symptom: IP configuration disappeared after reboot

Cause: Only a temporary setting like ip addr add was used, with nothing written to persistent config

Check:

ip addr show
nmcli connection show

Fix: On NetworkManager, persist with nmcli connection modify; on Ubuntu, write it into /etc/netplan/*.yaml. Copy the temporary content into the persistent side.

Symptom: Edited the netplan YAML but nothing changed

Cause: netplan apply was not run, or there is a YAML indentation error (tabs mixed in)

Check:

netplan try

Fix: Apply with netplan apply. If netplan try reports an error, review the YAML (no tabs, use space indentation).

Symptom: Configured with nmcli but the current IP did not change

Cause: nmcli connection modify only saved it; the connection was not reactivated

Check:

nmcli device status

Fix: Reactivate with nmcli connection up "connection name". This applies the saved profile to the live settings.

Completion Checklist

  • [ ] Checked the current settings with ip addr show / ip route show
  • [ ] Understood the difference between temporary (ip) and persistent config
  • [ ] Persisted a static IP with nmcli, netplan, or ifcfg
  • [ ] Persisted the default gateway
  • [ ] Persisted the hostname with hostnamectl hostname
  • [ ] Confirmed the settings remain after a reboot or service restart

Summary

Environment Persistence means Apply command
Temporary (all) ip addr / ip route Immediate (lost on reboot)
NetworkManager nmcli connection modify nmcli connection up
Ubuntu /etc/netplan/*.yaml netplan apply
Red Hat family ifcfg-* ifup / reboot
Hostname /etc/hostname hostnamectl hostname

The key to network configuration is always being aware of "temporary or persistent". Master the pattern of trying it quickly with ip and copying it to the persistent side once it works, and you will avoid both reboot-vanishing accidents and apply-forgotten failures.

Next Reading

Continue Your LPIC-1 Journey

LPIC-1 Hub

  • LPIC-1 Learning Hub — Full LPIC-1 article map, progress tracking, and exam objective coverage

Practice