SOC and blue team

Tcpdump Command for Beginners: Capture and Filter Traffic

tcpdump captures network traffic from the command line. It runs on servers and firewalls where there is no screen, which is why defenders keep it close. This guide covers the commands you will use most. Capture only on networks you own or administer.

First Capture

  • sudo tcpdump -i eth0 -nn -c 20

-i eth0 picks the interface (list them with ip link), -nn stops name lookups so output is faster and clearer, and -c 20 stops after 20 packets.

Filters You Will Use

  • host 192.168.56.20 shows traffic to or from one machine.
  • port 80 shows one port; port 53 shows DNS.
  • tcp and dst port 22 shows connections going to SSH.
  • "tcp[tcpflags] & tcp-syn != 0" shows packets with the SYN flag, the start of a connection and the signature of a port scan.

Read a Line

A line shows the time, the protocol, source address and port, an arrow, the destination and the TCP flags. Flags [S] is SYN, [S.] is SYN-ACK and [.] is ACK. Add -A to print the payload as text, which shows plain HTTP requests. That is also why unencrypted protocols are a risk.

Save and Analyze

  • sudo tcpdump -i eth0 -w capture.pcap saves packets to a file.
  • tcpdump -nn -r capture.pcap reads it back.
  • Open the file in Wireshark for a closer look; see Wireshark for beginners.

Command Cheat Sheet

  • sudo tcpdump -i any -nn captures on all interfaces without name lookups.
  • -c 50 stops after 50 packets.
  • host 192.168.56.20, net 192.168.56.0/24, port 443, portrange 1-1024 filter traffic.
  • src host X and dst port N filter by direction.
  • -A prints payload as text; -X prints hex and text.
  • -e shows link-level headers.
  • -w file.pcap saves and -r file.pcap reads a capture.

Try It

Capture SYN packets on a lab VM, then run a scan from another VM with Nmap, as in Nmap for beginners. Watch how a scan looks from the defender's side. This is network traffic monitoring, a topic in the CND syllabus and in SOC work.

Sources and Further Reading

Want to practice detection in a supervised lab? Book free trial classes. Contact us or call +91 86868 92922.

Start Your Cyber Security Career

Talk to a counselor, choose the right course for your goals, and get the fee, syllabus and next batch dates in writing.

Book Free Trial Classes

By submitting, you agree that Hacking Trainer Academy may contact you about courses by phone, WhatsApp or email. See our privacy notice and refund policy.

WhatsApp