Sub topic 12
Troubleshooting common failures
This chapter assumes you can read ip output, you know what a prefix length and a default gateway are, and you have already applied a static configuration with Netplan or NetworkManager. It gives you a repeatable way to find out why a server cannot reach the network or cannot resolve names, and it lists the failures you will meet most often.
Work from the bottom up
Network problems have layers. A name lookup needs a working route, and a route needs an address on a live link. If you test from the top, for example by opening a web page, every failure looks the same. Test from the bottom and stop at the first layer that fails.
The five checks below follow this diagram.
Step 1: Is the link up and is the address present?
Start with the same commands you used to inspect the server before you changed anything.
ip -br link show
ip -br address showLook at three things:
- The interface state.
UPmeans the link is active.DOWNmeans the interface is disabled or has no carrier.NO-CARRIERin the flags means no cable or virtual link is connected. - Whether the address you expect appears on the interface.
- Whether the interface name matches your configuration file.
Wrong interface name
A frequent cause of "my static IP did not apply" is a typo or a stale interface name in the configuration. Netplan matches on the name you write, such as enp1s0. If the real interface is ens18, Netplan has nothing to configure and the interface keeps whatever it had before, or nothing at all. Compare the names:
ip -br link show
grep -n "enp\|ens\|eth" /etc/netplan/*.yamlConfiguration written but never applied
If the file is correct but the address is missing or old, the change was probably not applied. Run sudo netplan apply for Netplan, or sudo nmcli connection up "<name>" for NetworkManager. A nmcli connection modify alone changes the stored profile and does not change the running connection.
Netplan syntax and permission problems
Netplan is strict about YAML. Use spaces only, keep indentation consistent, and keep the file readable only by root. Run the generator to see errors:
sudo netplan generateRecent Netplan versions warn when a file is readable by other users. Set the mode with sudo chmod 600 /etc/netplan/01-static.yaml. If you have several files in /etc/netplan/, they are merged in alphabetical order, and later files override earlier ones. A leftover cloud-init file such as 50-cloud-init.yaml can therefore fight with your file, for example by setting dhcp4: true on the same interface. List the directory and read every file.
ls -l /etc/netplan/
sudo netplan getnetplan get prints the merged result, which is what Netplan will actually use.
Two tools managing the same interface
If NetworkManager and systemd-networkd both try to manage one interface, you can see addresses appear and disappear. Check which one owns the interface:
networkctl status enp1s0
nmcli device statusIn the nmcli output, a device shown as unmanaged is not controlled by NetworkManager. In networkctl, a setup state of configured means systemd-networkd manages it. Pick one tool per interface and set the renderer in Netplan to match.
Step 2: Is the gateway reachable?
With an address in place, test the next hop.
ping -c 3 192.168.1.1
ip neigh show 192.168.1.1If the ping fails, ip neigh helps you decide why. The state REACHABLE or STALE means the gateway answered ARP (Address Resolution Protocol, which maps an IPv4 address to a hardware address on the local network) at some point. The state FAILED or INCOMPLETE means nobody on the local network answered for that address.
Wrong prefix length
The prefix length decides which addresses the server treats as local. With 192.168.1.50/24, the local range is 192.168.1.0 to 192.168.1.255. If you wrote /16 or /32 by mistake, the server draws the local boundary in the wrong place.
- A prefix that is too long, such as
/32, leaves the gateway outside the local range. The kernel then has no connected route to the gateway and cannot send it ARP requests. Adding the default route fails or the route is ignored. - A prefix that is too short, such as
/16on a/24network, makes the server try to reach addresses in the larger range directly. Hosts that are really on a different network become "unreachable" because the server sends ARP requests instead of using the gateway.
Check the connected route:
ip route showYou should see a line like 192.168.1.0/24 dev enp1s0 proto kernel scope link src 192.168.1.50. If the network part is not what your network team gave you, fix the prefix length.
Wrong gateway address
The gateway must be inside the server's own subnet. If the gateway is 192.168.2.1 but the server is 192.168.1.50/24, the route cannot be used. Confirm the gateway with your network documentation. It is not always .1.
Duplicate address
If another machine already uses 192.168.1.50, both machines get intermittent failures. Test from another machine on the same network with arping:
sudo arping -D -I enp1s0 -c 3 192.168.1.50Run it before assigning the address, or from a different host. A reply from a hardware address that is not yours points to a conflict. Choose an address outside the DHCP pool, or reserve it in the DHCP server.
Link layer problems
If the address and prefix are right and ARP still fails, the problem is below IP. Check the cable, the switch port, the VLAN assignment, and, on a virtual machine, the virtual switch or bridge the guest is attached to.
Step 3: Can the server reach an outside IP address?
Use a public address, not a name, so DNS cannot interfere.
ip route get 9.9.9.9
ping -c 3 9.9.9.9ip route get shows which route and source address the kernel will use. The output should name your gateway in a via field and your interface in dev. If it says RTNETLINK answers: Network is unreachable, there is no default route. Look at it directly:
ip route show defaultMissing default route
An empty result means no default route. The cause is usually a missing routes: block in Netplan, a missing ipv4.gateway in NetworkManager, or a gateway that was rejected because of a wrong prefix. Add the gateway and apply again.
Two default routes
With two network interfaces, you can end up with two default routes. The kernel picks the one with the lowest metric. Traffic may leave through the wrong interface, and replies may not come back. Show them with ip route show default. Keep one default route unless you intend to run multi-homed routing, and give the less preferred route a higher metric.
Gateway reachable but outside is not
If the gateway responds and the default route is correct but 9.9.9.9 does not, the fault is beyond your server. Look at upstream firewall rules, NAT, or ISP and cloud security groups. A local firewall can also block outbound traffic, so check sudo nft list ruleset or sudo iptables -S if you have configured one.
Step 4: Does DNS work?
Now test the resolver. Compare a direct DNS query with the system lookup.
resolvectl status
resolvectl query example.comReading the symptoms
| Symptom | Likely cause |
|---|---|
| `ping 9.9.9.9` works, `ping example.com` fails | DNS servers wrong or unreachable |
| `resolvectl query` times out | Listed DNS server does not answer from this network |
| `resolvectl query` works for full names, not short ones | Search domain missing or wrong |
| `Failed to resolve ... Link has no DNS servers` style message | No DNS servers set on that interface |
| Lookups work for a minute, then stop | Another tool overwrites the resolver settings |
DNS servers wrong or unreachable
resolvectl status lists DNS servers per interface. Confirm that the servers you configured appear under your interface. Then test a server directly, which bypasses the local resolver:
dig @192.168.1.1 example.com +short
dig @9.9.9.9 example.com +shortIf one server answers and the other does not, remove the dead one or put the working one first. A dead first server causes a long delay on every lookup, because the resolver waits for it to time out before it tries the next one. If dig is not installed, use resolvectl query or install the dnsutils package (bind-utils on RHEL-style systems).
Search domain surprises
A search domain is a suffix that the resolver appends to short names. With search: [example.com], the name db01 is tried as db01.example.com. Problems come from a missing search domain, a typo, or an unexpected one handed out by DHCP. Check what is active:
resolvectl domainThe resolver file is not what you think
On a system that uses systemd-resolved, /etc/resolv.conf is normally a symbolic link to a file that points to the local stub resolver at 127.0.0.53. This is correct. Do not replace it with a file listing your servers by hand unless you have removed systemd-resolved on purpose. Check the link:
ls -l /etc/resolv.confIf /etc/resolv.conf is a regular file that was edited by hand, or was written by another tool, changes you make in Netplan or NetworkManager will not appear in it. Likewise, if systemd-resolved is stopped, the stub address has nothing listening:
systemctl status systemd-resolvedRestart it with sudo systemctl restart systemd-resolved and recheck.
Step 5: Does the system name lookup agree?
resolvectl query talks to the resolver. Most programs do not. They use the C library, which follows the order in /etc/nsswitch.conf. Test that path with getent:
getent hosts example.com
getent hosts web01
grep '^hosts:' /etc/nsswitch.confIf resolvectl query succeeds and getent hosts fails, the problem is in the name service order, not in DNS. If getent hosts returns a different address from DNS, an entry in /etc/hosts is probably overriding it, since files usually comes before dns in the hosts: line.
Hostname that does not resolve
A common symptom is a slow sudo command, or a warning such as unable to resolve host web01. The server cannot resolve its own hostname. Check that the name you set with hostnamectl appears in /etc/hosts:
hostnamectl --static
getent hosts "$(hostname)"
grep -n "$(hostname -s)" /etc/hostsIf nothing is returned, add the line that maps the fully qualified name and short name to the address, as shown earlier in this tutorial. Change the hostname and /etc/hosts together so they never disagree.
Stale entries in /etc/hosts
After you change an address, an old line in /etc/hosts can keep sending local programs to the previous IP. Remove it. Applications that cache lookups may also need a restart.
When you lose remote access
If SSH stops working after a change, use the console or out-of-band access. If you used netplan try and did not confirm, the old configuration returns by itself after the timeout, which is the safety net it provides. Once you have a console, run through steps 1 to 5 above, starting with ip -br address show. Keep a copy of the working configuration before each edit, for example sudo cp /etc/netplan/01-static.yaml /root/01-static.yaml.bak, so you can restore it quickly.
Quick reference
| Check | Command | A good result looks like |
|---|---|---|
| Link and address | `ip -br address show` | `UP` and your address with the right prefix |
| Merged Netplan config | `sudo netplan get` | Only your intended settings |
| Gateway | `ping -c 3 <gateway>` | Replies, no loss |
| Default route | `ip route show default` | One line with `via <gateway>` |
| Outside IP | `ping -c 3 9.9.9.9` | Replies |
| DNS | `resolvectl query example.com` | An address and the server used |
| System lookup | `getent hosts example.com` | An address |
Exercise
A server at 192.168.1.50/24 can ping its gateway 192.168.1.1, but ping 9.9.9.9 returns "Network is unreachable". ping example.com fails too. Which check failed first, what is the most likely cause, and which command confirms it?
Show answer
Step 3 failed first. "Network is unreachable" means the kernel has no route to the destination, so the default route is probably missing. Run ip route show default. An empty result confirms it. Add the routes: block with to: default and via: 192.168.1.1 in Netplan, or set ipv4.gateway in NetworkManager, and apply the change. The DNS failure is a side effect, because the DNS servers are not reachable without a route.
Exercise
resolvectl query example.com returns an address, but getent hosts example.com returns a different address. What does that tell you, and where do you look?
Show answer
Programs that use the C library follow /etc/nsswitch.conf, and the hosts: line probably lists files before dns. An entry for example.com in /etc/hosts is overriding the DNS answer. Run grep example.com /etc/hosts, and remove or correct the stale entry.
Exercise
After you changed the static address in Netplan, sudo prints "unable to resolve host web01". Name two things to check.
Show answer
Check that hostnamectl --static shows the name you expect, and that /etc/hosts has a line mapping that name and its short form to the server's address. Also check for an old line that still lists the previous IP address. Fix /etc/hosts so the hostname and the file agree.