Skip to content

tcpdump MacOS command

The MacOS tcpdump command is a versatile network analysis tool used to capture and analyze network traffic. It allows users to inspect incoming and outgoing packets, monitor network activity, troubleshoot network issues, and analyze network protocols. With tcpdump, users can filter and display packets based on various criteria, such as source and destination IP addresses, ports, protocols, and packet types. This command provides detailed information about network traffic, making it an essential tool for network administrators, security professionals, and anyone looking to understand and troubleshoot their network communications.

tcpdump Syntax:

Terminal window
tcpdump [ -AbdDefhHIJKlLnNOpqStuUvxX ] [ -B buffer_size ] [ -c count ] [ -C file_size ] [ -G rotate_seconds ] [ -W file_count ] [ -M secret ] [ -m module ] [ -r file ] [ -s snaplen ] [ -T type ] [ -w file ] [ -X ] [ -E discard ] [ -P in|out|inout ] [ -i interface ] [ expression ]

tcpdump Options:

OptionDescription
-APrint each packet (minus its link level header) in ASCII.
-bPrint 32-bit DWORDs in libpcap capture format.
-c countExit after receiving count packets.
-C file_sizeBefore actually starting to write to a savefile, check whether the file with the name currently being written to is larger than file_size.
-dDump the compiled form of the filter expression as a C program fragment.
-ePrint the link level header on each dump line.
-fPrint filter code in a human readable form.
-hPrint packets in a human readable form.
-HPrint packet data (minus its link level header) in HEX and ASCII.
-IPrint Layer 2 information on each dump line.
-KUsed in conjunction with the -C or -G options.
-lMake standard output line buffered.
-nDo not convert addresses (host addresses, port numbers, etc.) to names.
-NPrint the data of each packet (including its link level header) in HEX.
-OPrint packet data in the manner of `od -Ax -tx1’.
-pDon’t put the interface into promiscuous mode.
-qQuick output. Print less protocol information so output lines are shorter.
-SPrint absolute, rather than relative, TCP sequence numbers.
-tDon’t print a timestamp on each dump line.
-uDisplay undecoded NFS handles instead of the UID/GID.
-UMake output packets appear under control of the user (normal output packets are not).
-vPrint more verbose output.
-xPrint each packet (minus its link level header) in HEX.
-XPrint each packet (minus the link level header) in HEX and ASCII.

Parameters:

ParameterDescription
buffer_sizeSet the buffer size for reading packets.
countSpecify the number of packets to capture before exiting.
file_sizeSet the maximum file size for the savefile before rotating.
rotate_secondsRotate capture files after a specified number of seconds.
file_countSet the maximum number of files to keep.
secretEncrypt captured data with a secret key.
moduleSpecify a decoding module.
fileRead packets from a specified saved file.
snaplenSet the snapshot length for each packet.
typeForce the interpretation of the link layer header.
expressionFilter expression to select only specific packets for capturing.

tcpdump Command Usage Examples:

Capture all Traffic on a Specific Interface

Terminal window
sudo tcpdump -i en0

Captures all network traffic on the “en0” interface.

Display Filters for a Specific Port

Terminal window
sudo tcpdump port 80

Displays all packets with port 80 in the network traffic.

Save Captured Traffic to a File

Terminal window
sudo tcpdump -i en0 -w captured.pcap

Captures network traffic on “en0” interface and saves it to a file named “captured.pcap”.

Display Traffic for a Specific IP Address

Terminal window
sudo tcpdump host 192.168.1.100

Shows network traffic involving the IP address 192.168.1.100.

Monitor DNS Traffic

Terminal window
sudo tcpdump -i en0 port 53

Captures and displays DNS traffic on the “en0” interface.

How do I use tcpdump in MacOS?

To use the tcpdump command in bash, execute the following command:

Terminal window
tcpdump -i en0

What is the syntax for filtering traffic in tcpdump?

To filter specific traffic using tcpdump, you can use the following syntax:

Terminal window
tcpdump -i en0 tcp port 80

How can I save tcpdump output to a file in MacOS?

To save the tcpdump output to a file in MacOS, you can use the following command:

Terminal window
tcpdump -i en0 -w output.pcap

How do I display detailed packet information with tcpdump?

To display detailed packet information while using tcpdump in MacOS, you can use the following command:

Terminal window
tcpdump -i en0 -vvv

How do I specify the number of packets to capture with tcpdump?

To specify the number of packets to capture using tcpdump in MacOS, you can use the following command:

Terminal window
tcpdump -i en0 -c 10

How do I capture traffic for a specific IP address with tcpdump?

To capture traffic for a specific IP address using tcpdump in MacOS, you can use the following command:

Terminal window
tcpdump -i en0 host 192.168.1.1

How do I analyze tcpdump output using Wireshark in MacOS?

To analyze tcpdump output using Wireshark in MacOS, you can save the tcpdump output to a .pcap file and then open it in Wireshark:

Terminal window
tcpdump -i en0 -w output.pcap

How can I view the entire packet contents with tcpdump in MacOS?

To view the entire packet contents while using tcpdump in MacOS, you can use the following command:

Terminal window
tcpdump -i en0 -X

Applications of the tcpdump command

  • Capturing network packets
  • Analyzing network traffic
  • Troubleshooting network issues
  • Monitoring network activity
  • Performing security analysis