tcpdump — Capturing and Analyzing Network Packets in Real Time¶
tcpdump is a command-line packet analyzer used to capture, inspect, and analyze network traffic directly from a network interface. It allows administrators to observe every packet entering or leaving a system, making it one of the most powerful tools for diagnosing network connectivity issues, DNS failures, TCP handshake problems, HTTP requests, TLS communication, routing issues, packet loss, and Kubernetes networking problems. Every Linux Administrator, Network Engineer, DevOps Engineer, SRE, Cloud Architect, Security Engineer, and Kubernetes Administrator should master tcpdump.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand packet capturing
- Capture network traffic using tcpdump
- Apply capture filters
- Analyze TCP handshakes
- Inspect DNS, HTTP, and HTTPS traffic
- Troubleshoot production networking issues
- Capture packets in cloud and Kubernetes environments
Prerequisites¶
Complete:
- Ping
- traceroute
- TCP/IP
- Linux Networking
- Routing
Basic understanding of:
- Transmission Control Protocol (TCP)
- User Datagram Protocol (UDP)
- Internet Control Message Protocol (ICMP)
- Domain Name System (DNS)
- HTTP
Why Do We Need tcpdump?¶
Imagine an application reports:
Ping works.
Traceroute works.
But:
- Is the packet leaving the server?
- Is the response returning?
- Is DNS working?
- Is TLS failing?
- Is TCP completing the handshake?
The answer is:
What is tcpdump?¶
tcpdump is:
It captures packets directly from a network interface.
Packet Capture Workflow¶
tcpdump observes packets before applications process them.
Where tcpdump Works¶
tcpdump can capture traffic from:
- Ethernet
- Wi-Fi
- Loopback
- Virtual Interfaces
- Docker Networks
- Kubernetes Nodes
- VPN Interfaces
List Network Interfaces¶
Display available interfaces.
Example:
Capture All Traffic¶
Capture packets on:
Packets appear in real time.
Capture Limited Packets¶
Capture only ten packets.
Useful during quick troubleshooting sessions.
Disable Name Resolution¶
Avoid DNS lookups.
Advantages:
- Faster Output
- Raw IP Addresses
- Easier Troubleshooting
Verbose Output¶
Increase details.
or
Displays:
- Time To Live (TTL)
- Window Size
- TCP Options
- Flags
Save Packets¶
Write captures to a file.
The file can later be opened in:
- Wireshark
- tcpdump
Read Saved Packets¶
Analyze previously captured traffic.
Packet Flow¶
tcpdump records every packet that reaches the selected interface.
Capture Filters¶
Capture only traffic matching specific conditions.
Examples:
Host:
Source Host:
Destination Host:
Port Filters¶
Capture traffic on port:
Specific destination port:
Multiple ports:
Protocol Filters¶
Capture ICMP.
Capture TCP.
Capture UDP.
Network Filters¶
Capture an entire subnet.
Useful for analyzing traffic across multiple hosts.
Boolean Filters¶
Example:
Example:
Filters can combine:
- and
- or
- not
TCP Three-Way Handshake¶
Capture:
tcpdump allows you to verify whether the TCP connection completes successfully.
Example TCP Output¶
A successful handshake indicates the TCP session is established.
DNS Troubleshooting¶
Capture DNS traffic.
Observe:
- DNS Query
- DNS Response
Useful when applications cannot resolve hostnames.
HTTP Troubleshooting¶
Capture HTTP.
View:
- HTTP Requests
- HTTP Responses
HTTPS Troubleshooting¶
Capture encrypted traffic.
Although payloads are encrypted, you can still inspect:
- TCP Handshake
- TLS Handshake
- Packet Sizes
- Retransmissions
ICMP Troubleshooting¶
Capture Ping packets.
Observe:
Useful for validating connectivity.
Kubernetes Perspective¶
Capture packets on a Kubernetes node.
Capture Pod traffic.
Useful for:
- Container Network Interface (CNI) Debugging
- Service Issues
- Network Policies
- DNS Resolution
Docker Perspective¶
Capture Docker bridge traffic.
Useful for container networking analysis.
Cloud Perspective¶
Capture traffic on:
- AWS EC2
- Azure VM
- Google Compute Engine
Common use cases:
- Security Group Validation
- Firewall Troubleshooting
- VPN Diagnostics
Enterprise Troubleshooting Workflow¶
Each tool provides progressively deeper visibility.
Common TCP Flags¶
| Flag | Meaning |
|---|---|
| SYN | Start Connection |
| ACK | Acknowledgement |
| FIN | Close Connection |
| RST | Reset Connection |
| PSH | Push Data |
| URG | Urgent Data |
CLI Examples¶
Capture on interface.
Capture ten packets.
Capture DNS traffic.
Capture HTTPS traffic.
Save capture.
Read capture.
Hands-on Lab¶
Task 1¶
List network interfaces.
Task 2¶
Capture ten packets.
Task 3¶
Ping another host while running:
Observe:
- Echo Request
- Echo Reply
Task 4¶
Capture DNS queries.
Run:
Observe the request and response.
Task 5¶
Capture HTTPS traffic.
Browse a secure website and observe the TCP and TLS handshakes.
Task 6¶
Save a packet capture.
Open the file later in Wireshark.
Task 7¶
Capture traffic on a Kubernetes node while accessing a ClusterIP Service.
Task 8¶
Draw the packet journey:
Explain what tcpdump captures at every stage.
Production Troubleshooting¶
Problem:
Check:
- DNS Query
- TCP SYN
- SYN-ACK
- ACK
- TLS Handshake
- HTTP Request
- Firewall
- Packet Loss
Workflow:
tcpdump vs Wireshark¶
| tcpdump | Wireshark |
|---|---|
| Command Line | Graphical Interface |
| Lightweight | Rich Visualization |
| Live Capture | Live & Offline Analysis |
| Ideal for Servers | Ideal for Desktop Analysis |
| Low Resource Usage | Higher Resource Usage |
Common Mistakes¶
❌ Capturing all traffic without filters.
✅ Apply capture filters to reduce unnecessary data.
❌ Forgetting -n.
✅ Disable DNS resolution for faster and clearer output.
❌ Capturing on the wrong interface.
✅ Verify the correct interface using tcpdump -D.
❌ Ignoring packet timestamps.
✅ Use timestamps to correlate events with application logs.
❌ Leaving long-running captures active.
✅ Limit packet count or duration to avoid large capture files.
Best Practices¶
- Capture only the traffic you need.
- Always identify the correct interface before capturing.
- Save important captures as
.pcapfiles. - Use filters to minimize noise.
- Combine tcpdump with application logs.
- Analyze complex captures using Wireshark.
- Remove sensitive packet captures after analysis.
- Be aware of privacy and security requirements when capturing production traffic.
Interview Questions¶
Beginner¶
- What is tcpdump?
- What is a packet capture?
- How do you capture packets on an interface?
- What is a
.pcapfile?
Intermediate¶
- Explain the TCP three-way handshake using tcpdump.
- How do you capture only DNS traffic?
- Compare tcpdump and Wireshark.
- How would you troubleshoot a failed HTTPS connection?
Architect Level¶
- Design a packet capture strategy for a production Kubernetes cluster.
- Explain how tcpdump helps diagnose intermittent network failures.
- How would you troubleshoot application connectivity across cloud regions using packet captures?
Summary¶
In this lesson, you learned:
- tcpdump
- Packet Capture
- Capture Filters
- TCP Three-Way Handshake
- DNS Analysis
- HTTP Analysis
- HTTPS Analysis
- ICMP Analysis
- Kubernetes Packet Capture
- Production Network Troubleshooting
tcpdump is one of the most powerful command-line tools for network troubleshooting. It provides direct visibility into packets flowing across network interfaces, allowing engineers to diagnose connectivity issues, routing problems, protocol failures, and application communication with precision. It is an essential skill for Linux, cloud, networking, and Kubernetes professionals.
Key Takeaways¶
- tcpdump captures packets directly from network interfaces.
- Use capture filters to focus on relevant traffic.
- Verify the TCP three-way handshake when troubleshooting connection issues.
- Capture DNS, HTTP, HTTPS, and ICMP traffic for protocol-specific analysis.
- Save captures as
.pcapfiles for later analysis in Wireshark. - Combine tcpdump with Ping, traceroute, and application logs for systematic troubleshooting.
What's Next?¶
In the next lesson, you'll learn about Wireshark.
You'll explore:
- Packet Analysis
- Protocol Decoding
- Display Filters
- TCP Stream Analysis
- DNS Analysis
- HTTP and HTTPS Inspection
- Production Packet Investigation
By the end of the lesson, you'll be able to analyse packet captures visually, inspect network protocols in depth, and diagnose complex networking issues using one of the industry's most powerful protocol analyzers.