Networking troubleshooting cheat sheet
The Linux commands for addresses, ports, sockets, DNS and HTTP, in the order you use them to find why a service is up but unreachable.
Layer by layer
| Question | Command |
|---|---|
| Does this machine have an address? | ip -br a |
| Is there a route? | ip r · ip r get 10.0.0.5 |
| Is the other side reachable? | ping -c 3 10.0.0.5 (ICMP may be blocked: not proof) |
| Does the name resolve? | getent hosts api · dig +short api |
| Is something listening? | ss -tlnp (TCP) · ss -ulnp (UDP) |
| On which address? | 127.0.0.1:8000 is local only; 0.0.0.0:8000 is every interface |
| Can I connect to the port? | nc -zv host 8000 · curl -v telnet://host:8000 |
| Does the application answer? | curl -v http://host:8000/health |
| Is a firewall in the way? | sudo iptables -L -n -v · sudo nft list ruleset |
Reading ss
State Local Address:Port Peer Address:Port Process
LISTEN 127.0.0.1:8000 0.0.0.0:* users:(("python3",pid=812))
ESTAB 10.0.0.4:22 10.0.0.9:51234 users:(("sshd",pid=901))
ss -tan state established all open connections · ss -tanp | grep :5432 who talks to Postgres.
DNS
| File / command | Role |
|---|---|
/etc/hosts | names that never ask DNS (wins first) |
/etc/nsswitch.conf (hosts: line) | which sources, in which order |
/etc/resolv.conf | DNS servers and search domains |
resolvectl status | the real servers behind 127.0.0.53 |
dig @server name | ask one server directly |
NXDOMAIN = the name does not exist · SERVFAIL = the server failed · getent follows the system's rules, dig asks DNS only.
HTTP by hand
curl -v http://localhost/ # request and response headers
curl -i -H 'Host: shop.example' http://10.0.0.4/
curl -X POST -H 'Content-Type: application/json' -d '{"sku":"MILK-1L"}' http://localhost:8000/orders
printf 'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n' | nc localhost 80
Status classes: 2xx ok · 3xx go elsewhere · 4xx your request (401 who are you, 403 not allowed, 404 not here) · 5xx the server (502 the proxy got no good answer from the app behind it, 504 it timed out).
Addresses
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 are private · /24 = 256 addresses · 127.0.0.1 is this machine. Work out any range with the subnet calculator.