Why does my app say Name or service not known for an internal host name after a config change?
Programs resolve names through the system resolver, which reads /etc/hosts before DNS on most servers. A name that only exists in /etc/hosts stops resolving the moment its line is removed, and every call fails with Name or service not known. getent hosts asks the resolver the same way the app does. In this incident configuration management rewrote /etc/hosts and dropped the payments.internal line.
What it looks like
- Calls fail with Name or service not known or Errno -2.
- getent hosts for the name prints nothing.
- The service on the other side is up.
- A configuration management run happened shortly before.
Commands that find the cause
journalctl -u orders-api -n 5 --no-pagerThe service's log, newest last. A failed call to another service shows the name it used and the error, which tells you whether the name or the connection failed.
diff /etc/hosts.pre-cm /etc/hostsCompares the copy configuration management kept with the file it wrote. Lines starting with < were only in the old file, > only in the new one.
getent hosts payments.internalAsks the system resolver for a name the way programs do: /etc/hosts first, then DNS, as nsswitch.conf orders them. No output and exit code 2 means the name does not resolve.
cat /etc/hostsStatic name to address entries the resolver checks before DNS. Names that only exist here stop working the moment a line is removed.
systemctl status payments-proxy --no-pagerThe local payments proxy the API calls. If it is active (running), the far side is up and the problem is on the way to it.
What the evidence looked like
Recorded on a real system when this incident was captured for the game.
$ journalctl -u orders-api -n 5 --no-pager
Nov 29 20:27:35 ops-1 python3[3673]: ERROR /pay: [Errno -2] Name or service not known
Nov 29 20:27:39 ops-1 python3[3673]: ERROR /pay: [Errno -2] Name or service not known
Nov 29 20:27:39 ops-1 python3[3673]: ERROR /pay: [Errno -2] Name or service not known
Nov 29 20:27:39 ops-1 python3[3673]: ERROR /pay: [Errno -2] Name or service not known
Nov 29 20:27:39 ops-1 python3[3673]: ERROR /pay: [Errno -2] Name or service not knownRoot cause
Last night's config run rewrote /etc/hosts without payments.internal, so lookups failed; restoring the line fixed it.
The fix
Put the missing line back in /etc/hosts:
echo '127.0.0.1 payments.internal' | sudo tee -a /etc/hostsHow to prevent it
Keep internal names in DNS or in the configuration management data, not hand edits to /etc/hosts, and alert on resolution failures.
More incident guides
- Linux disk full: no space left on device
- systemd service keeps restarting after a deploy
- Address already in use: find what holds a port on Linux
- Too many open files in a systemd service
- CrashLoopBackOff after a config change
- Service returns 503 while every pod is Running
- OOMKilled and exit code 137
- Pods fail to start after a Secret change
- Requests fail after adding a NetworkPolicy
- Healthy pods restarted by a liveness probe
- Slow service with low CPU and no restarts
- Rollout stuck on ImagePullBackOff
- Pods stuck Pending with insufficient CPU
- Docker container exits immediately after a config change
- Docker port mapping not working, empty reply
- Docker container cannot connect to the database host
- Docker volume permission denied
- Docker container exit code 137, killed for memory