Sub topic 11
Applying the Configuration and Verifying It
This chapter covers the last step of a network change: putting it into effect and proving that it works. It assumes you have already written a Netplan file or an NetworkManager profile, and you set a hostname. It also assumes you can read ip output, use sudo, and reach the server's console or out-of-band access if SSH drops. The aim is to check each layer in order. That way a failure points to one cause instead of "the network is broken".
Writing a Change Is Not Applying It
Each tool separates the stored configuration from the running state. A correct file can sit on disk while the interface still uses the old address.
| Setting | Where it is stored | What puts it into effect |
|---|---|---|
| Netplan YAML | `/etc/netplan/*.yaml` | `netplan try` or `netplan apply` |
| NetworkManager profile | `/etc/NetworkManager/system-connections/` | `nmcli connection up` or `nmcli device reapply` |
| Static hostname | `/etc/hostname` | `hostnamectl set-hostname` does both at once |
| `/etc/hosts` | `/etc/hosts` | Read on every lookup, so it takes effect immediately |
| DNS servers | The renderer's configuration | Applying the network change, then `resolvectl status` to confirm |
/etc/hosts needs no reload because the resolver library reads it on each lookup. A typo there therefore takes effect at once, so check it as soon as you save it.
Applying Netplan Changes
Netplan reads YAML and generates configuration for a renderer, either networkd or NetworkManager. Three commands matter:
netplan generatewrites the backend configuration without applying it. It reports syntax and schema errors.netplan tryapplies the configuration and waits for you to press Enter. If you do not confirm within the timeout (120 seconds by default), it reverts.netplan applyapplies the configuration permanently, with no rollback.
sudo chmod 600 /etc/netplan/01-static.yaml
sudo netplan generate
sudo netplan try --timeout 60
sudo netplan applyNetplan warns about files that other users can read, because they can contain Wi-Fi passwords or keys. Setting mode 600 removes the warning and is the correct permission even on a wired server.
Run netplan try first on any remote server. If the new address or route is wrong, your SSH session freezes and you never confirm. The rollback then restores the old configuration, and you can reconnect on the old address. The order of operations is:
Two details can surprise you. First, netplan try needs an interactive terminal, so you cannot use it in a script or from a non-interactive ssh host command invocation. Second, if you change the address you are connected to, your existing SSH session will not survive even when the change is correct, because the TCP connection is bound to the old address. In that case, confirm from a second session on the new address before the timeout expires.
To see what Netplan thinks the final merged configuration is, use sudo netplan get. Netplan merges all files in /etc/netplan/, /run/netplan/ and /lib/netplan/ in lexical order. A leftover 50-cloud-init.yaml that still sets dhcp4: true for the same interface is a common reason a static address appears alongside a DHCP one.
Applying NetworkManager Changes
nmcli connection modify edits the profile only. The running connection does not change until you reactivate it.
nmcli connection show
sudo nmcli connection modify "Wired connection 1" \
ipv4.method manual \
ipv4.addresses 192.168.1.50/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "192.168.1.1 9.9.9.9" \
ipv4.dns-search example.com
sudo nmcli connection up "Wired connection 1"NetworkManager has no equivalent of netplan try. A wrong value can lock you out with no automatic recovery. Two habits reduce the risk:
- Work from the console if you can.
- Otherwise schedule a revert before you start. Use
ator a backgroundsleepto bring the old profile back. For example,( sleep 120; nmcli connection up "old-profile" ) &runs the revert in the background. Kill it once you have confirmed the new setup works.
After up, compare the stored profile with the live state. nmcli -f ipv4 connection show "Wired connection 1" prints the profile's settings, including ipv4.method, ipv4.addresses, and ipv4.dns. nmcli device show enp1s0 prints the values actually in use, which are the lines starting with IP4.. A mismatch between the two usually means the profile was never reactivated.
If you set ipv4.method manual but forget ipv4.addresses, NetworkManager refuses the change. If you leave an old ipv4.addresses line in a profile you switched back to auto, the profile keeps both. Clear it with nmcli connection modify "Wired connection 1" ipv4.addresses "".
Applying the Hostname
hostnamectl set-hostname needs no separate apply step. It writes /etc/hostname and updates the kernel's running hostname together.
sudo hostnamectl set-hostname web01.example.com
hostnamectl --static
hostname
hostname -fhostnamectl --static prints the stored value. hostname prints the running value, and the two should match. hostname -f prints the fully qualified name, and it works by resolving the hostname through the normal lookup path. If /etc/hosts has no matching line, hostname -f can fail or return only the short name. That is the most common sign that /etc/hosts is inconsistent with the hostname.
Long-running programs may have read the old hostname at startup. A mail server or logging agent that cached it keeps using the old name until you restart it. A reboot is the thorough way to rule that out.
Verifying in Layers
Verify from the bottom of the stack upward. Each check depends on the one before it, so the first failure shows where to look.
- The interface has the right address and prefix length.
- The kernel has the right default route.
- The gateway answers.
- An outside IP address is reachable, which proves routing and NAT beyond the gateway.
- The resolver answers DNS queries.
- The whole system, including
/etc/hostsandnsswitch.conf, resolves names.
ip -br address show dev enp1s0
ip route show default
ip route get 9.9.9.9
ping -c 3 192.168.1.1
ping -c 3 9.9.9.9
resolvectl query example.com
getent hosts example.comRead the output carefully:
ip -br addressshould show192.168.1.50/24and stateUP. A leftover address from DHCP next to it means the old lease was not removed. A/32or/16where you expected/24means the prefix length is wrong, which breaks which addresses count as local.ip route show defaultshould showdefault via 192.168.1.1 dev enp1s0. A second default route with a differentmetricmeans another profile or interface is competing. The lowest metric wins.ip route get 9.9.9.9shows the exact route, source address, and interface the kernel would use. If thesrcaddress is not the one you set, something else is in play.- A reply from
9.9.9.9with no reply from the gateway is unusual and points to ICMP filtering. A reply from the gateway but not from9.9.9.9points to the gateway's own upstream.
Two Name Checks Answer Different Questions
resolvectl query example.com asks systemd-resolved directly. It bypasses /etc/hosts and nsswitch.conf. getent hosts example.com goes through the Name Service Switch, so it is the lookup that most programs use. Run both. When resolvectl works and getent fails, look at /etc/nsswitch.conf, the hosts: line, and /etc/hosts. When both fail, look at the DNS servers.
Run resolvectl status to confirm which servers and search domains the interface received. Check that the DNS Servers and DNS Domain lines under your link match what you configured. A global entry for another server is a sign that some other setting overrides yours.
Check the search domain with a short name. If example.com is your search domain, getent hosts db01 should resolve db01.example.com when that record exists.
The server's own name should also resolve locally:
getent hosts "$(hostname)"
getent hosts "$(hostname -f)"Both should return the address from your /etc/hosts line. If they return nothing, the hosts entry does not match the hostname you set.
A Repeatable Check Script
Typing the same checks after every change invites mistakes. This script runs each layer and prints one line per result. Adjust the variables at the top for your server.
#!/usr/bin/env bash
set -u
IFACE=enp1s0
ADDR=192.168.1.50/24
GW=192.168.1.1
NAME=example.com
HOST=web01.example.com
check() {
local label=$1
shift
if "$@" >/dev/null 2>&1; then
printf 'PASS %s\n' "$label"
else
printf 'FAIL %s\n' "$label"
fi
}
check "address $ADDR on $IFACE" \
bash -c "ip -4 -o address show dev $IFACE | grep -qF ' $ADDR '"
check "default route via $GW" \
bash -c "ip route show default | grep -qF 'via $GW'"
check "gateway $GW answers ping" ping -c 2 -W 2 "$GW"
check "outside address 9.9.9.9 answers ping" ping -c 2 -W 2 9.9.9.9
check "resolver answers for $NAME" resolvectl query "$NAME"
check "system lookup works for $NAME" getent hosts "$NAME"
check "static hostname is $HOST" \
bash -c "[ \"\$(hostnamectl --static)\" = '$HOST' ]"
check "own name resolves locally" getent hosts "$HOST"Save it as netcheck.sh and run bash netcheck.sh. The first FAIL line tells you which layer to inspect. Later failures often follow from the first one, so fix them in order.
Proving the Change Survives a Reboot
A change that works now but disappears at boot is a failure that shows up weeks later. After the checks pass, confirm persistence in two ways:
- Check that nothing depends on a manual step. Run
ip -br addressand compare it with the file. An address you added withip address addworks immediately but does not survive a reboot, and it does not appear in any configuration. - If the server can be rebooted, reboot it and run the script again. Do this at a time when a failed boot is acceptable, and keep console access ready.
sudo rebootAfter reconnecting, run bash netcheck.sh again. A change that passes before and after the reboot is stored correctly.
Common Surprises When Verifying
- The address is correct but the gateway is not reachable. The prefix length is probably wrong, so the gateway sits outside the subnet the kernel believes is local. Compare the
/24in your file with the real network. - Name lookups work for
resolvectlbut not for an application. The application may bypass the system resolver, for example by reading/etc/resolv.confdirectly./etc/resolv.confwithsystemd-resolvedis usually a symlink to a stub file that points to127.0.0.53, so checkls -l /etc/resolv.conf. - A duplicate IP address causes intermittent failures. Another machine already uses
192.168.1.50.sudo arping -D -I enp1s0 -c 3 192.168.1.50checks for a duplicate. Run it before applying a new static address when the network has no address reservation system. - Pings to a name succeed but SSH to it fails. Check whether the name resolves to an IPv6 address first. IPv6 settings are separate from the IPv4 settings in this tutorial.
Exercise
After you run sudo nmcli connection modify "Wired connection 1" ipv4.addresses 192.168.1.60/24, ip -br address still shows the old address. Why, and what do you run next?
Show answer
nmcli connection modify only edits the stored profile. The running connection keeps its old state until it is reactivated. Run sudo nmcli connection up "Wired connection 1", then check ip -br address show dev enp1s0 again.
Exercise
resolvectl query example.com succeeds, but getent hosts example.com returns nothing. Which two places do you inspect, and why?
Show answer
Inspect the hosts: line in /etc/nsswitch.conf and the contents of /etc/hosts. resolvectl asks the resolver directly, while getent follows the Name Service Switch order. A missing dns or resolve source in nsswitch.conf, or a wrong entry in /etc/hosts that matches first, would explain the difference.
Exercise
You apply a new static address over SSH with netplan try, and your terminal freezes. What happens next, and what should you do?
Show answer
If you do not press Enter before the timeout expires, Netplan reverts to the previous configuration. Wait for the timeout, reconnect on the old address, and correct the file. If the cause was only that the address you were connected to changed, open a second session on the new address before the timeout and confirm from there.