How to Use Tcpdump: Beginner's Guide to Packet Capture in Kali Linux
Learn how to use tcpdump in Kali Linux — capture packets, filter with BPF, save pcap files and read output, with a worked example and cheat sheet.
What Is Tcpdump?
Tcpdump is an open-source command-line packet capture tool built on libpcap. It listens on a network interface, captures the packets passing through it, and prints or saves them so you can inspect traffic, troubleshoot connections, and spot suspicious activity. It is pre-installed on Kali Linux and uses Berkeley Packet Filter (BPF) expressions to capture only the traffic you ask for.
Why You Need Tcpdump
You need to see network traffic in real time from the command line — Tcpdump captures packets on any interface and displays or saves them for analysis. It uses BPF filter syntax for precise traffic selection and runs in environments where a GUI is unavailable.
A server stops answering, a login fails for no visible reason, or a lab machine talks to an address it should not. Ping and curl tell you that something is wrong; tcpdump shows you exactly what crossed the wire — the SYN that never got an answer, the DNS query going to the wrong server, the reset packet killing the connection. That is why it is the first tool most network troubleshooters reach for, and why it belongs in every Kali Linux workflow.
Prerequisites
Installing Tcpdump
Tcpdump is pre-installed on Kali Linux. Verify it with:
tcpdump --version
If it is missing, install it for your system:
# Debian / Ubuntu / Kali
sudo apt update && sudo apt install tcpdump
# Fedora / RHEL
sudo dnf install tcpdump
# Arch Linux
sudo pacman -S tcpdump
# macOS (capture still needs sudo)
brew install tcpdump
On Windows, tcpdump does not run natively. The closest equivalent is tshark, the command-line tool bundled with Wireshark, which uses the same BPF filter syntax and reads and writes the same pcap files. Install Wireshark (which includes Npcap, the packet-capture driver) and use tshark wherever this guide says tcpdump.
How to Use Tcpdump in 6 Steps
This is the whole workflow in miniature. Master these six steps and you can capture anything in this guide.
Step 1: Check the install
tcpdump --version
You should see a version number and a libpcap version. If the command is not found, install it using the section above.
Step 2: List your interfaces
tcpdump -D
Tcpdump prints every interface it can capture on, numbered: 1.eth0, 2.wlan0, 3.lo, and on Linux any. Pick the one carrying the traffic you care about.
Step 3: Run your first capture
sudo tcpdump -i eth0 -c 5
The -c 5 stops after five packets so the capture ends by itself. You will see one line per packet, each starting with a timestamp. Press Ctrl+C to stop any capture that has no -c limit.
Step 4: Add a filter
sudo tcpdump -i eth0 -c 10 port 80
Now only web traffic appears. Filters are the difference between a useful capture and a flood of noise — most of this guide is about writing good ones.
Step 5: Save the capture to a file
sudo tcpdump -i eth0 -w capture.pcap -c 100
Nothing is printed; the packets go into capture.pcap in full. Saving first and analyzing later is the professional habit — live output can drop packets on a busy network.
Step 6: Read the file back
tcpdump -r capture.pcap -nn port 443
Reading a file needs no root privileges, and you can apply a different filter while reading. Open the same file in Wireshark for a graphical view.
Choosing an Interface
The -i flag picks where tcpdump listens. Get it wrong and you capture nothing, or the wrong traffic entirely.
# List interfaces with their numbers
tcpdump -D
# Capture on a named interface
sudo tcpdump -i eth0
# Capture on every interface at once (Linux only)
sudo tcpdump -i any
# Capture localhost traffic only
sudo tcpdump -i lo
With no -i flag, tcpdump uses the first interface it finds — usually fine on a laptop, unreliable on a machine with several interfaces. The any pseudo-device is convenient for a first look, but it can show the same packet twice when it crosses two interfaces, so prefer a named interface once you know which one carries the traffic. Loopback (lo) is the interface for traffic a machine sends to itself, which is exactly what the worked example below uses.
Basic Usage
sudo tcpdump -i eth0
sudo tcpdump -i eth0 -c 100
sudo tcpdump -i eth0 -w capture.pcap
tcpdump -r capture.pcap
Essential Options
| Option | Description |
|---|---|
-i INTERFACE | Network interface |
-D | List available interfaces |
-c COUNT | Stop after COUNT packets |
-w FILE | Write to file |
-r FILE | Read from file |
-n | No hostname resolution |
-nn | No hostname or port resolution |
-v | Verbose output |
-vv | More verbose output |
-vvv | Most verbose output |
-X | Hex and ASCII output |
-XX | Hex and ASCII, including the link-level header |
-A | ASCII output |
-t | No timestamp |
-tt | Timestamp as seconds since 1970 |
-ttt | Time since the previous packet |
-tttt | Full date and time |
-s SNAPLEN | Capture SNAPLEN bytes per packet |
-l | Line-buffered output (for piping to grep or tee) |
-e | Print the link-level header |
-S | Absolute TCP sequence numbers |
-q | Quiet output (less protocol detail) |
-G SECONDS | Rotate the output file every SECONDS |
-C MB | Rotate the output file at MB megabytes |
-W COUNT | Keep at most COUNT rotated files |
-B KB | Kernel capture buffer size, in KiB |
BPF Filter Expressions
# Host filters
sudo tcpdump -i eth0 host 192.168.1.100
sudo tcpdump -i eth0 src host 10.0.0.1
sudo tcpdump -i eth0 dst host 93.184.216.34
# Port filters
sudo tcpdump -i eth0 port 80
sudo tcpdump -i eth0 portrange 8000-8100
# Protocol filters
sudo tcpdump -i eth0 tcp
sudo tcpdump -i eth0 udp icmp arp
# Combined
sudo tcpdump -i eth0 tcp and port 80
sudo tcpdump -i eth0 not arp and not icmp
BPF is the filter language tcpdump, Wireshark, and tshark all share, so anything you learn here transfers directly. A filter is built from primitives joined by and, or, and not, with parentheses for grouping (quote them so the shell does not eat them).
# One host, one direction
sudo tcpdump -i eth0 src host 10.0.0.5 and dst port 443
# A whole subnet
sudo tcpdump -i eth0 net 192.168.1.0/24
# Everything except the noise
sudo tcpdump -i eth0 not arp and not icmp and not port 5353
# Grouping with parentheses (note the quotes)
sudo tcpdump -i eth0 '(port 80 or port 443) and host 93.184.216.34'
# Only connection attempts (SYN packets, no data)
sudo tcpdump -i eth0 'tcp[tcpflags] & tcp-syn != 0'
# Only DNS queries
sudo tcpdump -i eth0 udp port 53
# Only ICMP (ping) traffic
sudo tcpdump -i eth0 icmp
# Only ARP requests
sudo tcpdump -i eth0 arp
# Packets longer than 1000 bytes
sudo tcpdump -i eth0 greater 1000
# SSH traffic to one server
sudo tcpdump -i eth0 host 10.0.0.5 and port 22
# Web traffic, either HTTP or HTTPS
sudo tcpdump -i eth0 'tcp port 80 or tcp port 443'
Two rules keep filters predictable: and binds tighter than or, so use parentheses whenever you mix them; and filters apply before packets reach userspace, so a tight filter costs almost nothing even on a busy interface, while no filter at all costs you a flood.
Worked Example: Capturing a Real HTTP Request
Theory is not enough — here is a complete capture you can run on your own machine in two minutes, with nothing leaving localhost.
Open two terminals. In the first, start a tiny web server bound to localhost only:
python3 -m http.server 8000 --bind 127.0.0.1
In the second, start the capture on the loopback interface, then fetch the page:
sudo tcpdump -i lo -nn -A port 8000
curl http://127.0.0.1:8000/
The capture shows the whole conversation. Sample output (illustrative — your ports, sequence numbers, and timestamps will differ):
14:32:10.123456 IP 127.0.0.1.54321 > 127.0.0.1.8000: Flags [S], seq 1000000000, win 65495, length 0
14:32:10.124000 IP 127.0.0.1.8000 > 127.0.0.1.54321: Flags [S.], seq 2000000000, ack 1000000001, win 65495, length 0
14:32:10.124500 IP 127.0.0.1.54321 > 127.0.0.1.8000: Flags [.], ack 2000000001, win 65535, length 0
14:32:10.125000 IP 127.0.0.1.54321 > 127.0.0.1.8000: Flags [P.], seq 1000000001:1000000100, ack 2000000001, win 65535, length 99: HTTP: GET / HTTP/1.1
14:32:10.126000 IP 127.0.0.1.8000 > 127.0.0.1.54321: Flags [P.], seq 2000000001:2000000500, ack 1000000100, win 65535, length 499: HTTP: HTTP/1.0 200 OK
Read it line by line: the first three lines are the TCP three-way handshake — SYN, SYN-ACK, ACK — proving the connection opened. The fourth line is the request itself, and because -A prints payload as ASCII you can read GET / HTTP/1.1 directly in the capture. The fifth line is the server answering 200 OK. The length field is the payload size, and seq/ack let you follow which bytes belong to which part of the conversation.
Try it again with -X instead of -A to see the same request as hex plus ASCII, and with port 8000 removed to see how much background localhost traffic appears — that contrast is the best lesson in why filters matter.
Reading Tcpdump Output Like a Pro
One output line carries a surprising amount of information once you know its shape:
22:15:30.123456 IP 192.168.1.100.54321 > 93.184.216.34.80: Flags [S], seq 123456789, win 65535, length 0
From left to right: the timestamp (with microseconds), the protocol (IP), the source address and port (192.168.1.100.54321), the direction arrow, the destination address and port (93.184.216.34.80), the TCP flags, the sequence number, the advertised window, and the payload length. A length 0 packet with [S] is a connection attempt, not data — it is the handshake, and on a scan you will see many of them with no reply.
Flags: [S] = SYN, [S.] = SYN-ACK, [.] = ACK, [P] = PUSH, [F] = FIN, [R] = RST.
Control the output with the verbosity and timestamp flags:
# Quiet: less protocol detail
sudo tcpdump -i eth0 -q
# Verbose: TTL, IP ID, options, and more
sudo tcpdump -i eth0 -v
# Very verbose: full protocol decode
sudo tcpdump -i eth0 -vv
# Readable date and time instead of bare clock time
sudo tcpdump -i eth0 -tttt
# Time between packets (great for spotting delays)
sudo tcpdump -i eth0 -ttt
# Absolute sequence numbers (default is relative)
sudo tcpdump -i eth0 -S
For payload inspection, -A prints ASCII (readable for HTTP, DNS names, and cleartext protocols), -X prints hex plus ASCII (the choice when the payload is binary), and -XX adds the link-level header on top. Modern tcpdump defaults to a 262,144-byte snapshot length, so packets are rarely truncated; on older builds, if you see [|tcp] truncation markers, raise it with -s 65535.
Advanced Tcpdump Options
Beyond the everyday flags, a few options solve specific problems:
# Full packets, never truncated
sudo tcpdump -i eth0 -s 0
# Line-buffered output so grep sees packets immediately
sudo tcpdump -i eth0 -l | grep "192.168.1.100"
# Rotate the capture file every 60 seconds
sudo tcpdump -i eth0 -G 60 -w capture-%Y-%m-%d_%H-%M-%S.pcap
# Rotate at 100 MB, keep at most 5 files
sudo tcpdump -i eth0 -C 100 -W 5 -w capture.pcap
# Bigger kernel buffer to avoid dropped packets (size in KiB)
sudo tcpdump -i eth0 -B 4096
# Show the Ethernet header (MAC addresses)
sudo tcpdump -i eth0 -e
# Capture on all interfaces and save with timestamps in the filename
sudo tcpdump -i any -nn -tttt -w all-traffic.pcap
Rotation (-G, -C, -W) is what makes long captures safe: without it, a forgotten capture fills the disk. The %Y-%m-%d patterns in -w filenames are strftime formats, so each rotated file gets its own timestamped name automatically.
Saving Captures and Analyzing Them in Wireshark
The save-first workflow is the professional default: capture to a file, then analyze without time pressure.
# Save 1000 packets to a file
sudo tcpdump -i eth0 -w output.pcap -c 1000
# Read the file back with a filter applied
tcpdump -r output.pcap -nn port 443
# Carve a subset into a new file
tcpdump -r output.pcap -w web-only.pcap port 80
# Count packets per host from a saved capture
tcpdump -r output.pcap -nn | awk '{print $3}' | sort | uniq -c | sort -nr | head
Reading a pcap needs no root privileges, so you can analyze captures on a different machine from the one that recorded them. The same file opens directly in Wireshark — drag it in, or open it from the File menu — where you get protocol dissection, stream following (Follow > TCP Stream), and statistics. tshark -r output.pcap gives you the same dissection from the command line. Keep the original pcap: it is the evidence, and every filtered view you make should be a new file derived from it.
Tcpdump vs Wireshark vs TShark
| Tool | Interface | Best for | BPF filters | Scripting |
|---|---|---|---|---|
| tcpdump | Command line | Quick captures, servers, headless hosts | Yes | Yes |
| Wireshark | Graphical | Deep analysis, streams, statistics | Yes | No |
| TShark | Command line | Scripted analysis, same dissection as Wireshark | Yes | Yes |
Use tcpdump when you need to capture fast on a machine with no screen — a server, a router, a Kali box over SSH. Use Wireshark when you need to understand a capture: its protocol trees, colour rules, and stream views beat raw text for anything complicated. Use TShark when you want Wireshark's dissection inside a script, or on Windows where tcpdump does not run natively. Most practitioners use all three: tcpdump to capture, Wireshark to understand, tshark to automate.
Tcpdump Commands Cheat Sheet
| Task | Command |
|---|---|
| List interfaces | tcpdump -D |
| Capture on an interface | sudo tcpdump -i eth0 |
| Capture on all interfaces | sudo tcpdump -i any |
| Capture localhost only | sudo tcpdump -i lo |
| Capture 10 packets then stop | sudo tcpdump -i eth0 -c 10 |
| Capture without DNS lookups | sudo tcpdump -i eth0 -nn |
| Save to a pcap file | sudo tcpdump -i eth0 -w capture.pcap |
| Read a pcap file | tcpdump -r capture.pcap |
| Read with a filter | tcpdump -r capture.pcap port 443 |
| Filter by host | sudo tcpdump -i eth0 host 192.168.1.100 |
| Filter by source host | sudo tcpdump -i eth0 src host 10.0.0.1 |
| Filter by destination host | sudo tcpdump -i eth0 dst host 93.184.216.34 |
| Filter by port | sudo tcpdump -i eth0 port 80 |
| Filter by port range | sudo tcpdump -i eth0 portrange 8000-8100 |
| Filter by protocol | sudo tcpdump -i eth0 tcp |
| Filter UDP, ICMP, ARP | sudo tcpdump -i eth0 udp icmp arp |
| Filter by subnet | sudo tcpdump -i eth0 net 192.168.1.0/24 |
| Combine filters | sudo tcpdump -i eth0 tcp and port 80 |
| Exclude traffic | sudo tcpdump -i eth0 not arp and not icmp |
| SYN packets only | sudo tcpdump -i eth0 'tcp[tcpflags] & tcp-syn != 0' |
| Show ASCII payload | sudo tcpdump -i eth0 -A port 80 |
| Show hex + ASCII | sudo tcpdump -i eth0 -X port 443 |
| Verbose output | sudo tcpdump -i eth0 -v |
| Full date and time | sudo tcpdump -i eth0 -tttt |
| Full packets | sudo tcpdump -i eth0 -s 0 |
| Line-buffered for grep | sudo tcpdump -i eth0 -l | grep 192.168.1.100 |
| Rotate every 60 seconds | sudo tcpdump -i eth0 -G 60 -w cap-%H-%M-%S.pcap |
| Rotate at 100 MB | sudo tcpdump -i eth0 -C 100 -W 5 -w cap.pcap |
| DNS queries only | sudo tcpdump -i eth0 udp port 53 |
| Ping traffic only | sudo tcpdump -i eth0 icmp |
| SSH traffic only | sudo tcpdump -i eth0 port 22 |
| Packets over 1000 bytes | sudo tcpdump -i eth0 greater 1000 |
Troubleshooting Tcpdump Problems
| Problem | Likely cause | Fix |
|---|---|---|
You don't have permission to capture on that device | No root or capability | Run with sudo, or grant cap_net_raw with setcap |
tcpdump: no suitable device found | No usable interface or no permission | Run with sudo; check tcpdump -D lists interfaces |
tcpdump: eth0: No such device exists | Wrong interface name | List interfaces with tcpdump -D and use the exact name |
command not found: tcpdump | Not installed | Install per your OS (see Installing Tcpdump) |
| Capture shows no packets | Wrong interface, or filter too narrow | Try -i any, then drop the filter and add it back piece by piece |
| Output is very slow | DNS lookups on every packet | Add -nn to disable hostname and port resolution |
packets dropped by kernel | Capture buffer too small for the traffic rate | Tighten the filter, or raise the buffer with -B 4096 |
| Empty pcap file | Capture stopped before any matching packet arrived | Check the filter matches real traffic; capture without -c for longer |
listening on eth0 then nothing | Quiet network, or the filter excludes everything | Generate traffic (ping, curl) and confirm the interface carries it |
Common Mistakes
tcpdump -D first.-nn. Without it, every packet triggers DNS lookups, output crawls, and the capture itself can fall behind.-w file on a busy interface fills the disk. Use -G or -C for anything longer than a few minutes.Best Practices
-nn. Name resolution slows captures and can change what you see. Resolve names afterwards if you need them.-s 0 for full packets. Truncated packets hide payloads; modern defaults are generous, but verify on older builds.-G or -C with -W keeps disk usage bounded.When Not to Use Tcpdump
Tcpdump cannot read encrypted payloads, so it will not show you the contents of an HTTPS session, a VPN tunnel, or an SSH connection — only their metadata. On very high-speed links it drops packets unless the filter is tight and the buffer is large, so it is the wrong tool for full-rate capture on a gigabit backbone (use a dedicated tap or a capture appliance). And the legal boundary is absolute: capture only traffic on systems you own or have written permission to test. Intercepting traffic on a network you do not control is illegal in most jurisdictions, including India under the IT Act — the lab-only framing in this guide is not optional.
Keep Learning
Summary
Tcpdump is the standard command-line packet capture tool. Key techniques include BPF filters, saving to files, and understanding output format. The workflow is always the same: list interfaces, capture with a tight filter, save to a pcap, and analyze afterwards — in tcpdump, tshark, or Wireshark. Learn the six-step workflow, the BPF primitives, and the cheat sheet in this guide, and you can answer "what actually crossed the wire?" for almost any network problem.
Knowledge Check
-nn do?-w and -r?-G 60 do when combined with -w?Answers: 1. It disables both hostname and port number resolution, so output shows raw IPs and port numbers and no DNS lookups slow the capture. 2. Use sudo tcpdump -i eth0 port 80 (or tcp and port 80); for HTTPS use port 443, but the payload will be encrypted. 3. [S] is SYN (connection start), [S.] is SYN-ACK, [.] is ACK — the three packets of the TCP handshake. 4. -w writes packets to a pcap file, -r reads packets back from a pcap file for display or analysis. 5. Unfiltered captures on busy networks generate massive files and include irrelevant traffic; BPF filters capture only matching packets. 6. Run tcpdump -D, which lists every available interface with its number. 7. HTTPS encrypts the payload, so tcpdump sees only metadata — IPs, ports, and the TLS handshake including the SNI hostname — not the page content. 8. It rotates the output file every 60 seconds, writing each interval to a new timestamped file.
Frequently Asked Questions
Continue Learning
How to Use Dirb: Beginner's Guide to Directory Brute-Forcing in Kali Linux
Learn how to use Dirb in Kali Linux: run your first directory scan, pick the right wordlist, and read the results — with a worked example and cheat sheet.
Tools · BeginnerHow to Use FFUF: Beginner's Guide to Fast Web Fuzzing in Kali Linux
Learn how to use FFUF in Kali Linux — directory, subdomain and vhost fuzzing, parameter testing, filters and a worked DVWA example, with a cheat sheet.
Tools · BeginnerHow to Use Gobuster: Beginner's Guide to Directory, DNS & VHost Enumeration in Kali Linux
Learn how to use Gobuster in Kali Linux — dir, DNS and vhost modes, wordlists, and a worked DVWA example, with a cheat sheet and troubleshooting.
Tools · BeginnerHow to Use Netcat: Beginner's Guide to the nc Command in Kali Linux
How to use Netcat (nc) in Kali Linux: test ports, run a listener, grab banners, transfer files, and catch a reverse shell — worked example and cheat sheet.
Related Security Tools
tcpdump
tcpdump is a powerful, lightweight command-line packet analyzer that allows users to capture, parse, and filter TCP/IP and other packets transmitted or received over a network.
Sniffing & SpoofingWireshark
Wireshark tutorial for beginners: capture packets, read the three panes, filter traffic and follow TCP streams — a hands-on guide to the world's foremost network protocol analyzer.
Sniffing & SpoofingNetcat
Learn how to use Netcat (nc) in Kali Linux to open a TCP or UDP connection, check a port, and see what a service sends back. Follow the examples to send your first message, inspect HTTP and SMTP responses, and transfer a test file without exposing sensitive data.
Wireless AttacksWifite
Learn how to use Wifite in Kali Linux with this beginner tutorial: check your WiFi adapter, install Wifite, run your first authorized WiFi audit, capture WPA handshakes and PMKIDs, and crack them with a wordlist. Includes Wifite commands, a worked example, troubleshooting for common errors, and how Wifite compares with Aircrack-ng.