Part 6 · Real networks: infrastructure, security and operations
Network troubleshooting: a systematic method with tcpdump and curl
Course contents
You can track down almost any network problem with one fixed method and about ten tools. Rule one: don’t guess, measure. Rule two: split the problem in half, and find where along the path things work and where they stop working.
The method: bottom up, or split the path
- Pin down the problem: what fails, from where, to where, since when, always or only sometimes? What is the exact error message? (“It doesn’t work” is not data.)
- Go layer by layer, from the bottom: Is the link up? Are the IP address and route correct? Does DNS answer correctly? Is the port open? Does the TLS handshake complete? What does HTTP say?
- Or split the path: Does it work from the same host to the destination? From another host on the same network? From the Internet? Straight to the IP instead of the name? To the backend instead of the load balancer?
- Change only one variable at a time.
- Once you’ve found it, understand the cause and write it down.
The toolbox, layer by layer
| Layer | Question | Tools |
|---|---|---|
| Link | Is the interface up? Any hardware errors? | ip -br link, ethtool eth0, ethtool -S |
| Neighbor | Is the gateway reachable? | ip neigh, arping |
| IP and routing | Are the address and the route right? | ip -br addr, ip route get <dst>, ping, traceroute, mtr, tracepath (MTU) |
| DNS | Does the name resolve correctly? Through which resolver? | dig, dig +trace, getent hosts, resolvectl |
| Transport | Is the port listening? Is it reachable? | ss -tulpn, nc -vz host 443, nmap -p |
| TLS | Are the handshake and the certificate right? | openssl s_client -connect host:443 -servername host |
| HTTP | What’s the response, and how long does each phase take? | curl -v, curl -w, curl --resolve |
| All layers | What is really on the wire? | tcpdump |
| Firewall and NAT | Which rule is being applied? | nft list ruleset, iptables -S -t nat, conntrack -L |
| Throughput | What’s the real capacity of the path? | iperf3 -c server, ss -ti |
tcpdump: the ground truth
sudo tcpdump -i any -nn host 10.0.0.5 # all traffic to/from one host
sudo tcpdump -i eth0 -nn 'tcp port 443 and host api.example.com'
sudo tcpdump -i any -nn 'tcp[tcpflags] & (tcp-syn|tcp-rst) != 0' # only SYNs and RSTs
sudo tcpdump -i any -nn -A 'tcp port 80' # print payloads as ASCII
sudo tcpdump -i any -nn udp port 53 # DNS queries and answers
sudo tcpdump -i eth0 -w capture.pcap -s 0 -C 100 # save to rotating files for later
Everything you need is visible with tcpdump itself and its BPF filters, without any GUI tool:
sudo tcpdump -i any -nn 'tcp[tcpflags] & tcp-rst != 0' # only RSTs (who is resetting?)
sudo tcpdump -i any -nn 'tcp[tcpflags] & (tcp-syn) != 0' # only SYNs (connection attempts)
sudo tcpdump -i any -nn 'udp port 53' # DNS queries and answers
sudo tcpdump -i any -nn -A 'tcp port 80 and tcp[((tcp[12]&0xf0)>>2):4]=0x47455420' # HTTP GET requests
sudo tcpdump -i any -nn 'tcp port 443 and tcp[((tcp[12]&0xf0)>>2)]=0x16' # TLS handshake records
To see a complete stream (the equivalent of “Follow TCP Stream”), tcpdump -A -nn 'host X and port Y' plus -s0 prints all of the text content. To go through a capture later, read the same capture.pcap file back with tcpdump -r capture.pcap; again, no GUI tool needed. (TLS content is encrypted anyway, and no tool can read it without the keys.)
curl for everything HTTP
curl -sv https://api.example.com/health # handshake, headers, redirects
curl -so /dev/null -w 'dns:%{time_namelookup} tcp:%{time_connect} tls:%{time_appconnect} ttfb:%{time_starttransfer} total:%{time_total} code:%{http_code}\n' https://api.example.com/
curl --resolve api.example.com:443:10.0.3.7 https://api.example.com/ # bypass DNS, hit one backend
curl -H 'Host: shop.example.com' http://10.0.3.7/ # test virtual hosting directly
curl -4 https://example.com/ # force IPv4 (and -6 for IPv6)
curl -x http://proxy:3128 https://example.com # through a proxy
Common scenarios
| Symptom | Likely causes | What to run |
|---|---|---|
| “Could not resolve host” | DNS: wrong resolver, wrong name, search domain, private DNS | dig name, dig @8.8.8.8 name, cat /etc/resolv.conf |
| Connection refused | Nothing listens on that port, or only on 127.0.0.1 | ss -tulpn on the server |
| Connection timed out | Firewall or security group, routing, host down | traceroute -T -p 443, tcpdump on both ends |
| Works with the IP, not the name | DNS, virtual host or SNI | curl --resolve |
| Small pages load, big ones hang | MTU black hole (often behind a VPN) | ping -M do -s 1472, tracepath |
| Slow, but no errors | Packet loss, bufferbloat, slow DNS, too many handshakes | mtr, curl -w, ss -ti (retrans) |
| Drops now and then | NAT or LB idle timeout, one bad IP among several in DNS, port exhaustion | LB logs, keepalive, ss -s |
| TLS error | System clock, incomplete chain, wrong name, unknown CA, SNI | openssl s_client, date |
| 502 or 504 from the load balancer | Unhealthy backend, wrong port, timeout too short | LB health checks and logs, curl straight to the backend |
| Fails only from a container or pod | Internal DNS, NetworkPolicy, bound to localhost, overlay MTU | Test from inside the same namespace (nsenter or kubectl debug) |