Master tcpdump: Essential Commands for Network Packet Capture
This guide introduces tcpdump, a powerful network packet capture tool, explains its filtering capabilities with logical operators, and provides numerous practical examples—from capturing traffic on specific interfaces and hosts to filtering by ports, protocols, and saving captures—helping users troubleshoot network issues efficiently.
Introduction
tcpdump is a network packet capture tool that supports filtering by network layer, protocol, host, network or port, and provides logical operators such as and, or, not to discard irrelevant information.
Basic Usage Examples
Capture on default interface
tcpdumpCapture on a specific interface
tcpdump -i en0Capture traffic between local host and a remote host
tcpdump host 182.254.38.55Capture traffic from a specific source or destination
tcpdump src host hostname tcpdump dst host hostnameCapture traffic on a specific port
tcpdump port 3000Capture only TCP or UDP packets
tcpdump tcpCombine filters (source host, port, protocol)
tcpdump tcp port 22 and src host 123.207.116.169Capture traffic between two hosts
tcpdump ip host 210.27.48.1 and 210.27.48.2 tcpdump ip host 210.27.48.1 and ! 210.27.48.2More detailed example
tcpdump tcp -i eth1 -t -s 0 -c 100 and dst port ! 22 and src net 192.168.1.0/24 -w ./target.capCapture HTTP traffic from a specific host
sudo tcpdump -i any -s 0 -A 'tcp port 80 and host example.com'Limit number of captured packets
tcpdump -c 1000Save capture to file
tcpdump -n -vvv -c 1000 -w /tmp/tcpdump_save.capForce immediate write to disk (use -U)
tcpdump -U ...Practical Troubleshooting Example
In a typical setup where Nginx reverse‑proxies requests to a Node.js server listening on port 3000, you can use tcpdump to verify whether traffic reaches the backend. First, capture packets on the port used by Nginx: tcpdump port 8383 If no output appears, capture on the loopback interface because Nginx forwards to 127.0.0.1: tcpdump port 8383 -i lo To filter by the client IP address:
tcpdump port 8383 -i lo and src host 183.14.132.117Finally, verify the request reaches the server:
tcpdump -n tcp port 8383 -i lo and src host 183.14.132.117Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
