By Xavier Collantes
9/24/2025
tcpdump
is your Swiss Army knife for packet capture. It shows you exactly
what is crossing the wire.1# Capture HTTP traffic on port 80
2sudo tcpdump -i any -n port 80
3
4# Capture traffic to/from specific host
5sudo tcpdump -i any host api.example.com
6
7# Capture and save to file for analysis
8sudo tcpdump -i eth0 -s 65535 -w capture.pcap
9
10# Monitor DNS queries
11sudo tcpdump -i any port 53
12
1# Detect port scanning attempts (many connections to different ports)
2sudo tcpdump -i any -n 'tcp[tcpflags] & (tcp-syn) != 0 and tcp[tcpflags] & (tcp-ack) = 0'
3
4# Monitor for unusual outbound connections (potential data exfiltration)
5sudo tcpdump -i any -n 'src host YOUR_SERVER_IP and not dst net 192.168.0.0/16 and not dst net 10.0.0.0/8'
6
7# Detect potential DDoS or brute force attacks (high connection volume)
8sudo tcpdump -i any -n 'tcp[tcpflags] & (tcp-syn) != 0' | head -100
9
10# Monitor for suspicious DNS queries (potential DNS tunneling)
11sudo tcpdump -i any -n 'port 53 and greater 512'
12
13# Capture failed connection attempts (potential reconnaissance)
14sudo tcpdump -i any -n 'tcp[tcpflags] & (tcp-rst) != 0'
15
16# Monitor for large data transfers (potential exfiltration)
17sudo tcpdump -i any -n 'greater 1500 and not port 22'
18
19# Detect connections to uncommon ports
20sudo tcpdump -i any -n 'not port 22 and not port 80 and not port 443 and not port 53'
21
1# Show all listening ports
2ss -tuln
3
4# Show processes using network connections
5ss -tulnp
6
1# Basic connectivity test
2ping -c 4 google.com
3
4# Trace the network path
5traceroute google.com
6
1# Monitor TCP connections during the issue
2ss -i | grep :8080
3
4# Look for connection state changes
5tcpdump -i any host api-server and port 8080
6
When capturing packets in production, ensure you comply with privacy regulations. Consider capturing only packet headers or using sampling techniques to reduce data volume.
1# Debug container networking
2docker exec -it container_name ss -tuln
3docker exec -it container_name tcpdump -i eth0
4
5# Check container network namespaces
6docker exec -it container_name ip addr show
7
8# Monitor inter-container communication
9tcpdump -i docker0
10
1# Monitor HTTP headers and responses on port 80
2tcpdump port 80
3
4# SSL/TLS handshake analysis
5openssl s_client -connect xaviercollantes.dev:443 -debug
6
7# Test HTTP/2 connections
8curl -v --http2 https://xaviercollantes.dev
9
1#!/bin/bash
2
3# Xavier script for network debugging.
4
5HOST=${1:-"xaviercollantes.dev"} # host can be changed to a target site like `xaviercollantes.dev`
6PORT=${2:-"80"}
7
8echo "=== target site ==="
9ping -c 3 $HOST
10echo "Date: $(date)"
11
12echo -e "\n=== DNS info ==="
13# For DNS of a target site. Shows if site has propagated to DNS servers like
14# Cloudflare, etc.
15dig $HOST
16
17echo -e "\n=== port ==="
18nmap -p $PORT $HOST
19
20echo -e "\n=== Route Tracing ==="
21traceroute $HOST
22
23echo -e "\n=== Active Connections ==="
24ss -tuln | grep :$PORT
25
26echo -e "\n=== Network stats ==="
27ss -s
28
1=== Network Debug Report for localhost:80 ===
2Date: Wed Sep 24 16:15:56 PDT 2025
3
4=== basics ===
5PING localhost (127.0.0.1): 56 data bytes
664 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.041 ms
764 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.063 ms
864 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.085 ms
9
10--- localhost ping statistics ---
113 packets transmitted, 3 packets received, 0.0% packet loss
12round-trip min/avg/max/stddev = 0.041/0.063/0.085/0.018 ms
13-e
14=== DNS info ===
15
16; <<>> DiG 9.10.6 <<>> localhost
17;; global options: +cmd
18;; Got answer:
19;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: XXXX
20;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
21
22;; OPT PSEUDOSECTION:
23; EDNS: version: 0, flags:; udp: XXXX
24;; QUESTION SECTION:
25;localhost. IN A
26
27;; AUTHORITY SECTION:
28. XXXX IN SOA a.root-servers.net. nstld.verisign-grs.com. XXXXXXX
29
30;; Query time: 17 msec
31;; SERVER: 1.1.1.1#53(1.1.1.1)
32;; WHEN: Wed Sep 24 16:15:58 PDT 2025
33;; MSG SIZE rcvd: XXX
34
35-e
36=== port ===
37Starting Nmap 7.95 ( https://nmap.org ) at 2025-09-24 16:15 PDT
38Nmap scan report for localhost (127.0.0.1)
39Host is up (0.00012s latency).
40Other addresses for localhost (not scanned): ::1
41
42PORT STATE SERVICE
4380/tcp closed http
44
45Nmap done: 1 IP address (1 host up) scanned in 0.02 seconds
46-e
47=== Route Tracing ===
48traceroute to localhost (127.0.0.1), 64 hops max, 40 byte packets
49 1 localhost (127.0.0.1) 0.192 ms 0.061 ms 0.049 ms
50-e
51=== Active Connections ===
52temp.sh: line 25: ss: command not found
53-e
54=== Network stats ===
55temp.sh: line 28: ss: command not found
56
Network debugging pairs perfectly with async Python patterns for building resilient, high-performance applications that gracefully handle network instability.
Related by topics: