Linux tcpdump Command — Capturing and Analyzing Network Packets¶
tcpdumpis one of the most powerful command-line network packet analyzers available on Linux and Unix systems. It captures and displays network packets in real time, allowing administrators to inspect protocols, troubleshoot connectivity issues, analyse application traffic, investigate security incidents, and debug complex network problems.tcpdumpworks directly with network interfaces using the libpcap library and is widely used by Linux administrators, DevOps engineers, Cloud Architects, Platform Engineers, Site Reliability Engineers (SRE), Network Engineers, and Security Analysts.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand
tcpdump - Capture network packets
- Filter traffic efficiently
- Analyse network protocols
- Save and read packet captures
- Troubleshoot production networking issues
- Perform basic security investigations
Prerequisites¶
Complete:
Basic understanding of:
- TCP/IP
- OSI Model
- Ports
- Routing
Why Learn tcpdump?¶
Suppose users report:
- Website Not Working
- API Timeout
- DNS Failure
- Packet Loss
- Slow Application
- Unknown Network Traffic
Sometimes:
But packets are not reaching their destination.
The best way to investigate is to:
using:
What is tcpdump?¶
tcpdump captures packets directly from a network interface.
It can inspect:
- Ethernet Frames
- IPv4
- IPv6
- Transmission Control Protocol (TCP)
- User Datagram Protocol (UDP)
- Internet Control Message Protocol (ICMP)
- Address Resolution Protocol (ARP)
- Domain Name System (DNS)
- HTTP
- HTTPS Metadata
- Many Other Protocols
Packet Capture Workflow¶
Every packet can be inspected before it leaves or after it reaches the interface.
Basic Syntax¶
Example:
Administrator privileges are usually required because packet capture accesses raw network traffic.
List Available Interfaces¶
Example:
Capture Packets¶
Capture packets on the default interface.
Capture on Specific Interface¶
Capture on All Interfaces¶
Useful for servers with multiple interfaces.
Limit Number of Packets¶
Capture only ten packets.
Disable Name Resolution¶
Benefits:
- Faster Output
- Displays Numeric IP Addresses
- Easier Troubleshooting
Display Detailed Output¶
Extra verbosity:
Display Packet Contents¶
Hexadecimal:
ASCII + Hex:
Save Packets to File¶
This stores packets in PCAP format for later analysis.
Read Saved Capture¶
Capture Only TCP Traffic¶
Capture Only UDP Traffic¶
Capture ICMP Packets¶
Useful when troubleshooting:
Capture ARP Traffic¶
Useful for Layer 2 troubleshooting.
Filter by Host¶
Capture traffic to or from:
Filter by Source¶
Filter by Destination¶
Filter by Port¶
Capture HTTP traffic.
Capture HTTPS traffic.
Capture SSH traffic.
Filter by Source Port¶
Filter by Destination Port¶
Combine Filters¶
Example:
Another example:
Boolean Operators¶
Supported operators:
Example:
DNS Troubleshooting¶
Capture DNS traffic.
Useful for:
- DNS Queries
- DNS Responses
- DNS Timeouts
HTTP Troubleshooting¶
Inspect:
- HTTP Requests
- HTTP Responses
HTTPS Troubleshooting¶
Although encrypted payloads cannot be read without appropriate decryption material, you can still analyse:
- TCP Handshake
- TLS Handshake Metadata
- Connection Resets
- Retransmissions
SSH Troubleshooting¶
Useful for:
- Connection Attempts
- Failed Handshakes
- Session Establishment
Enterprise Example¶
Web Application:
Users report slow responses.
Capture:
Investigate:
- Retransmissions
- Packet Loss
- Connection Resets
- Delays
Cloud Perspective¶
Cloud engineers use tcpdump to troubleshoot:
- Virtual Machines
- VPN Connectivity
- Load Balancers
- NAT Gateways
- Kubernetes Nodes
- DNS Resolution
Kubernetes Perspective¶
Run:
Common interfaces:
Useful for:
- Pod Communication
- Service Traffic
- DNS Issues
- Overlay Network Debugging
Linux Perspective¶
Capture all traffic.
Capture DNS.
Capture SSH.
Save capture.
Read capture.
Common Packet Filters¶
| Command | Purpose |
|---|---|
tcpdump tcp | TCP packets |
tcpdump udp | UDP packets |
tcpdump icmp | ICMP packets |
tcpdump arp | ARP packets |
tcpdump port 80 | HTTP traffic |
tcpdump port 443 | HTTPS traffic |
tcpdump port 53 | DNS traffic |
tcpdump host IP | Traffic for a specific host |
Hands-on Lab¶
Task 1¶
List interfaces.
Task 2¶
Capture ten packets.
Task 3¶
Capture on all interfaces.
Task 4¶
Capture DNS traffic.
Task 5¶
Capture HTTP traffic.
Task 6¶
Save captured packets.
Task 7¶
Read the saved capture.
Task 8¶
Capture SSH traffic between your workstation and a Linux server.
Observe the TCP handshake and SSH session establishment.
Production Troubleshooting¶
Problem:
Check:
↓
Packets Leaving?
↓
Packets Returning?
↓
TCP Handshake Complete?
↓
Retransmissions?
↓
RST Packets?
This packet-level visibility helps isolate network, firewall, or application issues.
Common Mistakes¶
❌ Capturing without filters.
✅ Apply filters to reduce unnecessary traffic.
❌ Forgetting sudo.
✅ Packet capture generally requires elevated privileges.
❌ Leaving long captures running.
✅ Use -c or save to a file and stop captures promptly.
❌ Capturing on the wrong interface.
✅ Verify interfaces with tcpdump -D or ip link.
❌ Expecting HTTPS payloads to be readable.
✅ Remember that TLS encrypts application data.
Best Practices¶
- Capture only the traffic you need.
- Use filters to reduce noise.
- Save captures in PCAP format for later analysis.
- Disable DNS resolution using
-nduring troubleshooting. - Capture on the correct interface.
- Protect packet capture files because they may contain sensitive metadata or data.
- Remove packet capture files after investigations if they are no longer required.
Interview Questions¶
Beginner¶
- What is
tcpdump? - How do you capture packets on a specific interface?
- How do you save captured packets?
- What is a PCAP file?
Intermediate¶
- How do you filter traffic by host and port?
- Why is
tcpdumpuseful for DNS troubleshooting? - How do you analyse HTTPS traffic with
tcpdump? - Explain the difference between capturing and reading packets.
Architect Level¶
- Explain how you would troubleshoot intermittent packet loss using
tcpdump. - Design a packet capture strategy for a production Kubernetes cluster.
- How would you investigate an application that experiences random connection resets?
Summary¶
In this lesson, you learned:
- The
tcpdumpcommand - Packet Capture
- Traffic Filtering
- Protocol Analysis
- PCAP Files
- DNS Troubleshooting
- HTTP and HTTPS Analysis
- Enterprise Network Diagnostics
tcpdump is one of the most valuable networking tools available on Linux. It allows engineers to inspect network traffic at the packet level, making it possible to troubleshoot connectivity issues, investigate performance problems, verify protocol behaviour, and support security investigations. Mastering tcpdump is an essential skill for production Linux, cloud, Kubernetes, and enterprise networking environments.
Key Takeaways¶
tcpdumpcaptures live network packets.- Use
-ito select a network interface. - Use
-wto save packets in PCAP format. - Use
-rto read previously captured packets. - Apply filters by host, port, or protocol to simplify analysis.
tcpdumpis a fundamental tool for troubleshooting DNS, TCP, HTTP, VPN, Kubernetes, and cloud networking issues.
What's Next?¶
In the next lesson, you'll learn about traceroute.
You'll explore:
- What
tracerouteis - How packet forwarding works
- Hop-by-Hop Path Discovery
- TTL (Time To Live)
- Network Latency Analysis
- Routing Troubleshooting
- Enterprise Connectivity Diagnostics
By the end of the lesson, you'll understand how to trace the path packets take across networks, identify routing problems, locate high-latency links, and troubleshoot connectivity issues in enterprise, cloud, and Internet environments.