# List available interfacestcpdump-D
tshark-D
# Quick capture on interface (Ctrl+C to stop)tcpdump-ieth0
# Capture to file for later analysistcpdump-ieth0-w/tmp/capture.pcap
# Capture with capture filter (fast, kernel-level)tcpdump-ieth0-w/tmp/capture.pcap'host 10.0.1.5 and port 443'tcpdump-ieth0-w/tmp/capture.pcap'tcp port 8080'tcpdump-ieth0-w/tmp/capture.pcap'net 10.0.0.0/8'# Rotate files: 100MB per file, keep 10 filestcpdump-ieth0-w/tmp/cap.pcap-C100-W10# Capture all interfaces (useful when unsure which interface)tcpdump-iany-w/tmp/capture.pcap
# Capture with timestamps in displaytcpdump-ieth0-tttt'port 53'# Don't resolve DNS/ports (faster, clearer)tcpdump-ieth0-nn'port 80'>**Remember:**Alwaysuse`-nn`inproductioncaptures.Withoutit,tcpdumpdoesreverseDNSlookupsforeveryIP,whichslowscapture,generatesDNStrafficthatpollutesyourcapture,andcanhangifDNSisthethingyouaredebugging.
# Show packet contents in hex+ASCIItcpdump-ieth0-XX'port 25'# Limit packet counttcpdump-ieth0-c1000-w/tmp/capture.pcap
# tshark: read a pcap and displaytshark-r/tmp/capture.pcap
# tshark: apply display filter when readingtshark-r/tmp/capture.pcap-Y'http.response.code == 500'# tshark: extract specific fields as texttshark-r/tmp/capture.pcap-Tfields-eip.src-eip.dst-etcp.dstport
# tshark: extract fields as JSONtshark-r/tmp/capture.pcap-Tjson-Y'dns'|jq'.[].layers.dns'# tshark: count packets per protocoltshark-r/tmp/capture.pcap-qzio,phs
# tshark: conversation statistics (top talkers)tshark-r/tmp/capture.pcap-qzconv,tcp
# tshark: decode HTTP/2 or gRPC traffictshark-r/tmp/capture.pcap-Y'http2'-V
# tshark: follow TCP stream (text)tshark-r/tmp/capture.pcap-q-zfollow,tcp,ascii,0
# tshark: filter by timetshark-r/tmp/capture.pcap-Y'frame.time >= "2024-01-15 14:00:00"'
# Capture TLS traffic to filetcpdump-ieth0-w/tmp/tls.pcap'tcp port 443'# With tshark, look at handshaketshark-r/tmp/tls.pcap-Y'ssl.handshake'-V|less
# Show only TLS alert records (these indicate failures)tshark-r/tmp/tls.pcap-Y'ssl.alert_message'# Extract alert level and descriptiontshark-r/tmp/tls.pcap-Y'ssl.alert_message'\-Tfields-eip.src-eip.dst-essl.alert_message.level-essl.alert_message.desc
# Common TLS alert descriptions:# 40 = handshake_failure (cipher mismatch, cert rejected)# 42 = bad_certificate# 44 = certificate_expired# 48 = unknown_ca# 70 = protocol_version>**Debugclue:**Alert48(`unknown_ca`)isthemostcommonTLSfailureinproduction—itmeanstheclientdoesnottrusttheserver's CA. Either the server is missing an intermediate certificate in its chain, or the client'sCAbundleisoutdated.Checkwith:`openssls_client-connecthost:443-showcerts`.
# To see the server certificate in tshark:tshark-r/tmp/tls.pcap-Y'ssl.handshake.type == 11'-V|grep-A5'subject'
# Capture gRPC traffic (default port 50051, or whatever port your service uses)tcpdump-ieth0-w/tmp/grpc.pcap'tcp port 50051'# Decode HTTP/2 framestshark-r/tmp/grpc.pcap-Y'http2'-Tfields\-eip.src-eip.dst-ehttp2.type-ehttp2.flags-ehttp2.streamid
# HTTP/2 frame types: 0=DATA, 1=HEADERS, 4=SETTINGS, 7=GOAWAY, 8=WINDOW_UPDATE# Show gRPC method names (in HEADERS frames)tshark-r/tmp/grpc.pcap-Y'http2.header.name == ":path"'\-Tfields-eip.src-ehttp2.header.value
# Show gRPC status codes (grpc-status header)tshark-r/tmp/grpc.pcap-Y'http2.header.name == "grpc-status"'\-Tfields-eip.src-eip.dst-ehttp2.header.value
# A GOAWAY frame means the connection is being closed by the other side# Extract the error code from GOAWAYtshark-r/tmp/grpc.pcap-Y'http2.type == 7'-V|grep-E'Error|Last Stream'# If traffic is plaintext HTTP/2 (h2c), tshark may need a hint:tshark-r/tmp/grpc.pcap-d'tcp.port==50051,http2'-Y'http2'
Scenario 3: Finding retransmissions and RST packets¶
# Find all TCP retransmissions (indicates packet loss)tshark-r/tmp/capture.pcap-Y'tcp.analysis.retransmission'# Count retransmissions per sourcetshark-r/tmp/capture.pcap-Y'tcp.analysis.retransmission'\-Tfields-eip.src|sort|uniq-c|sort-rn
# Find RST packets (abrupt connection termination)tshark-r/tmp/capture.pcap-Y'tcp.flags.reset == 1'\-Tfields-eframe.time-eip.src-eip.dst-etcp.srcport-etcp.dstport
# Find connections that were reset immediately (likely rejected)tshark-r/tmp/capture.pcap-Y'tcp.flags.reset == 1 and tcp.seq == 1'# Find duplicate ACKs (precursor to retransmissions)tshark-r/tmp/capture.pcap-Y'tcp.analysis.duplicate_ack'# Zero window events (receiver overwhelmed, sender blocked)tshark-r/tmp/capture.pcap-Y'tcp.analysis.zero_window'>**Underthehood:**TCPretransmissionsdon't always mean packet loss on the wire. They can indicate the receiver'sapplicationistooslowtoreadfromthesocketbuffer(causingzero-windowstallsthatlooklikeretransmissions).Check`tcp.analysis.zero_window`alongsideretransmissionstodistinguishnetworkproblemsfromapplication-sidebackpressure.
# Full TCP analysis statstshark-r/tmp/capture.pcap-qztcp,sum
# Capture only DNStcpdump-ieth0-w/tmp/dns.pcap'udp port 53 or tcp port 53'# Show all DNS queries and responsestshark-r/tmp/dns.pcap-Y'dns'-Tfields\-eframe.time-eip.src-eip.dst-edns.qry.name-edns.resp.name-edns.a-edns.flags.response
# Find DNS queries with no response (potential DNS outage)tshark-r/tmp/dns.pcap-Y'dns.flags.response == 0'\-Tfields-eframe.time-edns.qry.name|head-20
# Then check if matching responses exist# Find NXDOMAIN responses (domain not found)tshark-r/tmp/dns.pcap-Y'dns.flags.rcode == 3'\-Tfields-eframe.time-eip.src-edns.qry.name
# DNS response time (latency)tshark-r/tmp/dns.pcap-qzdns,tree|head-40
# Find queries for internal domains going to external resolverstshark-r/tmp/dns.pcap-Y'dns.flags.response == 0 and not ip.dst == 10.0.0.0/8'\-Tfields-eip.dst-edns.qry.name|grep'\.corp\|\.internal\|\.local'
# Get the node and container runtime info for a podkubectlgetpodmy-pod-owide
# Note the node name# Option 1: Use kubectl debug (if ephemeral containers are enabled)kubectldebug-itmy-pod--image=nicolaka/netshoot--target=my-container
# Inside: tcpdump -i eth0 -w /tmp/cap.pcap# Option 2: Capture on the node using nsenter# SSH to the node, find the pod's network namespacePOD_IP=$(kubectlgetpodmy-pod-ojsonpath='{.status.podIP}')# Find the veth interface for this pod IP:iproute|grep"$POD_IP"# Capture on that interface:tcpdump-iveth<xyz>-w/tmp/pod-cap.pcap
# Option 3: Use ksniff (kubectl plugin)kubectlsniffmy-pod-f"port 8080"-o/tmp/pod.pcap
# Copy capture from the nodekubectlcpmy-pod:/tmp/cap.pcap/tmp/cap.pcap
# In Wireshark: Right-click a packet -> Follow -> TCP Stream# In tshark equivalent:# First, find the stream indextshark-r/tmp/capture.pcap-Y'tcp.port == 8080'\-Tfields-etcp.stream|sort-u
# Pick a stream number, say 5# Follow that streamtshark-r/tmp/capture.pcap-q-zfollow,tcp,ascii,5
# For HTTP streams:tshark-r/tmp/capture.pcap-q-zfollow,http,ascii,5
# Output raw bytes:tshark-r/tmp/capture.pcap-q-zfollow,tcp,raw,5