Network Debugging Tools
A practical toolkit — ping, traceroute/mtr, dig, curl, ss/netstat, nc, tcpdump and Wireshark, nmap, iperf — and a layer-by-layer troubleshooting method.
"It can't connect" is one of the most common problems in software engineering. Debug it layer by layer, from the bottom up, with the right tool at each layer, instead of guessing.
A troubleshooting method
- Name resolution — does the hostname resolve to the IP you expect? (
dig,nslookup) - Reachability — can you reach the IP at all? (
ping,traceroute/mtr) - Port — is something listening, and does a firewall let you in? (
nc -vz,ss -ltnp,nmap) - TLS — does the handshake succeed with a valid certificate? (
openssl s_client,curl -v) - Application — does the request get a sensible response? (
curl -v, logs) - Still stuck? Look at the packets. (
tcpdump, Wireshark)
The toolkit
| Tool | Answers | Example |
|---|---|---|
ip addr / ipconfig | What are my addresses? | ip -br addr |
ip route | Where does traffic go? | ip route get 8.8.8.8 |
ping | Is the host reachable, and what's the RTT? | ping -c 4 10.0.1.5 |
traceroute / tracert / mtr | Which path, and where does it break or slow down? | mtr -rwc 50 example.com |
dig / nslookup | What does DNS say? | dig +short api.example.com |
curl | Does the HTTP endpoint work? | curl -v https://api.example.com/health |
nc (netcat) | Can I open a TCP connection to this port? | nc -vz db.internal 5432 |
ss / netstat | What's listening; what connections exist? | ss -ltnp |
lsof -i | Which process owns this port? | lsof -i :8080 |
openssl s_client | TLS handshake and certificate chain | openssl s_client -connect host:443 -servername host |
tcpdump | Raw packets on an interface | tcpdump -i any port 443 -n |
| Wireshark | Graphical packet analysis | Open a .pcap from tcpdump |
nmap | Which ports are open on a host? | nmap -sT -p 1-1024 host (only on systems you're allowed to scan) |
iperf3 | Throughput between two hosts | iperf3 -s / iperf3 -c server |
curl is your best friend
curl -v https://api.example.com/users # full request/response headers + TLS info
curl -sS -o /dev/null -w "%{http_code} %{time_total}s\n" https://example.com
curl -w "dns:%{time_namelookup} connect:%{time_connect} tls:%{time_appconnect} ttfb:%{time_starttransfer}\n" -o /dev/null -s https://example.com
curl --resolve api.example.com:443:10.0.0.7 https://api.example.com/ # bypass DNS, keep SNI
curl -X POST -H "Content-Type: application/json" -d '{"name":"Ada"}' https://api.example.com/usersThe -w timing breakdown tells you immediately whether slowness is in DNS, the TCP connect, the TLS handshake, or the server (time to first byte).
Reading the error messages
| Error | Meaning | Usual cause |
|---|---|---|
Could not resolve host | DNS failed | Typo, wrong resolver, record missing, VPN/split DNS |
Connection refused | RST: host reachable, nothing listening on that port | Service down, wrong port, bound to 127.0.0.1 only |
Connection timed out | No answer at all | Firewall/security group dropping packets, wrong IP, routing |
No route to host | ICMP unreachable | Host down, routing problem, firewall rejecting |
Connection reset by peer | RST mid-connection | Server crashed or closed, idle timeout in a proxy, protocol mismatch |
SSL certificate problem | TLS verification failed | Expired certificate, missing intermediate, wrong hostname, corporate proxy |
| HTTP 502 / 504 | Proxy couldn't get a good or timely answer from upstream | App down or slow, wrong upstream port |
Capturing packets
sudo tcpdump -i any -nn host 10.0.1.5 and port 5432 # watch traffic to Postgres
sudo tcpdump -i eth0 -w capture.pcap # save for WiresharkWhat to look for in a capture:
- SYN sent, nothing comes back → a firewall is dropping packets.
- SYN answered with RST → nothing listening.
- Handshake succeeds, then TLS alert → certificate or protocol mismatch.
- Many retransmissions or zero windows → packet loss, or a slow receiver.
Key takeaways
- Debug bottom-up: DNS → reachability → port → TLS → application → packets.
dig,ping/mtr,nc,ss,curl -vandopenssl s_clientsolve most problems.- "Refused" = reachable but nothing listening; "timed out" = probably a firewall or a wrong address.
curl -wtimings localise slowness to DNS, connect, TLS or the server.- tcpdump and Wireshark show the ground truth.