1TCPDUMP(8) System Manager's Manual TCPDUMP(8)
2
3
4
6 tcpdump - dump traffic on a network
7
9 tcpdump [ -AdDeflLnNOpqRStuUvxX ] [ -c count ]
10 [ -C file_size ] [ -F file ]
11 [ -i interface ] [ -m module ] [ -M secret ]
12 [ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]
13 [ -W filecount ]
14 [ -E spi@ipaddr algo:secret,... ]
15 [ -y datalinktype ] [ -Z user ]
16 [ expression ]
17
19 Tcpdump prints out a description of the contents of packets on a net‐
20 work interface that match the boolean expression. It can also be run
21 with the -w flag, which causes it to save the packet data to a file for
22 later analysis, and/or with the -r flag, which causes it to read from a
23 saved packet file rather than to read packets from a network interface.
24 In all cases, only packets that match expression will be processed by
25 tcpdump.
26
27 Tcpdump will, if not run with the -c flag, continue capturing packets
28 until it is interrupted by a SIGINT signal (generated, for example, by
29 typing your interrupt character, typically control-C) or a SIGTERM sig‐
30 nal (typically generated with the kill(1) command); if run with the -c
31 flag, it will capture packets until it is interrupted by a SIGINT or
32 SIGTERM signal or the specified number of packets have been processed.
33
34 When tcpdump finishes capturing packets, it will report counts of:
35
36 packets ``captured'' (this is the number of packets that tcpdump
37 has received and processed);
38
39 packets ``received by filter'' (the meaning of this depends on
40 the OS on which you're running tcpdump, and possibly on the way
41 the OS was configured - if a filter was specified on the command
42 line, on some OSes it counts packets regardless of whether they
43 were matched by the filter expression and, even if they were
44 matched by the filter expression, regardless of whether tcpdump
45 has read and processed them yet, on other OSes it counts only
46 packets that were matched by the filter expression regardless of
47 whether tcpdump has read and processed them yet, and on other
48 OSes it counts only packets that were matched by the filter
49 expression and were processed by tcpdump);
50
51 packets ``dropped by kernel'' (this is the number of packets
52 that were dropped, due to a lack of buffer space, by the packet
53 capture mechanism in the OS on which tcpdump is running, if the
54 OS reports that information to applications; if not, it will be
55 reported as 0).
56
57 On platforms that support the SIGINFO signal, such as most BSDs
58 (including Mac OS X) and Digital/Tru64 UNIX, it will report those
59 counts when it receives a SIGINFO signal (generated, for example, by
60 typing your ``status'' character, typically control-T, although on some
61 platforms, such as Mac OS X, the ``status'' character is not set by
62 default, so you must set it with stty(1) in order to use it) and will
63 continue capturing packets.
64
65 Reading packets from a network interface may require that you have spe‐
66 cial privileges:
67
68 Under SunOS 3.x or 4.x with NIT or BPF:
69 You must have read access to /dev/nit or /dev/bpf*.
70
71 Under Solaris with DLPI:
72 You must have read/write access to the network pseudo device,
73 e.g. /dev/le. On at least some versions of Solaris, however,
74 this is not sufficient to allow tcpdump to capture in promiscu‐
75 ous mode; on those versions of Solaris, you must be root, or
76 tcpdump must be installed setuid to root, in order to capture in
77 promiscuous mode. Note that, on many (perhaps all) interfaces,
78 if you don't capture in promiscuous mode, you will not see any
79 outgoing packets, so a capture not done in promiscuous mode may
80 not be very useful.
81
82 Under HP-UX with DLPI:
83 You must be root or tcpdump must be installed setuid to root.
84
85 Under IRIX with snoop:
86 You must be root or tcpdump must be installed setuid to root.
87
88 Under Linux:
89 You must be root or tcpdump must be installed setuid to root
90 (unless your distribution has a kernel that supports capability
91 bits such as CAP_NET_RAW and code to allow those capability bits
92 to be given to particular accounts and to cause those bits to be
93 set on a user's initial processes when they log in, in which
94 case you must have CAP_NET_RAW in order to capture and
95 CAP_NET_ADMIN to enumerate network devices with, for example,
96 the -D flag).
97
98 Under ULTRIX and Digital UNIX/Tru64 UNIX:
99 Any user may capture network traffic with tcpdump. However, no
100 user (not even the super-user) can capture in promiscuous mode
101 on an interface unless the super-user has enabled promiscuous-
102 mode operation on that interface using pfconfig(8), and no user
103 (not even the super-user) can capture unicast traffic received
104 by or sent by the machine on an interface unless the super-user
105 has enabled copy-all-mode operation on that interface using
106 pfconfig, so useful packet capture on an interface probably
107 requires that either promiscuous-mode or copy-all-mode opera‐
108 tion, or both modes of operation, be enabled on that interface.
109
110 Under BSD (this includes Mac OS X):
111 You must have read access to /dev/bpf* on systems that don't
112 have a cloning BPF device, or to /dev/bpf on systems that do.
113 On BSDs with a devfs (this includes Mac OS X), this might
114 involve more than just having somebody with super-user access
115 setting the ownership or permissions on the BPF devices - it
116 might involve configuring devfs to set the ownership or permis‐
117 sions every time the system is booted, if the system even sup‐
118 ports that; if it doesn't support that, you might have to find
119 some other way to make that happen at boot time.
120
121 Reading a saved packet file doesn't require special privileges.
122
124 -A Print each packet (minus its link level header) in ASCII. Handy
125 for capturing web pages.
126
127 -c Exit after receiving count packets.
128
129 -C Before writing a raw packet to a savefile, check whether the
130 file is currently larger than file_size and, if so, close the
131 current savefile and open a new one. Savefiles after the first
132 savefile will have the name specified with the -w flag, with a
133 number after it, starting at 1 and continuing upward. The units
134 of file_size are millions of bytes (1,000,000 bytes, not
135 1,048,576 bytes).
136
137 Note that when used with -Z option (enabled by default), privi‐
138 leges are dropped before opening first savefile.
139
140 -d Dump the compiled packet-matching code in a human readable form
141 to standard output and stop.
142
143 -dd Dump packet-matching code as a C program fragment.
144
145 -ddd Dump packet-matching code as decimal numbers (preceded with a
146 count).
147
148 -D Print the list of the network interfaces available on the system
149 and on which tcpdump can capture packets. For each network
150 interface, a number and an interface name, possibly followed by
151 a text description of the interface, is printed. The interface
152 name or the number can be supplied to the -i flag to specify an
153 interface on which to capture.
154
155 This can be useful on systems that don't have a command to list
156 them (e.g., Windows systems, or UNIX systems lacking ifconfig
157 -a); the number can be useful on Windows 2000 and later systems,
158 where the interface name is a somewhat complex string.
159
160 The -D flag will not be supported if tcpdump was built with an
161 older version of libpcap that lacks the pcap_findalldevs() func‐
162 tion.
163
164 -e Print the link-level header on each dump line.
165
166 -E Use spi@ipaddr algo:secret for decrypting IPsec ESP packets that
167 are addressed to addr and contain Security Parameter Index value
168 spi. This combination may be repeated with comma or newline
169 seperation.
170
171 Note that setting the secret for IPv4 ESP packets is supported
172 at this time.
173
174 Algorithms may be des-cbc, 3des-cbc, blowfish-cbc, rc3-cbc,
175 cast128-cbc, or none. The default is des-cbc. The ability to
176 decrypt packets is only present if tcpdump was compiled with
177 cryptography enabled.
178
179 secret is the ASCII text for ESP secret key. If preceeded by
180 0x, then a hex value will be read.
181
182 The option assumes RFC2406 ESP, not RFC1827 ESP. The option is
183 only for debugging purposes, and the use of this option with a
184 true `secret' key is discouraged. By presenting IPsec secret
185 key onto command line you make it visible to others, via ps(1)
186 and other occasions.
187
188 In addition to the above syntax, the syntax file name may be
189 used to have tcpdump read the provided file in. The file is
190 opened upon receiving the first ESP packet, so any special per‐
191 missions that tcpdump may have been given should already have
192 been given up.
193
194 -f Print `foreign' IPv4 addresses numerically rather than symboli‐
195 cally (this option is intended to get around serious brain dam‐
196 age in Sun's NIS server — usually it hangs forever translating
197 non-local internet numbers).
198
199 The test for `foreign' IPv4 addresses is done using the IPv4
200 address and netmask of the interface on which capture is being
201 done. If that address or netmask are not available, available,
202 either because the interface on which capture is being done has
203 no address or netmask or because the capture is being done on
204 the Linux "any" interface, which can capture on more than one
205 interface, this option will not work correctly.
206
207 -F Use file as input for the filter expression. An additional
208 expression given on the command line is ignored.
209
210 -i Listen on interface. If unspecified, tcpdump searches the sys‐
211 tem interface list for the lowest numbered, configured up inter‐
212 face (excluding loopback). Ties are broken by choosing the ear‐
213 liest match.
214
215 On Linux systems with 2.2 or later kernels, an interface argu‐
216 ment of ``any'' can be used to capture packets from all inter‐
217 faces. Note that captures on the ``any'' device will not be
218 done in promiscuous mode.
219
220 If the -D flag is supported, an interface number as printed by
221 that flag can be used as the interface argument.
222
223 -l Make stdout line buffered. Useful if you want to see the data
224 while capturing it. E.g.,
225 ``tcpdump -l | tee dat'' or ``tcpdump -l >
226 dat & tail -f dat''.
227
228 -L List the known data link types for the interface and exit.
229
230 -m Load SMI MIB module definitions from file module. This option
231 can be used several times to load several MIB modules into tcp‐
232 dump.
233
234 -M Use secret as a shared secret for validating the digests found
235 in TCP segments with the TCP-MD5 option (RFC 2385), if present.
236
237 -n Don't convert host addresses to names. This can be used to
238 avoid DNS lookups.
239
240 -nn Don't convert protocol and port numbers etc. to names either.
241
242 -N Don't print domain name qualification of host names. E.g., if
243 you give this flag then tcpdump will print ``nic'' instead of
244 ``nic.ddn.mil''.
245
246 -O Do not run the packet-matching code optimizer. This is useful
247 only if you suspect a bug in the optimizer.
248
249 -p Don't put the interface into promiscuous mode. Note that the
250 interface might be in promiscuous mode for some other reason;
251 hence, `-p' cannot be used as an abbreviation for `ether host
252 {local-hw-addr} or ether broadcast'.
253
254 -q Quick (quiet?) output. Print less protocol information so out‐
255 put lines are shorter.
256
257 -R Assume ESP/AH packets to be based on old specification (RFC1825
258 to RFC1829). If specified, tcpdump will not print replay pre‐
259 vention field. Since there is no protocol version field in
260 ESP/AH specification, tcpdump cannot deduce the version of
261 ESP/AH protocol.
262
263 -r Read packets from file (which was created with the -w option).
264 Standard input is used if file is ``-''.
265
266 -S Print absolute, rather than relative, TCP sequence numbers.
267
268 -s Snarf snaplen bytes of data from each packet rather than the
269 default of 68 (with SunOS's NIT, the minimum is actually 96).
270 68 bytes is adequate for IP, ICMP, TCP and UDP but may truncate
271 protocol information from name server and NFS packets (see
272 below). Packets truncated because of a limited snapshot are
273 indicated in the output with ``[|proto]'', where proto is the
274 name of the protocol level at which the truncation has occurred.
275 Note that taking larger snapshots both increases the amount of
276 time it takes to process packets and, effectively, decreases the
277 amount of packet buffering. This may cause packets to be lost.
278 You should limit snaplen to the smallest number that will cap‐
279 ture the protocol information you're interested in. Setting
280 snaplen to 0 means use the required length to catch whole pack‐
281 ets.
282
283 -T Force packets selected by "expression" to be interpreted the
284 specified type. Currently known types are aodv (Ad-hoc On-
285 demand Distance Vector protocol), cnfp (Cisco NetFlow protocol),
286 rpc (Remote Procedure Call), rtp (Real-Time Applications proto‐
287 col), rtcp (Real-Time Applications control protocol), snmp (Sim‐
288 ple Network Management Protocol), tftp (Trivial File Transfer
289 Protocol), vat (Visual Audio Tool), and wb (distributed White
290 Board).
291
292 -t Don't print a timestamp on each dump line.
293
294 -tt Print an unformatted timestamp on each dump line.
295
296 -ttt Print a delta (in micro-seconds) between current and previous
297 line on each dump line.
298
299 -tttt Print a timestamp in default format proceeded by date on each
300 dump line.
301
302 -u Print undecoded NFS handles.
303
304 -U Make output saved via the -w option ``packet-buffered''; i.e.,
305 as each packet is saved, it will be written to the output file,
306 rather than being written only when the output buffer fills.
307
308 The -U flag will not be supported if tcpdump was built with an
309 older version of libpcap that lacks the pcap_dump_flush() func‐
310 tion.
311
312 -v When parsing and printing, produce (slightly more) verbose out‐
313 put. For example, the time to live, identification, total
314 length and options in an IP packet are printed. Also enables
315 additional packet integrity checks such as verifying the IP and
316 ICMP header checksum.
317
318 When writing to a file with the -w option, report, every 10 sec‐
319 onds, the number of packets captured.
320
321 -vv Even more verbose output. For example, additional fields are
322 printed from NFS reply packets, and SMB packets are fully
323 decoded.
324
325 -vvv Even more verbose output. For example, telnet SB ... SE options
326 are printed in full. With -X Telnet options are printed in hex
327 as well.
328
329 -w Write the raw packets to file rather than parsing and printing
330 them out. They can later be printed with the -r option. Stan‐
331 dard output is used if file is ``-''.
332
333 -W Used in conjunction with the -C option, this will limit the num‐
334 ber of files created to the specified number, and begin over‐
335 writing files from the beginning, thus creating a 'rotating'
336 buffer. In addition, it will name the files with enough leading
337 0s to support the maximum number of files, allowing them to sort
338 correctly.
339
340 -x When parsing and printing, in addition to printing the headers
341 of each packet, print the data of each packet (minus its link
342 level header) in hex. The smaller of the entire packet or
343 snaplen bytes will be printed. Note that this is the entire
344 link-layer packet, so for link layers that pad (e.g. Ethernet),
345 the padding bytes will also be printed when the higher layer
346 packet is shorter than the required padding.
347
348 -xx When parsing and printing, in addition to printing the headers
349 of each packet, print the data of each packet, including its
350 link level header, in hex.
351
352 -X When parsing and printing, in addition to printing the headers
353 of each packet, print the data of each packet (minus its link
354 level header) in hex and ASCII. This is very handy for
355 analysing new protocols.
356
357 -XX When parsing and printing, in addition to printing the headers
358 of each packet, print the data of each packet, including its
359 link level header, in hex and ASCII.
360
361 -y Set the data link type to use while capturing packets to
362 datalinktype.
363
364 -Z Drops privileges (if root) and changes user ID to user and the
365 group ID to the primary group of user.
366
367 This behavior is enabled by default (-Z pcap), and can be dis‐
368 abled by -Z root.
369
370
371 expression
372 selects which packets will be dumped. If no expression is
373 given, all packets on the net will be dumped. Otherwise, only
374 packets for which expression is `true' will be dumped.
375
376 The expression consists of one or more primitives. Primitives
377 usually consist of an id (name or number) preceded by one or
378 more qualifiers. There are three different kinds of qualifier:
379
380 type qualifiers say what kind of thing the id name or number
381 refers to. Possible types are host, net , port and por‐
382 trange. E.g., `host foo', `net 128.3', `port 20', `por‐
383 trange 6000-6008'. If there is no type qualifier, host
384 is assumed.
385
386 dir qualifiers specify a particular transfer direction to
387 and/or from id. Possible directions are src, dst, src or
388 dst and src and dst. E.g., `src foo', `dst net 128.3',
389 `src or dst port ftp-data'. If there is no dir quali‐
390 fier, src or dst is assumed. For some link layers, such
391 as SLIP and the ``cooked'' Linux capture mode used for
392 the ``any'' device and for some other device types, the
393 inbound and outbound qualifiers can be used to specify a
394 desired direction.
395
396 proto qualifiers restrict the match to a particular protocol.
397 Possible protos are: ether, fddi, tr, wlan, ip, ip6, arp,
398 rarp, decnet, tcp and udp. E.g., `ether src foo', `arp
399 net 128.3', `tcp port 21', `udp portrange 7000-7009'. If
400 there is no proto qualifier, all protocols consistent
401 with the type are assumed. E.g., `src foo' means `(ip or
402 arp or rarp) src foo' (except the latter is not legal
403 syntax), `net bar' means `(ip or arp or rarp) net bar'
404 and `port 53' means `(tcp or udp) port 53'.
405
406 [`fddi' is actually an alias for `ether'; the parser treats them
407 identically as meaning ``the data link level used on the speci‐
408 fied network interface.'' FDDI headers contain Ethernet-like
409 source and destination addresses, and often contain Ethernet-
410 like packet types, so you can filter on these FDDI fields just
411 as with the analogous Ethernet fields. FDDI headers also con‐
412 tain other fields, but you cannot name them explicitly in a fil‐
413 ter expression.
414
415 Similarly, `tr' and `wlan' are aliases for `ether'; the previous
416 paragraph's statements about FDDI headers also apply to Token
417 Ring and 802.11 wireless LAN headers. For 802.11 headers, the
418 destination address is the DA field and the source address is
419 the SA field; the BSSID, RA, and TA fields aren't tested.]
420
421 In addition to the above, there are some special `primitive'
422 keywords that don't follow the pattern: gateway, broadcast,
423 less, greater and arithmetic expressions. All of these are
424 described below.
425
426 More complex filter expressions are built up by using the words
427 and, or and not to combine primitives. E.g., `host foo and not
428 port ftp and not port ftp-data'. To save typing, identical
429 qualifier lists can be omitted. E.g., `tcp dst port ftp or ftp-
430 data or domain' is exactly the same as `tcp dst port ftp or tcp
431 dst port ftp-data or tcp dst port domain'.
432
433 Allowable primitives are:
434
435 dst host host
436 True if the IPv4/v6 destination field of the packet is
437 host, which may be either an address or a name.
438
439 src host host
440 True if the IPv4/v6 source field of the packet is host.
441
442 host host
443 True if either the IPv4/v6 source or destination of the
444 packet is host.
445
446 Any of the above host expressions can be prepended with
447 the keywords, ip, arp, rarp, or ip6 as in:
448 ip host host
449 which is equivalent to:
450 ether proto \ip and host host
451 If host is a name with multiple IP addresses, each
452 address will be checked for a match.
453
454 ether dst ehost
455 True if the Ethernet destination address is ehost. Ehost
456 may be either a name from /etc/ethers or a number (see
457 ethers(3N) for numeric format).
458
459 ether src ehost
460 True if the Ethernet source address is ehost.
461
462 ether host ehost
463 True if either the Ethernet source or destination address
464 is ehost.
465
466 gateway host
467 True if the packet used host as a gateway. I.e., the
468 Ethernet source or destination address was host but nei‐
469 ther the IP source nor the IP destination was host. Host
470 must be a name and must be found both by the machine's
471 host-name-to-IP-address resolution mechanisms (host name
472 file, DNS, NIS, etc.) and by the machine's host-name-to-
473 Ethernet-address resolution mechanism (/etc/ethers,
474 etc.). (An equivalent expression is
475 ether host ehost and not host host
476 which can be used with either names or numbers for host /
477 ehost.) This syntax does not work in IPv6-enabled con‐
478 figuration at this moment.
479
480 dst net net
481 True if the IPv4/v6 destination address of the packet has
482 a network number of net. Net may be either a name from
483 the networks database (/etc/networks, etc.) or a network
484 number. An IPv4 network number can be written as a dot‐
485 ted quad (e.g., 192.168.1.0), dotted triple (e.g.,
486 192.168.1), dotted pair (e.g, 172.16), or single number
487 (e.g., 10); the netmask is 255.255.255.255 for a dotted
488 quad (which means that it's really a host match),
489 255.255.255.0 for a dotted triple, 255.255.0.0 for a dot‐
490 ted pair, or 255.0.0.0 for a single number. An IPv6 net‐
491 work number must be written out fully; the netmask is
492 ff:ff:ff:ff:ff:ff:ff:ff, so IPv6 "network" matches are
493 really always host matches, and a network match requires
494 a netmask length.
495
496 src net net
497 True if the IPv4/v6 source address of the packet has a
498 network number of net.
499
500 net net
501 True if either the IPv4/v6 source or destination address
502 of the packet has a network number of net.
503
504 net net mask netmask
505 True if the IPv4 address matches net with the specific
506 netmask. May be qualified with src or dst. Note that
507 this syntax is not valid for IPv6 net.
508
509 net net/len
510 True if the IPv4/v6 address matches net with a netmask
511 len bits wide. May be qualified with src or dst.
512
513 dst port port
514 True if the packet is ip/tcp, ip/udp, ip6/tcp or ip6/udp
515 and has a destination port value of port. The port can
516 be a number or a name used in /etc/services (see tcp(4P)
517 and udp(4P)). If a name is used, both the port number
518 and protocol are checked. If a number or ambiguous name
519 is used, only the port number is checked (e.g., dst port
520 513 will print both tcp/login traffic and udp/who traf‐
521 fic, and port domain will print both tcp/domain and
522 udp/domain traffic).
523
524 src port port
525 True if the packet has a source port value of port.
526
527 port port
528 True if either the source or destination port of the
529 packet is port.
530
531 dst portrange port1-port2
532 True if the packet is ip/tcp, ip/udp, ip6/tcp or ip6/udp
533 and has a destination port value between port1 and port2.
534 port1 and port2 are interpreted in the same fashion as
535 the port parameter for port.
536
537 src portrange port1-port2
538 True if the packet has a source port value between port1
539 and port2.
540
541 portrange port1-port2
542 True if either the source or destination port of the
543 packet is between port1 and port2.
544
545 Any of the above port or port range expressions can be
546 prepended with the keywords, tcp or udp, as in:
547 tcp src port port
548 which matches only tcp packets whose source port is port.
549
550 less length
551 True if the packet has a length less than or equal to
552 length. This is equivalent to:
553 len <= length.
554
555 greater length
556 True if the packet has a length greater than or equal to
557 length. This is equivalent to:
558 len >= length.
559
560 ip proto protocol
561 True if the packet is an IPv4 packet (see ip(4P)) of pro‐
562 tocol type protocol. Protocol can be a number or one of
563 the names icmp, icmp6, igmp, igrp, pim, ah, esp, vrrp,
564 udp, or tcp. Note that the identifiers tcp, udp, and
565 icmp are also keywords and must be escaped via backslash
566 (\), which is \\ in the C-shell. Note that this primi‐
567 tive does not chase the protocol header chain.
568
569 ip6 proto protocol
570 True if the packet is an IPv6 packet of protocol type
571 protocol. Note that this primitive does not chase the
572 protocol header chain.
573
574 ip6 protochain protocol
575 True if the packet is IPv6 packet, and contains protocol
576 header with type protocol in its protocol header chain.
577 For example,
578 ip6 protochain 6
579 matches any IPv6 packet with TCP protocol header in the
580 protocol header chain. The packet may contain, for exam‐
581 ple, authentication header, routing header, or hop-by-hop
582 option header, between IPv6 header and TCP header. The
583 BPF code emitted by this primitive is complex and cannot
584 be optimized by BPF optimizer code in tcpdump, so this
585 can be somewhat slow.
586
587 ip protochain protocol
588 Equivalent to ip6 protochain protocol, but this is for
589 IPv4.
590
591 ether broadcast
592 True if the packet is an Ethernet broadcast packet. The
593 ether keyword is optional.
594
595 ip broadcast
596 True if the packet is an IPv4 broadcast packet. It
597 checks for both the all-zeroes and all-ones broadcast
598 conventions, and looks up the subnet mask on the inter‐
599 face on which the capture is being done.
600
601 If the subnet mask of the interface on which the capture
602 is being done is not available, either because the inter‐
603 face on which capture is being done has no netmask or
604 because the capture is being done on the Linux "any"
605 interface, which can capture on more than one interface,
606 this check will not work correctly.
607
608 ether multicast
609 True if the packet is an Ethernet multicast packet. The
610 ether keyword is optional. This is shorthand for
611 `ether[0] & 1 != 0'.
612
613 ip multicast
614 True if the packet is an IPv4 multicast packet.
615
616 ip6 multicast
617 True if the packet is an IPv6 multicast packet.
618
619 ether proto protocol
620 True if the packet is of ether type protocol. Protocol
621 can be a number or one of the names ip, ip6, arp, rarp,
622 atalk, aarp, decnet, sca, lat, mopdl, moprc, iso, stp,
623 ipx, or netbeui. Note these identifiers are also key‐
624 words and must be escaped via backslash (\).
625
626 [In the case of FDDI (e.g., `fddi protocol arp'), Token
627 Ring (e.g., `tr protocol arp'), and IEEE 802.11 wireless
628 LANS (e.g., `wlan protocol arp'), for most of those pro‐
629 tocols, the protocol identification comes from the 802.2
630 Logical Link Control (LLC) header, which is usually lay‐
631 ered on top of the FDDI, Token Ring, or 802.11 header.
632
633 When filtering for most protocol identifiers on FDDI,
634 Token Ring, or 802.11, tcpdump checks only the protocol
635 ID field of an LLC header in so-called SNAP format with
636 an Organizational Unit Identifier (OUI) of 0x000000, for
637 encapsulated Ethernet; it doesn't check whether the
638 packet is in SNAP format with an OUI of 0x000000. The
639 exceptions are:
640
641 iso tcpdump checks the DSAP (Destination Service
642 Access Point) and SSAP (Source Service Access
643 Point) fields of the LLC header;
644
645 stp and netbeui
646 tcpdump checks the DSAP of the LLC header;
647
648 atalk tcpdump checks for a SNAP-format packet with an
649 OUI of 0x080007 and the AppleTalk etype.
650
651 In the case of Ethernet, tcpdump checks the Ethernet type
652 field for most of those protocols. The exceptions are:
653
654 iso, stp, and netbeui
655 tcpdump checks for an 802.3 frame and then checks
656 the LLC header as it does for FDDI, Token Ring,
657 and 802.11;
658
659 atalk tcpdump checks both for the AppleTalk etype in an
660 Ethernet frame and for a SNAP-format packet as it
661 does for FDDI, Token Ring, and 802.11;
662
663 aarp tcpdump checks for the AppleTalk ARP etype in
664 either an Ethernet frame or an 802.2 SNAP frame
665 with an OUI of 0x000000;
666
667 ipx tcpdump checks for the IPX etype in an Ethernet
668 frame, the IPX DSAP in the LLC header, the
669 802.3-with-no-LLC-header encapsulation of IPX, and
670 the IPX etype in a SNAP frame.
671
672 decnet src host
673 True if the DECNET source address is host, which may be
674 an address of the form ``10.123'', or a DECNET host name.
675 [DECNET host name support is only available on ULTRIX
676 systems that are configured to run DECNET.]
677
678 decnet dst host
679 True if the DECNET destination address is host.
680
681 decnet host host
682 True if either the DECNET source or destination address
683 is host.
684
685 ifname interface
686 True if the packet was logged as coming from the speci‐
687 fied interface (applies only to packets logged by Open‐
688 BSD's pf(4)).
689
690 on interface
691 Synonymous with the ifname modifier.
692
693 rnr num
694 True if the packet was logged as matching the specified
695 PF rule number (applies only to packets logged by Open‐
696 BSD's pf(4)).
697
698 rulenum num
699 Synonomous with the rnr modifier.
700
701 reason code
702 True if the packet was logged with the specified PF rea‐
703 son code. The known codes are: match, bad-offset, frag‐
704 ment, short, normalize, and memory (applies only to pack‐
705 ets logged by OpenBSD's pf(4)).
706
707 rset name
708 True if the packet was logged as matching the specified
709 PF ruleset name of an anchored ruleset (applies only to
710 packets logged by pf(4)).
711
712 ruleset name
713 Synonomous with the rset modifier.
714
715 srnr num
716 True if the packet was logged as matching the specified
717 PF rule number of an anchored ruleset (applies only to
718 packets logged by pf(4)).
719
720 subrulenum num
721 Synonomous with the srnr modifier.
722
723 action act
724 True if PF took the specified action when the packet was
725 logged. Known actions are: pass and block (applies only
726 to packets logged by OpenBSD's pf(4)).
727
728 ip, ip6, arp, rarp, atalk, aarp, decnet, iso, stp, ipx, netbeui
729 Abbreviations for:
730 ether proto p
731 where p is one of the above protocols.
732
733 lat, moprc, mopdl
734 Abbreviations for:
735 ether proto p
736 where p is one of the above protocols. Note that tcpdump
737 does not currently know how to parse these protocols.
738
739 vlan [vlan_id]
740 True if the packet is an IEEE 802.1Q VLAN packet. If
741 [vlan_id] is specified, only true if the packet has the
742 specified vlan_id. Note that the first vlan keyword
743 encountered in expression changes the decoding offsets
744 for the remainder of expression on the assumption that
745 the packet is a VLAN packet. The vlan [vlan_id] expres‐
746 sion may be used more than once, to filter on VLAN hier‐
747 archies. Each use of that expression increments the fil‐
748 ter offsets by 4.
749
750 For example:
751 vlan 100 && vlan 200
752 filters on VLAN 200 encapsulated within VLAN 100, and
753 vlan && vlan 300 && ip
754 filters IPv4 protocols encapsulated in VLAN 300 encapsu‐
755 lated within any higher order VLAN.
756
757 mpls [label_num]
758 True if the packet is an MPLS packet. If [label_num] is
759 specified, only true is the packet has the specified
760 label_num. Note that the first mpls keyword encountered
761 in expression changes the decoding offsets for the
762 remainder of expression on the assumption that the packet
763 is a MPLS-encapsulated IP packet. The mpls [label_num]
764 expression may be used more than once, to filter on MPLS
765 hierarchies. Each use of that expression increments the
766 filter offsets by 4.
767
768 For example:
769 mpls 100000 && mpls 1024
770 filters packets with an outer label of 100000 and an
771 inner label of 1024, and
772 mpls && mpls 1024 && host 192.9.200.1
773 filters packets to or from 192.9.200.1 with an inner
774 label of 1024 and any outer label.
775
776 pppoed True if the packet is a PPP-over-Ethernet Discovery
777 packet (Ethernet type 0x8863).
778
779 pppoes True if the packet is a PPP-over-Ethernet Session packet
780 (Ethernet type 0x8864). Note that the first pppoes key‐
781 word encountered in expression changes the decoding off‐
782 sets for the remainder of expression on the assumption
783 that the packet is a PPPoE session packet.
784
785 For example:
786 pppoes && ip
787 filters IPv4 protocols encapsulated in PPPoE.
788
789 tcp, udp, icmp
790 Abbreviations for:
791 ip proto p or ip6 proto p
792 where p is one of the above protocols.
793
794 iso proto protocol
795 True if the packet is an OSI packet of protocol type pro‐
796 tocol. Protocol can be a number or one of the names
797 clnp, esis, or isis.
798
799 clnp, esis, isis
800 Abbreviations for:
801 iso proto p
802 where p is one of the above protocols.
803
804 l1, l2, iih, lsp, snp, csnp, psnp
805 Abbreviations for IS-IS PDU types.
806
807 vpi n True if the packet is an ATM packet, for SunATM on
808 Solaris, with a virtual path identifier of n.
809
810 vci n True if the packet is an ATM packet, for SunATM on
811 Solaris, with a virtual channel identifier of n.
812
813 lane True if the packet is an ATM packet, for SunATM on
814 Solaris, and is an ATM LANE packet. Note that the first
815 lane keyword encountered in expression changes the tests
816 done in the remainder of expression on the assumption
817 that the packet is either a LANE emulated Ethernet packet
818 or a LANE LE Control packet. If lane isn't specified,
819 the tests are done under the assumption that the packet
820 is an LLC-encapsulated packet.
821
822 llc True if the packet is an ATM packet, for SunATM on
823 Solaris, and is an LLC-encapsulated packet.
824
825 oamf4s True if the packet is an ATM packet, for SunATM on
826 Solaris, and is a segment OAM F4 flow cell (VPI=0 &
827 VCI=3).
828
829 oamf4e True if the packet is an ATM packet, for SunATM on
830 Solaris, and is an end-to-end OAM F4 flow cell (VPI=0 &
831 VCI=4).
832
833 oamf4 True if the packet is an ATM packet, for SunATM on
834 Solaris, and is a segment or end-to-end OAM F4 flow cell
835 (VPI=0 & (VCI=3 | VCI=4)).
836
837 oam True if the packet is an ATM packet, for SunATM on
838 Solaris, and is a segment or end-to-end OAM F4 flow cell
839 (VPI=0 & (VCI=3 | VCI=4)).
840
841 metac True if the packet is an ATM packet, for SunATM on
842 Solaris, and is on a meta signaling circuit (VPI=0 &
843 VCI=1).
844
845 bcc True if the packet is an ATM packet, for SunATM on
846 Solaris, and is on a broadcast signaling circuit (VPI=0 &
847 VCI=2).
848
849 sc True if the packet is an ATM packet, for SunATM on
850 Solaris, and is on a signaling circuit (VPI=0 & VCI=5).
851
852 ilmic True if the packet is an ATM packet, for SunATM on
853 Solaris, and is on an ILMI circuit (VPI=0 & VCI=16).
854
855 connectmsg
856 True if the packet is an ATM packet, for SunATM on
857 Solaris, and is on a signaling circuit and is a Q.2931
858 Setup, Call Proceeding, Connect, Connect Ack, Release, or
859 Release Done message.
860
861 metaconnect
862 True if the packet is an ATM packet, for SunATM on
863 Solaris, and is on a meta signaling circuit and is a
864 Q.2931 Setup, Call Proceeding, Connect, Release, or
865 Release Done message.
866
867 expr relop expr
868 True if the relation holds, where relop is one of >, <,
869 >=, <=, =, !=, and expr is an arithmetic expression com‐
870 posed of integer constants (expressed in standard C syn‐
871 tax), the normal binary operators [+, -, *, /, &, |, <<,
872 >>], a length operator, and special packet data acces‐
873 sors. Note that all comparisons are unsigned, so that,
874 for example, 0x80000000 and 0xffffffff are > 0. To
875 access data inside the packet, use the following syntax:
876 proto [ expr : size ]
877 Proto is one of ether, fddi, tr, wlan, ppp, slip, link,
878 ip, arp, rarp, tcp, udp, icmp, ip6 or radio, and indi‐
879 cates the protocol layer for the index operation.
880 (ether, fddi, wlan, tr, ppp, slip and link all refer to
881 the link layer. radio refers to the "radio header" added
882 to some 802.11 captures.) Note that tcp, udp and other
883 upper-layer protocol types only apply to IPv4, not IPv6
884 (this will be fixed in the future). The byte offset,
885 relative to the indicated protocol layer, is given by
886 expr. Size is optional and indicates the number of bytes
887 in the field of interest; it can be either one, two, or
888 four, and defaults to one. The length operator, indi‐
889 cated by the keyword len, gives the length of the packet.
890
891 For example, `ether[0] & 1 != 0' catches all multicast
892 traffic. The expression `ip[0] & 0xf != 5' catches all
893 IPv4 packets with options. The expression `ip[6:2] &
894 0x1fff = 0' catches only unfragmented IPv4 datagrams and
895 frag zero of fragmented IPv4 datagrams. This check is
896 implicitly applied to the tcp and udp index operations.
897 For instance, tcp[0] always means the first byte of the
898 TCP header, and never means the first byte of an inter‐
899 vening fragment.
900
901 Some offsets and field values may be expressed as names
902 rather than as numeric values. The following protocol
903 header field offsets are available: icmptype (ICMP type
904 field), icmpcode (ICMP code field), and tcpflags (TCP
905 flags field).
906
907 The following ICMP type field values are available: icmp-
908 echoreply, icmp-unreach, icmp-sourcequench, icmp-redi‐
909 rect, icmp-echo, icmp-routeradvert, icmp-routersolicit,
910 icmp-timxceed, icmp-paramprob, icmp-tstamp, icmp-tstam‐
911 preply, icmp-ireq, icmp-ireqreply, icmp-maskreq, icmp-
912 maskreply.
913
914 The following TCP flags field values are available: tcp-
915 fin, tcp-syn, tcp-rst, tcp-push, tcp-ack, tcp-urg.
916
917 Primitives may be combined using:
918
919 A parenthesized group of primitives and operators (paren‐
920 theses are special to the Shell and must be escaped).
921
922 Negation (`!' or `not').
923
924 Concatenation (`&&' or `and').
925
926 Alternation (`||' or `or').
927
928 Negation has highest precedence. Alternation and concatenation
929 have equal precedence and associate left to right. Note that
930 explicit and tokens, not juxtaposition, are now required for
931 concatenation.
932
933 If an identifier is given without a keyword, the most recent
934 keyword is assumed. For example,
935 not host vs and ace
936 is short for
937 not host vs and host ace
938 which should not be confused with
939 not ( host vs or ace )
940
941 Expression arguments can be passed to tcpdump as either a single
942 argument or as multiple arguments, whichever is more convenient.
943 Generally, if the expression contains Shell metacharacters, it
944 is easier to pass it as a single, quoted argument. Multiple
945 arguments are concatenated with spaces before being parsed.
946
948 To print all packets arriving at or departing from sundown:
949 tcpdump host sundown
950
951 To print traffic between helios and either hot or ace:
952 tcpdump host helios and \( hot or ace \)
953
954 To print all IP packets between ace and any host except helios:
955 tcpdump ip host ace and not helios
956
957 To print all traffic between local hosts and hosts at Berkeley:
958 tcpdump net ucb-ether
959
960 To print all ftp traffic through internet gateway snup: (note that the
961 expression is quoted to prevent the shell from (mis-)interpreting the
962 parentheses):
963 tcpdump 'gateway snup and (port ftp or ftp-data)'
964
965 To print traffic neither sourced from nor destined for local hosts (if
966 you gateway to one other net, this stuff should never make it onto your
967 local net).
968 tcpdump ip and not net localnet
969
970 To print the start and end packets (the SYN and FIN packets) of each
971 TCP conversation that involves a non-local host.
972 tcpdump 'tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net localnet'
973
974 To print all IPv4 HTTP packets to and from port 80, i.e. print only
975 packets that contain data, not, for example, SYN and FIN packets and
976 ACK-only packets. (IPv6 is left as an exercise for the reader.)
977 tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
978
979 To print IP packets longer than 576 bytes sent through gateway snup:
980 tcpdump 'gateway snup and ip[2:2] > 576'
981
982 To print IP broadcast or multicast packets that were not sent via Eth‐
983 ernet broadcast or multicast:
984 tcpdump 'ether[0] & 1 = 0 and ip[16] >= 224'
985
986 To print all ICMP packets that are not echo requests/replies (i.e., not
987 ping packets):
988 tcpdump 'icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply'
989
991 The output of tcpdump is protocol dependent. The following gives a
992 brief description and examples of most of the formats.
993
994 Link Level Headers
995
996 If the '-e' option is given, the link level header is printed out. On
997 Ethernets, the source and destination addresses, protocol, and packet
998 length are printed.
999
1000 On FDDI networks, the '-e' option causes tcpdump to print the `frame
1001 control' field, the source and destination addresses, and the packet
1002 length. (The `frame control' field governs the interpretation of the
1003 rest of the packet. Normal packets (such as those containing IP data‐
1004 grams) are `async' packets, with a priority value between 0 and 7; for
1005 example, `async4'. Such packets are assumed to contain an 802.2 Logi‐
1006 cal Link Control (LLC) packet; the LLC header is printed if it is not
1007 an ISO datagram or a so-called SNAP packet.
1008
1009 On Token Ring networks, the '-e' option causes tcpdump to print the
1010 `access control' and `frame control' fields, the source and destination
1011 addresses, and the packet length. As on FDDI networks, packets are
1012 assumed to contain an LLC packet. Regardless of whether the '-e'
1013 option is specified or not, the source routing information is printed
1014 for source-routed packets.
1015
1016 On 802.11 networks, the '-e' option causes tcpdump to print the `frame
1017 control' fields, all of the addresses in the 802.11 header, and the
1018 packet length. As on FDDI networks, packets are assumed to contain an
1019 LLC packet.
1020
1021 (N.B.: The following description assumes familiarity with the SLIP com‐
1022 pression algorithm described in RFC-1144.)
1023
1024 On SLIP links, a direction indicator (``I'' for inbound, ``O'' for out‐
1025 bound), packet type, and compression information are printed out. The
1026 packet type is printed first. The three types are ip, utcp, and ctcp.
1027 No further link information is printed for ip packets. For TCP pack‐
1028 ets, the connection identifier is printed following the type. If the
1029 packet is compressed, its encoded header is printed out. The special
1030 cases are printed out as *S+n and *SA+n, where n is the amount by which
1031 the sequence number (or sequence number and ack) has changed. If it is
1032 not a special case, zero or more changes are printed. A change is
1033 indicated by U (urgent pointer), W (window), A (ack), S (sequence num‐
1034 ber), and I (packet ID), followed by a delta (+n or -n), or a new value
1035 (=n). Finally, the amount of data in the packet and compressed header
1036 length are printed.
1037
1038 For example, the following line shows an outbound compressed TCP
1039 packet, with an implicit connection identifier; the ack has changed by
1040 6, the sequence number by 49, and the packet ID by 6; there are 3 bytes
1041 of data and 6 bytes of compressed header:
1042 O ctcp * A+6 S+49 I+6 3 (6)
1043
1044 ARP/RARP Packets
1045
1046 Arp/rarp output shows the type of request and its arguments. The for‐
1047 mat is intended to be self explanatory. Here is a short sample taken
1048 from the start of an `rlogin' from host rtsg to host csam:
1049 arp who-has csam tell rtsg
1050 arp reply csam is-at CSAM
1051 The first line says that rtsg sent an arp packet asking for the Ether‐
1052 net address of internet host csam. Csam replies with its Ethernet
1053 address (in this example, Ethernet addresses are in caps and internet
1054 addresses in lower case).
1055
1056 This would look less redundant if we had done tcpdump -n:
1057 arp who-has 128.3.254.6 tell 128.3.254.68
1058 arp reply 128.3.254.6 is-at 02:07:01:00:01:c4
1059
1060 If we had done tcpdump -e, the fact that the first packet is broadcast
1061 and the second is point-to-point would be visible:
1062 RTSG Broadcast 0806 64: arp who-has csam tell rtsg
1063 CSAM RTSG 0806 64: arp reply csam is-at CSAM
1064 For the first packet this says the Ethernet source address is RTSG, the
1065 destination is the Ethernet broadcast address, the type field contained
1066 hex 0806 (type ETHER_ARP) and the total length was 64 bytes.
1067
1068 TCP Packets
1069
1070 (N.B.:The following description assumes familiarity with the TCP proto‐
1071 col described in RFC-793. If you are not familiar with the protocol,
1072 neither this description nor tcpdump will be of much use to you.)
1073
1074 The general format of a tcp protocol line is:
1075 src > dst: flags data-seqno ack window urgent options
1076 Src and dst are the source and destination IP addresses and ports.
1077 Flags are some combination of S (SYN), F (FIN), P (PUSH), R (RST), W
1078 (ECN CWR) or E (ECN-Echo), or a single `.' (no flags). Data-seqno
1079 describes the portion of sequence space covered by the data in this
1080 packet (see example below). Ack is sequence number of the next data
1081 expected the other direction on this connection. Window is the number
1082 of bytes of receive buffer space available the other direction on this
1083 connection. Urg indicates there is `urgent' data in the packet.
1084 Options are tcp options enclosed in angle brackets (e.g., <mss 1024>).
1085
1086 Src, dst and flags are always present. The other fields depend on the
1087 contents of the packet's tcp protocol header and are output only if
1088 appropriate.
1089
1090 Here is the opening portion of an rlogin from host rtsg to host csam.
1091 rtsg.1023 > csam.login: S 768512:768512(0) win 4096 <mss 1024>
1092 csam.login > rtsg.1023: S 947648:947648(0) ack 768513 win 4096 <mss 1024>
1093 rtsg.1023 > csam.login: . ack 1 win 4096
1094 rtsg.1023 > csam.login: P 1:2(1) ack 1 win 4096
1095 csam.login > rtsg.1023: . ack 2 win 4096
1096 rtsg.1023 > csam.login: P 2:21(19) ack 1 win 4096
1097 csam.login > rtsg.1023: P 1:2(1) ack 21 win 4077
1098 csam.login > rtsg.1023: P 2:3(1) ack 21 win 4077 urg 1
1099 csam.login > rtsg.1023: P 3:4(1) ack 21 win 4077 urg 1
1100 The first line says that tcp port 1023 on rtsg sent a packet to port
1101 login on csam. The S indicates that the SYN flag was set. The packet
1102 sequence number was 768512 and it contained no data. (The notation is
1103 `first:last(nbytes)' which means `sequence numbers first up to but not
1104 including last which is nbytes bytes of user data'.) There was no
1105 piggy-backed ack, the available receive window was 4096 bytes and there
1106 was a max-segment-size option requesting an mss of 1024 bytes.
1107
1108 Csam replies with a similar packet except it includes a piggy-backed
1109 ack for rtsg's SYN. Rtsg then acks csam's SYN. The `.' means no flags
1110 were set. The packet contained no data so there is no data sequence
1111 number. Note that the ack sequence number is a small integer (1). The
1112 first time tcpdump sees a tcp `conversation', it prints the sequence
1113 number from the packet. On subsequent packets of the conversation, the
1114 difference between the current packet's sequence number and this ini‐
1115 tial sequence number is printed. This means that sequence numbers
1116 after the first can be interpreted as relative byte positions in the
1117 conversation's data stream (with the first data byte each direction
1118 being `1'). `-S' will override this feature, causing the original
1119 sequence numbers to be output.
1120
1121 On the 6th line, rtsg sends csam 19 bytes of data (bytes 2 through 20
1122 in the rtsg → csam side of the conversation). The PUSH flag is set in
1123 the packet. On the 7th line, csam says it's received data sent by rtsg
1124 up to but not including byte 21. Most of this data is apparently sit‐
1125 ting in the socket buffer since csam's receive window has gotten 19
1126 bytes smaller. Csam also sends one byte of data to rtsg in this
1127 packet. On the 8th and 9th lines, csam sends two bytes of urgent,
1128 pushed data to rtsg.
1129
1130 If the snapshot was small enough that tcpdump didn't capture the full
1131 TCP header, it interprets as much of the header as it can and then
1132 reports ``[|tcp]'' to indicate the remainder could not be interpreted.
1133 If the header contains a bogus option (one with a length that's either
1134 too small or beyond the end of the header), tcpdump reports it as
1135 ``[bad opt]'' and does not interpret any further options (since it's
1136 impossible to tell where they start). If the header length indicates
1137 options are present but the IP datagram length is not long enough for
1138 the options to actually be there, tcpdump reports it as ``[bad hdr
1139 length]''.
1140
1141 Capturing TCP packets with particular flag combinations (SYN-ACK, URG-
1142 ACK, etc.)
1143
1144 There are 8 bits in the control bits section of the TCP header:
1145
1146 CWR | ECE | URG | ACK | PSH | RST | SYN | FIN
1147
1148 Let's assume that we want to watch packets used in establishing a TCP
1149 connection. Recall that TCP uses a 3-way handshake protocol when it
1150 initializes a new connection; the connection sequence with regard to
1151 the TCP control bits is
1152
1153 1) Caller sends SYN
1154 2) Recipient responds with SYN, ACK
1155 3) Caller sends ACK
1156
1157 Now we're interested in capturing packets that have only the SYN bit
1158 set (Step 1). Note that we don't want packets from step 2 (SYN-ACK),
1159 just a plain initial SYN. What we need is a correct filter expression
1160 for tcpdump.
1161
1162 Recall the structure of a TCP header without options:
1163
1164 0 15 31
1165 -----------------------------------------------------------------
1166 | source port | destination port |
1167 -----------------------------------------------------------------
1168 | sequence number |
1169 -----------------------------------------------------------------
1170 | acknowledgment number |
1171 -----------------------------------------------------------------
1172 | HL | rsvd |C|E|U|A|P|R|S|F| window size |
1173 -----------------------------------------------------------------
1174 | TCP checksum | urgent pointer |
1175 -----------------------------------------------------------------
1176
1177 A TCP header usually holds 20 octets of data, unless options are
1178 present. The first line of the graph contains octets 0 - 3, the second
1179 line shows octets 4 - 7 etc.
1180
1181 Starting to count with 0, the relevant TCP control bits are contained
1182 in octet 13:
1183
1184 0 7| 15| 23| 31
1185 ----------------|---------------|---------------|----------------
1186 | HL | rsvd |C|E|U|A|P|R|S|F| window size |
1187 ----------------|---------------|---------------|----------------
1188 | | 13th octet | | |
1189
1190 Let's have a closer look at octet no. 13:
1191
1192 | |
1193 |---------------|
1194 |C|E|U|A|P|R|S|F|
1195 |---------------|
1196 |7 5 3 0|
1197
1198 These are the TCP control bits we are interested in. We have numbered
1199 the bits in this octet from 0 to 7, right to left, so the PSH bit is
1200 bit number 3, while the URG bit is number 5.
1201
1202 Recall that we want to capture packets with only SYN set. Let's see
1203 what happens to octet 13 if a TCP datagram arrives with the SYN bit set
1204 in its header:
1205
1206 |C|E|U|A|P|R|S|F|
1207 |---------------|
1208 |0 0 0 0 0 0 1 0|
1209 |---------------|
1210 |7 6 5 4 3 2 1 0|
1211
1212 Looking at the control bits section we see that only bit number 1 (SYN)
1213 is set.
1214
1215 Assuming that octet number 13 is an 8-bit unsigned integer in network
1216 byte order, the binary value of this octet is
1217
1218 00000010
1219
1220 and its decimal representation is
1221
1222 7 6 5 4 3 2 1 0
1223 0*2 + 0*2 + 0*2 + 0*2 + 0*2 + 0*2 + 1*2 + 0*2 = 2
1224
1225 We're almost done, because now we know that if only SYN is set, the
1226 value of the 13th octet in the TCP header, when interpreted as a 8-bit
1227 unsigned integer in network byte order, must be exactly 2.
1228
1229 This relationship can be expressed as
1230 tcp[13] == 2
1231
1232 We can use this expression as the filter for tcpdump in order to watch
1233 packets which have only SYN set:
1234 tcpdump -i xl0 tcp[13] == 2
1235
1236 The expression says "let the 13th octet of a TCP datagram have the dec‐
1237 imal value 2", which is exactly what we want.
1238
1239 Now, let's assume that we need to capture SYN packets, but we don't
1240 care if ACK or any other TCP control bit is set at the same time.
1241 Let's see what happens to octet 13 when a TCP datagram with SYN-ACK set
1242 arrives:
1243
1244 |C|E|U|A|P|R|S|F|
1245 |---------------|
1246 |0 0 0 1 0 0 1 0|
1247 |---------------|
1248 |7 6 5 4 3 2 1 0|
1249
1250 Now bits 1 and 4 are set in the 13th octet. The binary value of octet
1251 13 is
1252
1253 00010010
1254
1255 which translates to decimal
1256
1257 7 6 5 4 3 2 1 0
1258 0*2 + 0*2 + 0*2 + 1*2 + 0*2 + 0*2 + 1*2 + 0*2 = 18
1259
1260 Now we can't just use 'tcp[13] == 18' in the tcpdump filter expression,
1261 because that would select only those packets that have SYN-ACK set, but
1262 not those with only SYN set. Remember that we don't care if ACK or any
1263 other control bit is set as long as SYN is set.
1264
1265 In order to achieve our goal, we need to logically AND the binary value
1266 of octet 13 with some other value to preserve the SYN bit. We know
1267 that we want SYN to be set in any case, so we'll logically AND the
1268 value in the 13th octet with the binary value of a SYN:
1269
1270 00010010 SYN-ACK 00000010 SYN
1271 AND 00000010 (we want SYN) AND 00000010 (we want SYN)
1272 -------- --------
1273 = 00000010 = 00000010
1274
1275 We see that this AND operation delivers the same result regardless
1276 whether ACK or another TCP control bit is set. The decimal representa‐
1277 tion of the AND value as well as the result of this operation is 2
1278 (binary 00000010), so we know that for packets with SYN set the follow‐
1279 ing relation must hold true:
1280
1281 ( ( value of octet 13 ) AND ( 2 ) ) == ( 2 )
1282
1283 This points us to the tcpdump filter expression
1284 tcpdump -i xl0 'tcp[13] & 2 == 2'
1285
1286 Note that you should use single quotes or a backslash in the expression
1287 to hide the AND ('&') special character from the shell.
1288
1289 UDP Packets
1290
1291 UDP format is illustrated by this rwho packet:
1292 actinide.who > broadcast.who: udp 84
1293 This says that port who on host actinide sent a udp datagram to port
1294 who on host broadcast, the Internet broadcast address. The packet con‐
1295 tained 84 bytes of user data.
1296
1297 Some UDP services are recognized (from the source or destination port
1298 number) and the higher level protocol information printed. In particu‐
1299 lar, Domain Name service requests (RFC-1034/1035) and Sun RPC calls
1300 (RFC-1050) to NFS.
1301
1302 UDP Name Server Requests
1303
1304 (N.B.:The following description assumes familiarity with the Domain
1305 Service protocol described in RFC-1035. If you are not familiar with
1306 the protocol, the following description will appear to be written in
1307 greek.)
1308
1309 Name server requests are formatted as
1310 src > dst: id op? flags qtype qclass name (len)
1311 h2opolo.1538 > helios.domain: 3+ A? ucbvax.berkeley.edu. (37)
1312 Host h2opolo asked the domain server on helios for an address record
1313 (qtype=A) associated with the name ucbvax.berkeley.edu. The query id
1314 was `3'. The `+' indicates the recursion desired flag was set. The
1315 query length was 37 bytes, not including the UDP and IP protocol head‐
1316 ers. The query operation was the normal one, Query, so the op field
1317 was omitted. If the op had been anything else, it would have been
1318 printed between the `3' and the `+'. Similarly, the qclass was the
1319 normal one, C_IN, and omitted. Any other qclass would have been
1320 printed immediately after the `A'.
1321
1322 A few anomalies are checked and may result in extra fields enclosed in
1323 square brackets: If a query contains an answer, authority records or
1324 additional records section, ancount, nscount, or arcount are printed as
1325 `[na]', `[nn]' or `[nau]' where n is the appropriate count. If any of
1326 the response bits are set (AA, RA or rcode) or any of the `must be
1327 zero' bits are set in bytes two and three, `[b2&3=x]' is printed, where
1328 x is the hex value of header bytes two and three.
1329
1330 UDP Name Server Responses
1331
1332 Name server responses are formatted as
1333 src > dst: id op rcode flags a/n/au type class data (len)
1334 helios.domain > h2opolo.1538: 3 3/3/7 A 128.32.137.3 (273)
1335 helios.domain > h2opolo.1537: 2 NXDomain* 0/1/0 (97)
1336 In the first example, helios responds to query id 3 from h2opolo with 3
1337 answer records, 3 name server records and 7 additional records. The
1338 first answer record is type A (address) and its data is internet
1339 address 128.32.137.3. The total size of the response was 273 bytes,
1340 excluding UDP and IP headers. The op (Query) and response code (NoEr‐
1341 ror) were omitted, as was the class (C_IN) of the A record.
1342
1343 In the second example, helios responds to query 2 with a response code
1344 of non-existent domain (NXDomain) with no answers, one name server and
1345 no authority records. The `*' indicates that the authoritative answer
1346 bit was set. Since there were no answers, no type, class or data were
1347 printed.
1348
1349 Other flag characters that might appear are `-' (recursion available,
1350 RA, not set) and `|' (truncated message, TC, set). If the `question'
1351 section doesn't contain exactly one entry, `[nq]' is printed.
1352
1353 Note that name server requests and responses tend to be large and the
1354 default snaplen of 68 bytes may not capture enough of the packet to
1355 print. Use the -s flag to increase the snaplen if you need to seri‐
1356 ously investigate name server traffic. `-s 128' has worked well for
1357 me.
1358
1359
1360 SMB/CIFS decoding
1361
1362 tcpdump now includes fairly extensive SMB/CIFS/NBT decoding for data on
1363 UDP/137, UDP/138 and TCP/139. Some primitive decoding of IPX and Net‐
1364 BEUI SMB data is also done.
1365
1366 By default a fairly minimal decode is done, with a much more detailed
1367 decode done if -v is used. Be warned that with -v a single SMB packet
1368 may take up a page or more, so only use -v if you really want all the
1369 gory details.
1370
1371 For information on SMB packet formats and what all te fields mean see
1372 www.cifs.org or the pub/samba/specs/ directory on your favorite
1373 samba.org mirror site. The SMB patches were written by Andrew Tridgell
1374 (tridge@samba.org).
1375
1376
1377 NFS Requests and Replies
1378
1379 Sun NFS (Network File System) requests and replies are printed as:
1380 src.xid > dst.nfs: len op args
1381 src.nfs > dst.xid: reply stat len op results
1382 sushi.6709 > wrl.nfs: 112 readlink fh 21,24/10.73165
1383 wrl.nfs > sushi.6709: reply ok 40 readlink "../var"
1384 sushi.201b > wrl.nfs:
1385 144 lookup fh 9,74/4096.6878 "xcolors"
1386 wrl.nfs > sushi.201b:
1387 reply ok 128 lookup fh 9,74/4134.3150
1388 In the first line, host sushi sends a transaction with id 6709 to wrl
1389 (note that the number following the src host is a transaction id, not
1390 the source port). The request was 112 bytes, excluding the UDP and IP
1391 headers. The operation was a readlink (read symbolic link) on file
1392 handle (fh) 21,24/10.731657119. (If one is lucky, as in this case, the
1393 file handle can be interpreted as a major,minor device number pair,
1394 followed by the inode number and generation number.) Wrl replies `ok'
1395 with the contents of the link.
1396
1397 In the third line, sushi asks wrl to lookup the name `xcolors' in
1398 directory file 9,74/4096.6878. Note that the data printed depends on
1399 the operation type. The format is intended to be self explanatory if
1400 read in conjunction with an NFS protocol spec.
1401
1402 If the -v (verbose) flag is given, additional information is printed.
1403 For example:
1404 sushi.1372a > wrl.nfs:
1405 148 read fh 21,11/12.195 8192 bytes @ 24576
1406 wrl.nfs > sushi.1372a:
1407 reply ok 1472 read REG 100664 ids 417/0 sz 29388
1408 (-v also prints the IP header TTL, ID, length, and fragmentation
1409 fields, which have been omitted from this example.) In the first line,
1410 sushi asks wrl to read 8192 bytes from file 21,11/12.195, at byte off‐
1411 set 24576. Wrl replies `ok'; the packet shown on the second line is
1412 the first fragment of the reply, and hence is only 1472 bytes long (the
1413 other bytes will follow in subsequent fragments, but these fragments do
1414 not have NFS or even UDP headers and so might not be printed, depending
1415 on the filter expression used). Because the -v flag is given, some of
1416 the file attributes (which are returned in addition to the file data)
1417 are printed: the file type (``REG'', for regular file), the file mode
1418 (in octal), the uid and gid, and the file size.
1419
1420 If the -v flag is given more than once, even more details are printed.
1421
1422 Note that NFS requests are very large and much of the detail won't be
1423 printed unless snaplen is increased. Try using `-s 192' to watch NFS
1424 traffic.
1425
1426 NFS reply packets do not explicitly identify the RPC operation.
1427 Instead, tcpdump keeps track of ``recent'' requests, and matches them
1428 to the replies using the transaction ID. If a reply does not closely
1429 follow the corresponding request, it might not be parsable.
1430
1431 AFS Requests and Replies
1432
1433 Transarc AFS (Andrew File System) requests and replies are printed as:
1434
1435 src.sport > dst.dport: rx packet-type
1436 src.sport > dst.dport: rx packet-type service call call-name args
1437 src.sport > dst.dport: rx packet-type service reply call-name args
1438 elvis.7001 > pike.afsfs:
1439 rx data fs call rename old fid 536876964/1/1 ".newsrc.new"
1440 new fid 536876964/1/1 ".newsrc"
1441 pike.afsfs > elvis.7001: rx data fs reply rename
1442 In the first line, host elvis sends a RX packet to pike. This was a RX
1443 data packet to the fs (fileserver) service, and is the start of an RPC
1444 call. The RPC call was a rename, with the old directory file id of
1445 536876964/1/1 and an old filename of `.newsrc.new', and a new directory
1446 file id of 536876964/1/1 and a new filename of `.newsrc'. The host
1447 pike responds with a RPC reply to the rename call (which was success‐
1448 ful, because it was a data packet and not an abort packet).
1449
1450 In general, all AFS RPCs are decoded at least by RPC call name. Most
1451 AFS RPCs have at least some of the arguments decoded (generally only
1452 the `interesting' arguments, for some definition of interesting).
1453
1454 The format is intended to be self-describing, but it will probably not
1455 be useful to people who are not familiar with the workings of AFS and
1456 RX.
1457
1458 If the -v (verbose) flag is given twice, acknowledgement packets and
1459 additional header information is printed, such as the the RX call ID,
1460 call number, sequence number, serial number, and the RX packet flags.
1461
1462 If the -v flag is given twice, additional information is printed, such
1463 as the the RX call ID, serial number, and the RX packet flags. The MTU
1464 negotiation information is also printed from RX ack packets.
1465
1466 If the -v flag is given three times, the security index and service id
1467 are printed.
1468
1469 Error codes are printed for abort packets, with the exception of Ubik
1470 beacon packets (because abort packets are used to signify a yes vote
1471 for the Ubik protocol).
1472
1473 Note that AFS requests are very large and many of the arguments won't
1474 be printed unless snaplen is increased. Try using `-s 256' to watch
1475 AFS traffic.
1476
1477 AFS reply packets do not explicitly identify the RPC operation.
1478 Instead, tcpdump keeps track of ``recent'' requests, and matches them
1479 to the replies using the call number and service ID. If a reply does
1480 not closely follow the corresponding request, it might not be parsable.
1481
1482
1483 KIP AppleTalk (DDP in UDP)
1484
1485 AppleTalk DDP packets encapsulated in UDP datagrams are de-encapsulated
1486 and dumped as DDP packets (i.e., all the UDP header information is dis‐
1487 carded). The file /etc/atalk.names is used to translate AppleTalk net
1488 and node numbers to names. Lines in this file have the form
1489 number name
1490
1491 1.254 ether
1492 16.1 icsd-net
1493 1.254.110 ace
1494 The first two lines give the names of AppleTalk networks. The third
1495 line gives the name of a particular host (a host is distinguished from
1496 a net by the 3rd octet in the number - a net number must have two
1497 octets and a host number must have three octets.) The number and name
1498 should be separated by whitespace (blanks or tabs). The
1499 /etc/atalk.names file may contain blank lines or comment lines (lines
1500 starting with a `#').
1501
1502 AppleTalk addresses are printed in the form
1503 net.host.port
1504
1505 144.1.209.2 > icsd-net.112.220
1506 office.2 > icsd-net.112.220
1507 jssmag.149.235 > icsd-net.2
1508 (If the /etc/atalk.names doesn't exist or doesn't contain an entry for
1509 some AppleTalk host/net number, addresses are printed in numeric form.)
1510 In the first example, NBP (DDP port 2) on net 144.1 node 209 is sending
1511 to whatever is listening on port 220 of net icsd node 112. The second
1512 line is the same except the full name of the source node is known
1513 (`office'). The third line is a send from port 235 on net jssmag node
1514 149 to broadcast on the icsd-net NBP port (note that the broadcast
1515 address (255) is indicated by a net name with no host number - for this
1516 reason it's a good idea to keep node names and net names distinct in
1517 /etc/atalk.names).
1518
1519 NBP (name binding protocol) and ATP (AppleTalk transaction protocol)
1520 packets have their contents interpreted. Other protocols just dump the
1521 protocol name (or number if no name is registered for the protocol) and
1522 packet size.
1523
1524 NBP packets are formatted like the following examples:
1525 icsd-net.112.220 > jssmag.2: nbp-lkup 190: "=:LaserWriter@*"
1526 jssmag.209.2 > icsd-net.112.220: nbp-reply 190: "RM1140:LaserWriter@*" 250
1527 techpit.2 > icsd-net.112.220: nbp-reply 190: "techpit:LaserWriter@*" 186
1528 The first line is a name lookup request for laserwriters sent by net
1529 icsd host 112 and broadcast on net jssmag. The nbp id for the lookup
1530 is 190. The second line shows a reply for this request (note that it
1531 has the same id) from host jssmag.209 saying that it has a laserwriter
1532 resource named "RM1140" registered on port 250. The third line is
1533 another reply to the same request saying host techpit has laserwriter
1534 "techpit" registered on port 186.
1535
1536 ATP packet formatting is demonstrated by the following example:
1537 jssmag.209.165 > helios.132: atp-req 12266<0-7> 0xae030001
1538 helios.132 > jssmag.209.165: atp-resp 12266:0 (512) 0xae040000
1539 helios.132 > jssmag.209.165: atp-resp 12266:1 (512) 0xae040000
1540 helios.132 > jssmag.209.165: atp-resp 12266:2 (512) 0xae040000
1541 helios.132 > jssmag.209.165: atp-resp 12266:3 (512) 0xae040000
1542 helios.132 > jssmag.209.165: atp-resp 12266:4 (512) 0xae040000
1543 helios.132 > jssmag.209.165: atp-resp 12266:5 (512) 0xae040000
1544 helios.132 > jssmag.209.165: atp-resp 12266:6 (512) 0xae040000
1545 helios.132 > jssmag.209.165: atp-resp*12266:7 (512) 0xae040000
1546 jssmag.209.165 > helios.132: atp-req 12266<3,5> 0xae030001
1547 helios.132 > jssmag.209.165: atp-resp 12266:3 (512) 0xae040000
1548 helios.132 > jssmag.209.165: atp-resp 12266:5 (512) 0xae040000
1549 jssmag.209.165 > helios.132: atp-rel 12266<0-7> 0xae030001
1550 jssmag.209.133 > helios.132: atp-req* 12267<0-7> 0xae030002
1551 Jssmag.209 initiates transaction id 12266 with host helios by request‐
1552 ing up to 8 packets (the `<0-7>'). The hex number at the end of the
1553 line is the value of the `userdata' field in the request.
1554
1555 Helios responds with 8 512-byte packets. The `:digit' following the
1556 transaction id gives the packet sequence number in the transaction and
1557 the number in parens is the amount of data in the packet, excluding the
1558 atp header. The `*' on packet 7 indicates that the EOM bit was set.
1559
1560 Jssmag.209 then requests that packets 3 & 5 be retransmitted. Helios
1561 resends them then jssmag.209 releases the transaction. Finally, jss‐
1562 mag.209 initiates the next request. The `*' on the request indicates
1563 that XO (`exactly once') was not set.
1564
1565
1566 IP Fragmentation
1567
1568 Fragmented Internet datagrams are printed as
1569 (frag id:size@offset+)
1570 (frag id:size@offset)
1571 (The first form indicates there are more fragments. The second indi‐
1572 cates this is the last fragment.)
1573
1574 Id is the fragment id. Size is the fragment size (in bytes) excluding
1575 the IP header. Offset is this fragment's offset (in bytes) in the
1576 original datagram.
1577
1578 The fragment information is output for each fragment. The first frag‐
1579 ment contains the higher level protocol header and the frag info is
1580 printed after the protocol info. Fragments after the first contain no
1581 higher level protocol header and the frag info is printed after the
1582 source and destination addresses. For example, here is part of an ftp
1583 from arizona.edu to lbl-rtsg.arpa over a CSNET connection that doesn't
1584 appear to handle 576 byte datagrams:
1585 arizona.ftp-data > rtsg.1170: . 1024:1332(308) ack 1 win 4096 (frag 595a:328@0+)
1586 arizona > rtsg: (frag 595a:204@328)
1587 rtsg.1170 > arizona.ftp-data: . ack 1536 win 2560
1588 There are a couple of things to note here: First, addresses in the 2nd
1589 line don't include port numbers. This is because the TCP protocol
1590 information is all in the first fragment and we have no idea what the
1591 port or sequence numbers are when we print the later fragments. Sec‐
1592 ond, the tcp sequence information in the first line is printed as if
1593 there were 308 bytes of user data when, in fact, there are 512 bytes
1594 (308 in the first frag and 204 in the second). If you are looking for
1595 holes in the sequence space or trying to match up acks with packets,
1596 this can fool you.
1597
1598 A packet with the IP don't fragment flag is marked with a trailing
1599 (DF).
1600
1601 Timestamps
1602
1603 By default, all output lines are preceded by a timestamp. The time‐
1604 stamp is the current clock time in the form
1605 hh:mm:ss.frac
1606 and is as accurate as the kernel's clock. The timestamp reflects the
1607 time the kernel first saw the packet. No attempt is made to account
1608 for the time lag between when the Ethernet interface removed the packet
1609 from the wire and when the kernel serviced the `new packet' interrupt.
1610
1612 stty(1), pcap(3), bpf(4), nit(4P), pfconfig(8)
1613
1615 The original authors are:
1616
1617 Van Jacobson, Craig Leres and Steven McCanne, all of the Lawrence
1618 Berkeley National Laboratory, University of California, Berkeley, CA.
1619
1620 It is currently being maintained by tcpdump.org.
1621
1622 The current version is available via http:
1623
1624 http://www.tcpdump.org/
1625
1626 The original distribution is available via anonymous ftp:
1627
1628 ftp://ftp.ee.lbl.gov/tcpdump.tar.Z
1629
1630 IPv6/IPsec support is added by WIDE/KAME project. This program uses
1631 Eric Young's SSLeay library, under specific configuration.
1632
1634 Please send problems, bugs, questions, desirable enhancements, etc. to:
1635
1636 tcpdump-workers@tcpdump.org
1637
1638 Please send source code contributions, etc. to:
1639
1640 patches@tcpdump.org
1641
1642 NIT doesn't let you watch your own outbound traffic, BPF will. We rec‐
1643 ommend that you use the latter.
1644
1645 On Linux systems with 2.0[.x] kernels:
1646
1647 packets on the loopback device will be seen twice;
1648
1649 packet filtering cannot be done in the kernel, so that all pack‐
1650 ets must be copied from the kernel in order to be filtered in
1651 user mode;
1652
1653 all of a packet, not just the part that's within the snapshot
1654 length, will be copied from the kernel (the 2.0[.x] packet cap‐
1655 ture mechanism, if asked to copy only part of a packet to user‐
1656 land, will not report the true length of the packet; this would
1657 cause most IP packets to get an error from tcpdump);
1658
1659 capturing on some PPP devices won't work correctly.
1660
1661 We recommend that you upgrade to a 2.2 or later kernel.
1662
1663 Some attempt should be made to reassemble IP fragments or, at least to
1664 compute the right length for the higher level protocol.
1665
1666 Name server inverse queries are not dumped correctly: the (empty) ques‐
1667 tion section is printed rather than real query in the answer section.
1668 Some believe that inverse queries are themselves a bug and prefer to
1669 fix the program generating them rather than tcpdump.
1670
1671 A packet trace that crosses a daylight savings time change will give
1672 skewed time stamps (the time change is ignored).
1673
1674 Filter expressions on fields other than those in Token Ring headers
1675 will not correctly handle source-routed Token Ring packets.
1676
1677 Filter expressions on fields other than those in 802.11 headers will
1678 not correctly handle 802.11 data packets with both To DS and From DS
1679 set.
1680
1681 ip6 proto should chase header chain, but at this moment it does not.
1682 ip6 protochain is supplied for this behavior.
1683
1684 Arithmetic expression against transport layer headers, like tcp[0],
1685 does not work against IPv6 packets. It only looks at IPv4 packets.
1686
1687
1688
1689 18 April 2005 TCPDUMP(8)