Network Debug Guide
ping โ Connectivity Test
# Basic ping
ping google.com
# Limit count
ping -c 4 google.com
# Specify interval (0.2s)
ping -i 0.2 -c 10 8.8.8.8
# Set packet size (test MTU)
ping -s 1472 -c 3 10.0.0.1
# Ping with timestamp
ping -D google.com
traceroute / tracert โ Path Tracing
# Linux/macOS
traceroute google.com
# Use ICMP (not UDP)
traceroute -I google.com
# Use TCP port 80
traceroute -T -p 80 google.com
# Windows
tracert google.com
# mtr (better traceroute)
mtr --report --report-cycles 10 google.com
nslookup / dig โ DNS Lookup
# Basic nslookup
nslookup example.com
# Query specific record type
nslookup -type=MX example.com
nslookup -type=TXT example.com
nslookup -type=NS example.com
# dig (more detailed)
dig example.com
dig example.com MX
dig example.com NS +short
# Reverse DNS
dig -x 8.8.8.8
# Query specific DNS server
dig @8.8.8.8 example.com
# Trace full resolution
dig +trace example.com
curl โ HTTP Debugging
# Basic request with headers
curl -v https://example.com
# Show only response headers
curl -I https://example.com
# Time breakdown
curl -w "@curl-format.txt" -o /dev/null -s https://example.com
# curl-format.txt:
# time_namelookup: %{time_namelookup}\n
# time_connect: %{time_connect}\n
# time_appconnect: %{time_appconnect}\n
# time_pretransfer: %{time_pretransfer}\n
# time_redirect: %{time_redirect}\n
# time_starttransfer: %{time_starttransfer}\n
# time_total: %{time_total}\n
# POST JSON
curl -X POST https://api.example.com/data \
-H "Content-Type: application/json" \
-d '{"key":"value"}'
netstat / ss โ Connection State
# List listening ports
netstat -tlnp # Linux (needs sudo for PID)
ss -tlnp # modern replacement
# All connections
netstat -an
ss -an
# Filter by port
ss -tnp sport = :80
# Show established connections
ss -tn state established
# Port usage summary
ss -s
tcpdump โ Packet Capture
# Capture on interface eth0
tcpdump -i eth0
# Filter by host
tcpdump -i eth0 host 10.0.0.1
# Filter by port
tcpdump -i eth0 port 80
# Capture HTTP traffic (GET/POST)
tcpdump -i eth0 -A 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
# Save to file
tcpdump -i eth0 -w capture.pcap
# Read saved capture
tcpdump -r capture.pcap
Quick Diagnostic Checklist
| Symptom | Command |
|---|---|
| Can't reach host | ping host โ traceroute host |
| DNS not resolving | dig host โ dig @8.8.8.8 host |
| Port not accessible | telnet host port or nc -zv host port |
| High latency | mtr host to find the bottleneck hop |
| Slow HTTP | curl -w time_total ... |
| Dropped packets | ping -c 100 host watch packet loss % |