The Ultimate tcpdump Cheat Sheet: Packet Capture Made Easy

Listen to this Post

Master network traffic analysis with tcpdump! This cheat sheet covers essential commands, filters, and switches to help you capture and analyze packets efficiently. Get the syntax right and enhance your troubleshooting skills.
📡 Read more: https://lnkd.in/e744dqci

Essential tcpdump Commands and Examples

1. Capture packets on a specific interface:

tcpdump -i eth0 

2. Capture a specific number of packets:

tcpdump -c 10 

3. Capture packets and save to a file:

tcpdump -w capture.pcap 

4. Read packets from a saved file:

tcpdump -r capture.pcap 

5. Filter packets by IP address:

tcpdump host 192.168.1.1 

6. Filter packets by port:

tcpdump port 80 

7. Capture only TCP packets:

tcpdump tcp 

8. Capture packets with verbose output:

tcpdump -v 

9. Capture packets with detailed output:

tcpdump -vvv 

10. Filter packets by source IP:

tcpdump src 192.168.1.1 

11. Filter packets by destination IP:

tcpdump dst 192.168.1.1 

12. Capture packets with a specific size:

tcpdump greater 100 

13. Combine filters:

tcpdump src 192.168.1.1 and port 22 

14. Capture packets and display in ASCII:

tcpdump -A 
  1. Capture packets and display in HEX and ASCII:
    tcpdump -XX 
    

What Undercode Say

tcpdump is an indispensable tool for network administrators and cybersecurity professionals. It allows you to capture and analyze network traffic in real-time, making it easier to diagnose network issues, detect anomalies, and secure your systems. By mastering tcpdump commands, you can filter and inspect packets with precision, ensuring efficient troubleshooting and enhanced network security.

For example, using `tcpdump -i eth0` lets you monitor traffic on a specific interface, while `tcpdump port 80` helps you focus on HTTP traffic. Combining filters like `src 192.168.1.1 and port 22` enables you to pinpoint SSH traffic from a specific source. Saving captures with `tcpdump -w capture.pcap` allows for offline analysis, and reading them back with `tcpdump -r capture.pcap` ensures you can review data at any time.

In addition to tcpdump, other Linux commands like netstat, nmap, and `wireshark` complement network analysis. For instance, `netstat -tuln` lists all listening ports, while `nmap 192.168.1.1` scans a target for open ports and services. Wireshark provides a graphical interface for deeper packet inspection.

For Windows users, tools like `netsh` and `Powershell` commands such as `Test-NetConnection` are invaluable. For example, `netsh trace start capture=yes` captures network traces, and `Test-NetConnection -ComputerName google.com -Port 80` tests connectivity to a specific port.

To further enhance your skills, explore advanced tcpdump filters, such as capturing only SYN packets with tcpdump 'tcp[tcpflags] & (tcp-syn) != 0'. Additionally, integrating tcpdump with scripting languages like Python can automate network monitoring tasks.

For more resources, visit:

By combining tcpdump with other tools and commands, you can build a robust network analysis toolkit, ensuring your systems remain secure and efficient.

References:

initially reported by: https://www.linkedin.com/posts/stationx_the-ultimate-tcpdump-cheat-sheet-packet-activity-7300062751354212352-C6NW – Hackers Feeds
Extra Hub:
Undercode AIFeatured Image