from man page for version 4.3.0 -- Apple version 56,
libpcap version 1.3.0 - Apple version 41
The latest release as of 11/05/16 from tcpdump.org is Version: 4.8.1 / 1.8.1,
the documentation is current as of September 2015 Severly terseified by DG12
see the man page for the true(?) story
Outputs packets on a network interface that match the boolean
-w, writes the packet data to a file for later analysis,
-r, reads from a saved file .
In all cases, only packets that match expression will be processed.
Continues until it is interrupted by a SIGINT signal (generated, by typing the interrupt character, typically ^C) or
a SIGTERM signal (typically generated with the kill command) or
-c the specified number of packets have been processed.
On SIGINFO ( typing status character, frequently ^T, set via
stty status ^T) reports:
packets received by filter (depends on the OS and it's configuration)
packets dropped by kernel (due to a lack of buffer space,
by the packet capture mechanism in the OS
Reading packets from a network interface requires privileges, from a saved packet file doesn't .
sudo tcpdump -i en1 host 192.168.1.12 and udp port 514#
General TCP monitor (without header display, removing multiple "dots" and activity to google (1e100.net)
sudo tcpdump -A -q tcp |sed "s/\.\.//g ; /1e100.net/d"
selects which packets will be dumped. Default: all
For the expression syntax, see pcap-filter.
Expression arguments can be passed as either a single argument or as multiple arguments.
if the expression contains Shell metacharacters, it is easier to pass it as a single, quoted argument.
Multiple arguments are concatenated with spaces before being parsed.
packets arriving at or departing from sundown:
tcpdump host sundown
traffic between helios and either hot or ace:
tcpdump host helios and \( hot or ace \) # escaping parentheses
IP packets between ace and any host except helios:
tcpdump ip host ace and not helios
traffic between local hosts and hosts at Berkeley:
tcpdump net ucb-ether
ftp traffic through internet gateway sunup:
(the expression is quoted to prevent the shell from interpreting the parentheses):
tcpdump 'gateway sunup and (port ftp or ftp-data)'
traffic neither sourced from nor destined for local hosts (if you gateway to one other net, this should never make it
onto your local net).
tcpdump ip and not net localnet
the start and end packets (the SYN and FIN packets) of each TCP conversation that involves a non-local host.
tcpdump 'tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net localnet' # fails!
HTTP packets to & from port 80, only packets that contain data, not, for example, SYN and FIN packets and ACK-only packets.
tcpdump 'tcp port 80 and (((ip[2:2] - ((ip&0xf)<<2)) - ((tcp&0xf0)>>2)) != 0)'
IP packets longer than 576 bytes sent through gateway sunup:
tcpdump 'gateway sunup and ip[2:2] > 576' # len
IP broadcast or multicast packets that were not sent via Ethernet broadcast or multicast:
tcpdump 'ether & 1 = 0 and ip >= 224' # BCST & muticast NOT sent via eth or multicast
all ICMP packets that are not echo requests/replies (i.e., not ping packets):
tcpdump 'icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply' #ICMP not pings
-e the link level header is displayed.
arp who-has csam tell rtsg arp reply csam is-at CSAMcsam replies with its Ethernet address (Ethernet addresses are caps, internet lower case).
arp who-has 18.104.22.168 tell 22.214.171.124 arp reply 126.96.36.199 is-at 02:07:01:00:01:c4
-e, the fact that the first packet is broadcast and the second is point-to-point would be visible:
RTSG Broadcast 0806 64: arp who-has csam tell rtsg CSAM RTSG 0806 64: arp reply csam is-at CSAMFirst packet this says the Ethernet source address is RTSG, the destination is the Ethernet broadcast address, the type field contained hex 0806 (type ETHER_ARP) and the total length was 64 bytes.
The general format is:
src > dst: flags data-seqno ack window urgent optionsFlags may include
noneif no flags are set.
Data-seqnodescribes the portion of sequence space covered by the data in this packet (see example below).
Ackis sequence number of the next data expected the other direction on this connection.
Windowis the number of bytes of receive buffer space available the other direction on this connection.
Urg`urgent' data in the packet.
Src, dst and flags are always present. The other fields depend on the contents of the packet's tcp protocol header
1 rtsg.1023 > csam.login: S 768512:768512(0) win 4096Line 1: rtsg from port 1023 sends a packet to csam's login port. S indicates SYN flag .
2 csam.login > rtsg.1023: S 947648:947648(0) ack 768513 win 4096 3 rtsg.1023 > csam.login: . ack 1 win 4096 4 rtsg.1023 > csam.login: P 1:2(1) ack 1 win 4096 5 csam.login > rtsg.1023: . ack 2 win 4096 6 rtsg.1023 > csam.login: P 2:21(19) ack 1 win 4096 7 csam.login > rtsg.1023: P 1:2(1) ack 21 win 4077 8 csam.login > rtsg.1023: P 2:3(1) ack 21 win 4077 urg 1 9 csam.login > rtsg.1023: P 3:4(1) ack 21 win 4077 urg 1
line 2: csam replies with a similar packet except it includes a piggy-backed ACK for rtsg's SYN.
line 3: Rtsg then acks csam's SYN. The `.' means the ACK flag was set.
The packet contained no data so there is no data sequence number.
The ack sequence number is a small integer (1).
The first time tcpdump sees a tcp conversation it outputs the sequence number from the packet.
On subsequent packets of the conversation, are relative byte positions in the conversation's data stream (with the first data byte each direction being `1').
-S overrides this.
line 6: rtsg sends csam 19 bytes of data (bytes 2 through 20 in the rtsg -> csam side of the conversation). PUSH is
line 7: csam says it's received data sent by rtsg up to but not including byte 21. Most of this data is apparently sitting in the socket buffer since csam's receive window has gotten 19 bytes smaller.
(1) byte of data.
line 8: csam sends (1) byte of urgent, pushed data to rtsg.
line 9: csam sends (1) byte of urgent, pushed data to rtsg.
If the snapshot was too small to include the complete TCP header, it interprets as much of the header as it can and
then reports [|tcp] to indicate the remainder could not be interpreted.
If the header contains a bogus option (one with a length that's either too small or beyond the end of the header), tcpdump reports it as
[bad opt] and does not interpret any further
If the header length indicates options are present but the IP datagram length is not long enough for the options to actually be there, tcpdump reports it as
[bad hdr length].
There are 8 bits in the control bits section of the TCP header:
CWR | ECE | URG | ACK | PSH | RST | SYN | FIN
To watch packets used in establishing a TCP connection, a 3-way handshake protocol when it initializes a new connection;
Capturing packets that have only the SYN bit set (Step 1). Not packets from step 2 (SYN-ACK).
The structure of a TCP header without options:
0 15 31 ----------------------------------------------------------------- | source port | destination port | octets 0-3 ----------------------------------------------------------------- | sequence number | 4-7 ----------------------------------------------------------------- | acknowledgment number | 8-11 ----------------------------------------------------------------- | HL | rsvd |C|E|U|A|P|R|S|F| window size | 12-15 ----------------------------------------------------------------- | TCP checksum | urgent pointer | 16-19 ----------------------------------------------------------------- bits 0 7| 15| 23| 31
These are the TCP control bits we are interested in. PSH is URG bit
|C|E|U|A|P|R|S|F| |---------------| |0 0 0 0 0 0 1 0|
If only SYN is set, the value of the 13th octet in the TCP header, must be exactly 2:
tcp == 2
use this expression as the filter in order to watch packets which have only SYN set:
tcpdump -i xl0 tcp == 2
if other control bits might be set AND the binary value of octet 13 with 2 to preserve the SYN bit: ( value of octet 13 ) AND ( 2 ) == 2
tcpdump -i xl0 'tcp & 2 == 2'
Some offsets and field values may be expressed as names.
tcp aka i
The TCP flag fields :
tcp-urg, tcp-act, tcp-push, tcp-rst, tcp-syn, tcp-fin
tcpdump -i xl0 'tcp[tcpflags] & tcp-push != 0'
Use apostrophes around the expression to escape the
& from the shell.
UDP format is illustrated by this rwho packet:
actinide.who > broadcast.who: udp 84
host actinide port who sent a udp datagram to host broadcast's who port, the Internet broadcast address. The
packet contained 84 bytes of user data.
Some UDP services are recognized (from the source or destination port number) and the higher level protocol information output In particular, Domain Name service requests and Sun RPC calls to NFS.
src > dst: id op? flags qtype qclass name (len) h2opolo.1538 > helios.domain: 3+ A? ucbvax.berkeley.edu. (37)Host h2opolo asked the domain server on helios for an address record (qtype=A) associated with the name ucbvax.berkeley.edu.
A few anomalies are checked and may result in extra fields enclosed in square brackets:
If a query contains an answer, authority records or additional records section, ancount, nscount, or arcount are outputed as `[na]', `[nn]' or `[nau]' where n is the appropriate count.
If any of the response bits are set (AA, RA or rcode) or any of the `must be zero' bits are set in bytes two and three, `[b2&3=x]' is output, where x is the hex value of header bytes two and three.
src > dst: id op rcode flags a/n/au type class data (len) polo.1538 > helios.domain: 3+ A? ucbvax.berkeley.edu. (37) helios.domain > h2opolo.1538: 3 3/3/7 A 188.8.131.52 (273)helios responds to query id 3 from h2opolo with 3 answer records, 3 name server records and 7 additional records.
helios.domain > h2opolo.1537: 2 NXDomain* 0/1/0 (97)Here helios responds to with a response code of non-existent domain (NXDomain) with no answers, one name server and no authority records. The `*' indicates that the authoritative answer bit was set. Since there were no answers, no type, class or data were outputed.
Other flag characters that might appear are `-' (recursion available, RA, not set) and `|' (truncated message, TC, set).
If the `question' section doesn't contain exactly one entry, `[nq]' is outputed.
extensive SMB/CIFS/NBT decoding for data on UDP/137, UDP/138 and TCP/139. Some primitive decoding of IPX and NetBEUI SMB data is also done.
By default a minimal decode is done, much more detail with
-v . Be warned that with -v a single SMB packet may take up a page or more.
For information on SMB packet formats and what all the fields mean see www.cifs.org or the pub/samba/specs/ directory on your favorite samba.org mirror site. The SMB patches were written by Andrew Tridgell (email@example.com).
Sun NFS (Network File System) requests and replies are outputed as:
src.xid > dst.nfs: len op args src.nfs > dst.xid: reply stat len op results sushi.6709 > wrl.nfs: 112 readlink fh 21,24/10.73165 wrl.nfs > sushi.6709: reply ok 40 readlink "../var" sushi.201b > wrl.nfs: 144 lookup fh 9,74/4096.6878 "xcolors" wrl.nfs > sushi.201b: reply ok 128 lookup fh 9,74/4134.3150In the first line, host sushi sends a transaction with id 6709 to wrl (note that the number following the src host is a transaction id, not the source port). The request was 112 bytes, excluding the UDP and IP headers. The operation was a readlink (read symbolic link) on file handle (fh) 21,24/10.731657119. (If one is lucky, as in this case, the file handle can be interpreted as a major,minor device number pair, followed by the inode number and generation number.) Wrl replies `ok' with the contents of the link.
In the third line, sushi asks wrl to lookup the name `xcolors' in directory file 9,74/4096.6878. Note that the data outputed depends on the operation type. The format is intended to be self explanatory if read in conjunction with an NFS protocol spec.
If the -v (verbose) flag is given, additional information is outputed. For example:
sushi.1372a > wrl.nfs: 148 read fh 21,11/12.195 8192 bytes @ 24576 wrl.nfs > sushi.1372a: reply ok 1472 read REG 100664 ids 417/0 sz 29388(-v also outputs the IP header TTL, ID, length, and fragmentation fields, which have been omitted from this example.)
If the -v flag is given more than once, even more details are outputed.
Note that NFS requests are very large and much of the detail won't be outputed unless snaplen is increased. Try using `-s 192' to watch NFS traffic.
NFS reply packets do not explicitly identify the RPC operation. Instead, tcpdump keeps track of recent requests, and matches them to the replies using the transaction ID. If a reply does not closely follow the corresponding request, it might not be parsable.
Transarc AFS (Andrew File System) requests and replies are output as:
src.sport > dst.dport: rx packet-type src.sport > dst.dport: rx packet-type service call call-name args src.sport > dst.dport: rx packet-type service reply call-name args elvis.7001 > pike.afsfs: rx data fs call rename old fid 536876964/1/1 ".newsrc.new" new fid 536876964/1/1 ".newsrc" pike.afsfs > elvis.7001: rx data fs reply renameIn the first line, host elvis sends a RX packet to pike. This was a RX data packet to the fs (fileserver) service, and is the start of an RPC call. The RPC call was a rename, with the old directory file id of 536876964/1/1 and an old filename of `.newsrc.new', and a new directory file id of 536876964/1/1 and a new filename of `.newsrc'.
In general, all AFS RPCs are decoded at least by RPC call name. Most AFS RPCs have at least some of the arguments decoded (generally only the `interesting' arguments, for some definition of interesting).
The format is intended to be self-describing, but it will probably not be useful to people who are not familiar with the workings of AFS and RX.
Error codes are outputefor abort packets, with the exception of Ubik beacon packets (because abort packets are used to signify a yes vote for the Ubik protocol).
AFS requests are very large and many of the arguments won't be outputed unless snaplen is increased. Try `-s 256'
AFS reply packets do not explicitly identify the RPC operation. Instead, tcpdump keeps track of recent requests, and matches them to the replies using the call number and service ID. If a reply does not closely follow the corresponding request, it might not be parsable.
AppleTalk DDP packets encapsulated in UDP datagrams are de-encapsulated and dumped as DDP packets (i.e., all the UDP header informa-
tion is discarded).
/etc/atalk.names is used to translate AppleTalk net and node numbers to names.
number name 1.254 ether 16.1 icsd-net 1.254.110 aceThe first two lines give the names of AppleTalk networks.
AppleTalk addresses are outputed in the form
net.host.port(If the /etc/atalk.names doesn't exist or doesn't contain an entry for some AppleTalk host/net number, addresses are outputed in numeric form.)
184.108.40.206 > icsd-net.112.220 office.2 > icsd-net.112.220 jssmag.149.235 > icsd-net.2
NBP (name binding protocol) and ATP (AppleTalk transaction protocol) packets have their contents interpreted. Other protocols just dump the protocol name (or number if no name is registered for the protocol) and packet size.
icsd-net.112.220 > jssmag.2: nbp-lkup 190: "=:LaserWriter@*" jssmag.209.2 > icsd-net.112.220: nbp-reply 190: "RM1140:LaserWriter@*" 250 techpit.2 > icsd-net.112.220: nbp-reply 190: "techpit:LaserWriter@*" 186The first line is a name lookup request for laserwriters sent by net icsd host 112 and broadcast on net jssmag. The nbp id for the lookup is 190. The second line shows a reply for this request (note that it has the same id) from host jssmag.209 saying that it has a laserwriter resource named "RM1140" registered on port 250. The third line is another reply to the same request saying host techpit has laserwriter "techpit" registered on port 186.
ATP packet formatting is demonstrated by the following example:
jssmag.209.165 > helios.132: atp-req 12266<0-7> 0xae030001 helios.132 > jssmag.209.165: atp-resp 12266:0 (512) 0xae040000 helios.132 > jssmag.209.165: atp-resp 12266:1 (512) 0xae040000 helios.132 > jssmag.209.165: atp-resp 12266:2 (512) 0xae040000 helios.132 > jssmag.209.165: atp-resp 12266:3 (512) 0xae040000 helios.132 > jssmag.209.165: atp-resp 12266:4 (512) 0xae040000 helios.132 > jssmag.209.165: atp-resp 12266:5 (512) 0xae040000 helios.132 > jssmag.209.165: atp-resp 12266:6 (512) 0xae040000 helios.132 > jssmag.209.165: atp-resp*12266:7 (512) 0xae040000 jssmag.209.165 > helios.132: atp-req 12266<3,5> 0xae030001 helios.132 > jssmag.209.165: atp-resp 12266:3 (512) 0xae040000 helios.132 > jssmag.209.165: atp-resp 12266:5 (512) 0xae040000 jssmag.209.165 > helios.132: atp-rel 12266<0-7> 0xae030001 jssmag.209.133 > helios.132: atp-req* 12267<0-7> 0xae030002Jssmag.209 initiates transaction id 12266 with host helios by requesting up to 8 packets (the `<0-7>'). The hex number at the end of the line is the value of the `userdata' field in the request.
Helios responds with 8 512-byte packets. The `:digit' following the transaction id gives the packet sequence number in the transaction and the number in parens is the amount of data in the packet, excluding the atp header. The `*' on packet 7 indicates that the EOM bit was set.
Jssmag.209 then requests that packets 3 & 5 be retransmitted. Helios resends them then jssmag.209 releases the transaction. Finally, jssmag.209 initiates the next request. The `*' on the request indicates that XO (`exactly once') was not set.
Fragmented Internet datagrams are outputed as:
(frag id:size@offset+) (frag id:size@offset)(The first form indicates there are more fragments. The second indicates this is the last fragment.)
Id is the fragment id. Size is the fragment size (in bytes) excluding the IP header. Offset is this fragment's offset (in bytes) in the original datagram.
The fragment information is output for each fragment. The first fragment contains the higher level protocol header and the frag info
outputed after the protocol info. Fragments after the first contain no higher level protocol header and the frag info is outputed
the source and destination addresses. For example, here is part of an ftp from arizona.edu to lbl-rtsg.arpa over a CSNET connection that doesn't appear to handle 576 byte datagrams:
arizona.ftp-data > rtsg.1170: . 1024:1332(308) ack 1 win 4096 (frag 595a:328@0+) arizona > rtsg: (frag 595a:204@328) rtsg.1170 > arizona.ftp-data: . ack 1536 win 2560note: First, addresses in the 2nd line don't include port numbers. This is because the TCP protocol information is all in the first fragment and the port or sequence numbers are in the later fragents.
A packet with the IP don't fragment flag is marked with a trailing (
By default, output lines are preceded by a timestamp in the form
hh:mm:ss.frac the time the kernel first saw the packet.
or logical or and logical and not negation (...) to group sub-expressions = is equal != is not equal || logical or (alternate) && logical and (alternate) ! negation (alternate)keywords to denote which of packet metadata contents is to be compared:
if interface name proc process name pid process ID svc service class dir direction eproc effective process name epid effective process IDFor example to filter packets from interface en0 "sent" by the process named "nc" or incoming packet not on interface en0:
-Q "( if=en0 and proc =nc ) || (if != en0 and dir=in)"
Complex packet metadata filter expression needs to be put in quotes as the
-Q takes a single string parameter.
The current version is available via http: tcpdump.org
BPF to watch your own outbound traffic
Name server inverse queries are not dumped correctly: the (empty) question section is outputed rather than real query in the answer section.
Filter expressions on fields other than those in Token Ring headers will not correctly handle source-routed Token Ring packets.
Filter expressions on fields other than those in 802.11 headers will not correctly handle 802.11 data packets with both To DS and From DS set.