| name | debugging-network-debugging |
| description | Network debugging with tcpdump, Wireshark, curl, DNS tools, SSL/TLS inspection, and network tracing utilities |
Network Debugging
Scope: tcpdump, Wireshark, curl debugging, HTTP headers, SSL/TLS, DNS (dig, nslookup), strace, lsof, mtr, ping, traceroute
Lines: 420
Last Updated: 2025-10-26
When to Use This Skill
Use this skill when:
- Debugging API connectivity issues
- Analyzing HTTP request/response problems
- Investigating SSL/TLS certificate errors
- Troubleshooting DNS resolution failures
- Diagnosing network latency or packet loss
- Inspecting network traffic between services
- Debugging websocket connections
- Analyzing load balancer or proxy behavior
Don't use for:
- Application logic debugging (use debuggers)
- Simple HTTP client errors (check status codes first)
- Known firewall blocks (check security groups first)
Core Concepts
Network Debugging Layers
Layer 7: Application (HTTP, gRPC, WebSocket)
├─ curl, httpie, wget
├─ Browser DevTools
└─ API clients (Postman, Insomnia)
Layer 4-6: Transport/Session (TCP, TLS)
├─ openssl s_client
├─ nmap
└─ netcat (nc)
Layer 3: Network (IP, routing)
├─ ping, traceroute, mtr
├─ ip route
└─ tcpdump, Wireshark
Layer 2: Data Link (DNS, ARP)
├─ dig, nslookup, host
├─ arp -a
└─ Network packet inspection
Common Network Issues
| Symptom | Likely Cause | Debug Tool |
|---|
| Connection refused | Service not listening, firewall | netcat, telnet |
| Timeout | Network unreachable, slow route | ping, mtr, traceroute |
| DNS error | Misconfigured DNS, missing record | dig, nslookup |
| SSL error | Certificate invalid, expired | openssl s_client |
| Slow requests | High latency, packet loss | tcpdump, Wireshark |
| 404/503 errors | Wrong endpoint, service down | curl -v |
Patterns
Pattern 1: curl Debugging Flags
curl -v https://api.example.com/users
curl -I https://api.example.com/users
curl -i https://api.example.com/users
curl --trace-ascii /tmp/trace.txt https://api.example.com/users
cat /tmp/trace.txt
curl --trace /tmp/trace.bin https://api.example.com/users
curl -L https://example.com
curl -w "@curl-format.txt" -o /dev/null -s https://api.example.com/users
curl -H "Authorization: Bearer token123" \
-H "Content-Type: application/json" \
https://api.example.com/users
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name":"Alice","email":"alice@example.com"}' \
-v
curl --tlsv1.2 https://api.example.com/users
curl --tls-max 1.2 https://api.example.com/users
curl -k https://self-signed.example.com
curl --dns-servers 8.8.8.8 https://api.example.com/users
curl --resolve api.example.com:443:192.0.2.1 https://api.example.com/users
curl -o /dev/null -s -w https://api.example.com/users
curl -v https://api.example.com/users https://api.example.com/posts
Pattern 2: tcpdump Packet Capture
sudo tcpdump -i eth0
sudo tcpdump -i any
sudo tcpdump host api.example.com
sudo tcpdump port 443
sudo tcpdump port 80 or port 443
sudo tcpdump -i any -A 'tcp port 80'
sudo tcpdump -i any port 53
sudo tcpdump -i any -w /tmp/capture.pcap
tcpdump -r /tmp/capture.pcap
sudo tcpdump -tttt -i any port 443
sudo tcpdump -c 100 -i any
sudo tcpdump -v -i any host api.example.com
sudo tcpdump src 192.168.1.10
sudo tcpdump dst 10.0.0.5
sudo tcpdump 'tcp[tcpflags] & tcp-syn != 0'
sudo tcpdump 'tcp[tcpflags] & tcp-rst != 0'
sudo tcpdump host 192.168.1.10 and host 10.0.0.5
sudo tcpdump -i any port not 22
tcpdump -s 65535 -i any -w /tmp/full-capture.pcap
tcpdump -i any -A -w /tmp/api-debug.pcap
curl https://api.example.com/users
wireshark /tmp/api-debug.pcap
Pattern 3: DNS Debugging
dig api.example.com
dig api.example.com +short
dig api.example.com A
dig api.example.com AAAA
dig api.example.com CNAME
dig api.example.com MX
dig api.example.com TXT
dig @8.8.8.8 api.example.com
dig @1.1.1.1 api.example.com
dig api.example.com +trace
dig api.example.com +noall +answer +ttlid
dig -x 93.184.216.34
nslookup api.example.com
nslookup api.example.com 8.8.8.8
host api.example.com
host -t MX example.com
cat /etc/hosts | grep api.example.com
cat /etc/resolv.conf
for ns in 8.8.8.8 1.1.1.1 208.67.222.222; do
echo "DNS Server: $ns"
dig @$ns api.example.com +short
done
dig api.example.com +short
dig @8.8.8.8 api.example.com +short
dig api.example.com +trace
grep api.example.com /etc/hosts
Pattern 4: SSL/TLS Debugging
openssl s_client -connect api.example.com:443
openssl s_client -connect api.example.com:443 -showcerts
openssl s_client -connect api.example.com:443 -servername api.example.com
openssl s_client -connect api.example.com:443 -tls1_2
openssl s_client -connect api.example.com:443 -tls1_3
echo | openssl s_client -connect api.example.com:443 2>/dev/null | \
openssl x509 -noout -dates
echo | openssl s_client -connect api.example.com:443 -showcerts 2>/dev/null | \
openssl x509 -noout -text
echo | openssl s_client -connect api.example.com:443 2>/dev/null | \
openssl x509 -noout -subject
openssl s_client -connect api.example.com:443 -cipher 'ECDHE-RSA-AES128-GCM-SHA256'
nmap --script ssl-enum-ciphers -p 443 api.example.com
openssl s_client -connect api.example.com:443 -status
echo | openssl s_client -connect api.example.com:443 2>/dev/null | \
openssl x509 -out /tmp/cert.pem
openssl verify -CAfile /etc/ssl/certs/ca-bundle.crt /tmp/cert.pem
openssl s_client -connect api.example.com:443 -servername api.example.com
echo | openssl s_client -connect api.example.com:443 2>/dev/null | \
openssl x509 -noout -dates
curl -v https://api.example.com 2>&1 | grep -A 5 "SSL certificate"
Pattern 5: Network Tracing (strace, lsof)
strace -p <pid>
strace -e trace=network -p <pid>
strace -tt -e trace=network -p <pid>
strace -e trace=network -o /tmp/strace.log -p <pid>
strace -e trace=network python app.py
strace -e trace=network,open,stat python -c "import requests; requests.get('https://api.example.com')"
lsof -i
lsof -i :8080
lsof -p <pid>
lsof -c python
lsof -i -sTCP:LISTEN
lsof -i -sTCP:ESTABLISHED
lsof -i @api.example.com
lsof -i 4
lsof -i -r 2
lsof -i :8080
kill <pid>
netstat -tuln
netstat -tunap
netstat -r
ss -t
ss -tl
ss -tp
ss -s
Pattern 6: Connectivity Testing (ping, traceroute, mtr)
ping api.example.com
ping -c 4 api.example.com
ping -s 1000 api.example.com
sudo ping -f api.example.com
traceroute api.example.com
traceroute -I api.example.com
traceroute -A api.example.com
traceroute -m 20 api.example.com
mtr api.example.com
mtr -c 100 api.example.com
mtr -r -c 100 api.example.com
mtr -b api.example.com
nc -zv api.example.com 443
nc -zv api.example.com 80-443
echo -e "GET / HTTP/1.1\r\nHost: api.example.com\r\n\r\n" | nc api.example.com 80
nc -l 8080
mtr -r -c 1000 api.example.com > /tmp/mtr-report.txt
watch -n 1 'ss -t | grep api.example.com'
cat /tmp/mtr-report.txt | grep -E 'Loss%|[0-9]+\.[0-9]+'
Pattern 7: HTTP Header Inspection
curl -v https://api.example.com/users 2>&1 | grep '^>'
curl -v https://api.example.com/users 2>&1 | grep '^<'
curl -I https://api.example.com/users | grep -i content-type
curl -I https://api.example.com/users | grep -i cache-control
curl -I https://api.example.com/users | grep -i access-control
curl -I https://api.example.com/users | grep -i rate-limit
curl -X OPTIONS https://api.example.com/users \
-H "Origin: https://example.com" \
-H "Access-Control-Request-Method: POST" \
-H "Access-Control-Request-Headers: Content-Type" \
-v
curl -H "Accept-Encoding: gzip" -I https://api.example.com/users | grep -i content-encoding
curl -H "Authorization: Bearer token123" -I https://api.example.com/users
curl -A "MyApp/1.0" -I https://api.example.com/users
Quick Reference
Network Debugging Toolbox
sudo apt-get update && sudo apt-get install -y \
curl wget netcat-openbsd \
dnsutils net-tools iproute2 \
tcpdump wireshark-cli \
mtr traceroute nmap \
openssl
brew install curl wget netcat \
bind dnsutils \
tcpdump wireshark \
mtr nmap openssl
Common curl Options
| Flag | Purpose | Example |
|---|
-v | Verbose output | curl -v https://api.example.com |
-I | HEAD request only | curl -I https://api.example.com |
-i | Include headers | curl -i https://api.example.com |
-L | Follow redirects | curl -L https://example.com |
-H | Custom header | curl -H "Auth: token" https://api.example.com |
-X | HTTP method | curl -X POST https://api.example.com |
-d | Request data | curl -d '{"key":"val"}' https://api.example.com |
-k | Ignore SSL errors | curl -k https://self-signed.example.com |
-w | Custom output format | curl -w "%{http_code}" https://api.example.com |
tcpdump Filters
tcpdump tcp
tcpdump udp
tcpdump icmp
tcpdump host api.example.com
tcpdump src 192.168.1.10
tcpdump dst 10.0.0.5
tcpdump port 443
tcpdump portrange 8000-9000
tcpdump 'tcp and port 80'
tcpdump 'host api.example.com and (port 80 or port 443)'
tcpdump -A 'tcp port 80'
tcpdump -X 'tcp port 80'
Anti-Patterns
❌ Ignoring SSL Errors in Production
curl -k https://api.example.com
❌ Using ping for Application Health
ping api.example.com
curl -f https://api.example.com/health
❌ Capturing Too Much Data
sudo tcpdump -i any -w /tmp/capture.pcap
sudo tcpdump -i any -c 1000 -w /tmp/capture.pcap
sudo tcpdump -i any -G 60 -w /tmp/capture.pcap
❌ Not Using SNI with openssl
openssl s_client -connect api.example.com:443
openssl s_client -connect api.example.com:443 -servername api.example.com
Related Skills
- debugging/container-debugging.md - Network debugging in containers
- debugging/distributed-systems-debugging.md - Multi-service network issues
- observability/distributed-tracing.md - Trace network calls across services
- api/rest-api-design.md - HTTP best practices
Last Updated: 2025-10-26
Format Version: 1.0 (Atomic)