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.

Beginner 4 min readLesson 15 of 15

"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

  1. Name resolution — does the hostname resolve to the IP you expect? (dig, nslookup)
  2. Reachability — can you reach the IP at all? (ping, traceroute/mtr)
  3. Port — is something listening, and does a firewall let you in? (nc -vz, ss -ltnp, nmap)
  4. TLS — does the handshake succeed with a valid certificate? (openssl s_client, curl -v)
  5. Application — does the request get a sensible response? (curl -v, logs)
  6. Still stuck? Look at the packets. (tcpdump, Wireshark)

The toolkit

ToolAnswersExample
ip addr / ipconfigWhat are my addresses?ip -br addr
ip routeWhere does traffic go?ip route get 8.8.8.8
pingIs the host reachable, and what's the RTT?ping -c 4 10.0.1.5
traceroute / tracert / mtrWhich path, and where does it break or slow down?mtr -rwc 50 example.com
dig / nslookupWhat does DNS say?dig +short api.example.com
curlDoes 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 / netstatWhat's listening; what connections exist?ss -ltnp
lsof -iWhich process owns this port?lsof -i :8080
openssl s_clientTLS handshake and certificate chainopenssl s_client -connect host:443 -servername host
tcpdumpRaw packets on an interfacetcpdump -i any port 443 -n
WiresharkGraphical packet analysisOpen a .pcap from tcpdump
nmapWhich ports are open on a host?nmap -sT -p 1-1024 host (only on systems you're allowed to scan)
iperf3Throughput between two hostsiperf3 -s / iperf3 -c server

curl is your best friend

Shell
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/users

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

ErrorMeaningUsual cause
Could not resolve hostDNS failedTypo, wrong resolver, record missing, VPN/split DNS
Connection refusedRST: host reachable, nothing listening on that portService down, wrong port, bound to 127.0.0.1 only
Connection timed outNo answer at allFirewall/security group dropping packets, wrong IP, routing
No route to hostICMP unreachableHost down, routing problem, firewall rejecting
Connection reset by peerRST mid-connectionServer crashed or closed, idle timeout in a proxy, protocol mismatch
SSL certificate problemTLS verification failedExpired certificate, missing intermediate, wrong hostname, corporate proxy
HTTP 502 / 504Proxy couldn't get a good or timely answer from upstreamApp down or slow, wrong upstream port

Capturing packets

Shell
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 Wireshark

What 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 -v and openssl s_client solve most problems.
  • "Refused" = reachable but nothing listening; "timed out" = probably a firewall or a wrong address.
  • curl -w timings localise slowness to DNS, connect, TLS or the server.
  • tcpdump and Wireshark show the ground truth.