Understanding TCPDUMP

Table of Contents

TCP Basics

Tcpdump is a great tool for testing those strange issues where nothing seem to make sense. Using this tool we can track incoming request and verify the server is receiving a packet and how the server sends out the data, we can also use it to track request originated on the server and what may of ended up with the packets. Below I will go over some basic examples.

Before we get to in depth with how Tcpdump works I thought it may be beneficial to review how a TCP connection is handled, Remember TCP is a stateful protocol unlike UDP which is stateless.

TCPDUMP

Now that we have a better understanding of tcpdump lets go over a few examples. Have a look at the dump below and, what do you think happened to this TCP connection?

tcpdump -nn -i eth0 port 80
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
15:43:42.679984 IP 64.39.0.68.31226 > 98.129.169.14.80: S 1829087099:1829087099(0) win 5840 <mss 1380,sackOK,timestamp 63137047 0,nop,wscale 7>
15:43:42.679984 IP 98.129.169.14.80 > 64.39.0.68.31226: S 1032427262:1032427262(0) ack 1829087100 win 5792 <mss 1460,sackOK,timestamp 1030516906 63137047,nop,wscale 5>
15:43:42.699984 IP 64.39.0.68.31226 > 98.129.169.14.80: . ack 1 win 46 <nop,nop,timestamp 63137049 1030516906>
15:43:47.699984 IP 98.129.169.14.80 > 64.39.0.68.31226: F 1:1(0) ack 1 win 181 <nop,nop,timestamp 1030517408 63137049>
15:43:47.709984 IP 64.39.0.68.31226 > 98.129.169.14.80: F 1:1(0) ack 2 win 46 <nop,nop,timestamp 63137550 1030517408>
15:43:47.709984 IP 98.129.169.14.80 > 64.39.0.68.31226: . ack 2 win 181 <nop,nop,timestamp 1030517409 63137550>
^C
6 packets captured
6 packets received by filter
0 packets dropped by kernel

Have a look at this dump, what do you think may be happening?

$ tcpdump -nn -i eth0 port 80
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
15:48:00.639984 IP 64.39.0.68.40858 > 98.129.169.14.80: S 3026500468:3026500468(0) win 5840 <mss 1380,sackOK,timestamp 63162843 0,nop,wscale 7>
15:48:00.639984 IP 98.129.169.14.80 > 64.39.0.68.40858: S 783066446:783066446(0) ack 3026500469 win 5792 <mss 1460,sackOK,timestamp 1030542702 63162843,nop,wscale 5>
15:48:03.629984 IP 64.39.0.68.40858 > 98.129.169.14.80: S 3026500468:3026500468(0) win 5840 <mss 1380,sackOK,timestamp 63163143 0,nop,wscale 7>
15:48:03.629984 IP 98.129.169.14.80 > 64.39.0.68.40858: S 783066446:783066446(0) ack 3026500469 win 5792 <mss 1460,sackOK,timestamp 1030543001 63162843,nop,wscale 5>
15:48:04.489984 IP 98.129.169.14.80 > 64.39.0.68.40858: S 783066446:783066446(0) ack 3026500469 win 5792 <mss 1460,sackOK,timestamp 1030543087 63162843,nop,wscale 5>
15:48:09.629984 IP 64.39.0.68.40858 > 98.129.169.14.80: S 3026500468:3026500468(0) win 5840 <mss 1380,sackOK,timestamp 63163743 0,nop,wscale 7>
15:48:09.629984 IP 98.129.169.14.80 > 64.39.0.68.40858: S 783066446:783066446(0) ack 3026500469 win 5792 <mss 1460,sackOK,timestamp 1030543601 63162843,nop,wscale 5>
15:48:10.489984 IP 98.129.169.14.80 > 64.39.0.68.40858: S 783066446:783066446(0) ack 3026500469 win 5792 <mss 1460,sackOK,timestamp 1030543687 63162843,nop,wscale 5>
15:48:13.289984 IP 98.129.169.14.80 > 64.39.0.68.42551: S 280296214:280296214(0) ack 1624128497 win 5792 <mss 1460,sackOK,timestamp 1030543967 63159568,nop,wscale 5>
15:48:13.299984 IP 64.39.0.68.42551 > 98.129.169.14.80: R 1:1(0) ack 1 win 5792
15:48:21.629984 IP 64.39.0.68.40858 > 98.129.169.14.80: S 3026500468:3026500468(0) win 5840 <mss 1380,sackOK,timestamp 63164943 0,nop,wscale 7>
15:48:21.629984 IP 98.129.169.14.80 > 64.39.0.68.40858: S 783066446:783066446(0) ack 3026500469 win 5792 <mss 1460,sackOK,timestamp 1030544801 63162843,nop,wscale 5>
15:48:22.489984 IP 98.129.169.14.80 > 64.39.0.68.40858: S 783066446:783066446(0) ack 3026500469 win 5792 <mss 1460,sackOK,timestamp 1030544887 63162843,nop,wscale 5>
^C
13 packets captured
13 packets received by filter
0 packets dropped by kernel

As you can see tcpdump is a very powerful tool, below lets go over some more examples on flags.

Author: Jeffrey Ness <jness@flip-edesign.com>

Date: 2010-03-22 10:12:39 CDT

HTML generated by org-mode 6.21b in emacs 23