SnowOps Night Shift

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

  1. journalctl -u orders-api -n 5 --no-pager

    The 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.

  2. diff /etc/hosts.pre-cm /etc/hosts

    Compares the copy configuration management kept with the file it wrote. Lines starting with < were only in the old file, > only in the new one.

  3. getent hosts payments.internal

    Asks 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.

  4. cat /etc/hosts

    Static name to address entries the resolver checks before DNS. Names that only exist here stop working the moment a line is removed.

  5. systemctl status payments-proxy --no-pager

    The 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 known

Root 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/hosts

How 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