Sub topic 11
Applying the Configuration and Verifying It
Assume you can use a shell, edit network configuration files, run commands with sudo, and understand IPv4 addresses, prefixes, gateways, and DNS. This chapter focuses on applying a configuration safely and proving that the server uses it.
Apply changes without losing access
Network changes can interrupt SSH. A typo in the address, prefix length, gateway, or DNS settings may disconnect the server. Prefer a console or out-of-band connection when one is available. Otherwise, keep an existing SSH session open while testing the new configuration.
Netplan provides a rollback-aware command. netplan try applies the configuration temporarily and waits for confirmation. If you do not confirm it, Netplan rolls it back.
sudo chmod 600 /etc/netplan/01-static.yaml
sudo netplan try
sudo netplan applyThe file permissions protect network details from other users. During netplan try, test the connection from a second terminal. Confirm the change only after the address, route, and name resolution work. Run netplan apply after confirmation to apply the saved configuration normally.
On a NetworkManager system, reactivate the connection profile after changing it:
sudo nmcli connection up "Wired connection 1"The connection name must match a profile shown by nmcli connection show. Bringing the profile up may briefly interrupt the session.
Verify each layer
Verification should proceed from the local interface outward. First confirm the address. Then confirm the route, gateway, DNS resolver, and hostname. Testing in this order helps identify the layer that failed.
ip -br address show dev enp1s0
ip route get 9.9.9.9
resolvectl query example.com
getent hosts example.com
ping -c 3 192.168.1.1
hostnamectl --staticip -br address shows the address and prefix assigned to the interface. The prefix must match the intended network. For example, 192.168.1.50/24 places the server in the 192.168.1.0/24 network.
ip route get shows the route the kernel would use for a destination. Its output should name the expected interface and usually the configured gateway. This command is more useful than checking only whether a default route exists.
resolvectl query tests the system resolver, including the configured DNS servers. getent hosts tests the full name-service path selected by /etc/nsswitch.conf. These commands can produce different results when /etc/hosts, local caching, or another name service takes precedence.
ping tests reachability of the gateway. A successful gateway test does not prove that the internet or DNS works, but failure usually points to the interface, address, prefix, cable, virtual network, or gateway configuration.
Verify the hostname and resolver
Check both the running hostname and the stored hostname:
hostnamectl
hostnamectl --static
cat /etc/hosts
resolvectl statusThe hostname should match the name used in /etc/hostname and, where appropriate, in /etc/hosts. A local entry can prevent unnecessary DNS queries for the server's own name.
resolvectl status shows the DNS servers and search domains associated with each link. A search domain changes how an unqualified name such as db01 is expanded. It does not replace a fully qualified name such as db01.example.com.
Diagnose failures by layer
| Symptom | Likely layer | Useful check |
|---|---|---|
| Address is missing | Interface or configuration | `ip -br address show` |
| Gateway is unreachable | Prefix, link, or gateway | `ip route` and `ping` |
| IP addresses work but names fail | Resolver or DNS | `resolvectl status` |
| `resolvectl` works but applications fail | Name-service order | `getent hosts` and `/etc/nsswitch.conf` |
A wrong prefix length is a common cause of failure. With /24, the server treats 192.168.1.1 as local. With /16, it treats a much larger range as local. With /25, addresses above 192.168.1.127 may belong to another subnet. The result can be an incorrect route or failed gateway access.
If the address is correct but external destinations fail, inspect the default route:
ip route show
ip route get 9.9.9.9If the route is correct but names fail, query a known DNS server directly when supported, then inspect resolvectl status. If getent hosts fails while resolvectl query succeeds, inspect /etc/nsswitch.conf and ensure its hosts line includes the expected sources, commonly files and dns.
Exercise
The server can ping its gateway and ip route get 9.9.9.9 shows the correct default route, but getent hosts example.com returns nothing. Which layer should you inspect first?
Show answer
Inspect the resolver configuration and name-service path. Check resolvectl status, run resolvectl query example.com, and inspect the hosts entry in /etc/nsswitch.conf.