tcpdump for Dummies

Table of contents

IntroductionBACK TO TOC

In this article  I would like to talk about one of the most useful tools in my networking toolbox and that is tcpdump. Unfortunately mastering this tool completely is not an easy task. Yet stuff you do the most is relatively simple and may become a good springboard when diving into more complex topics.

tcpdump usesBACK TO TOC

tcpdump is a packet sniffer. It is able to capture traffic that passes through a machine. It operates on a packet level, meaning that it captures the actual packets that fly in and out of your computer. It can save the packets into a file. You can save whole packets or only the headers. Later you can “play” recorded file and apply different filters on the packets, telling tcpdump to ignore packets that you are not interested to see.

Under the hood, tcpdump understands protocols and host names. It will do all in its power to see what host sent each packet and will tell you its name instead of the IP address.

It is exceptionally useful tool for debugging what might have caused certain networking related problem. It is an excellent tool to learn new things.

InvocationBACK TO TOC

Invoking tcpdump is easy. First thing that you have to remember is that you should either be logged in as root or  be a sudoer on the computer – sudoer is someone who is entitled to gain administrator rights on computer for short period of time using sudo command.

Running tcpdump without any arguments makes it capture packets on first network interface (excluding lo) and print short description of each packet to output. This may cause a bit of a headache in case you are using network to connect to the machine. If you are connected with SSH or telnet (rlogin?), running tcpdump will produce a line of text for each incoming or outgoing packet. This line of text will cause SSH daemon to send a packet with this line, thus causing tcpdump to produce another line of text. And this will not stop until you do something about it.

Simple filteringBACK TO TOC

So first thing that we will learn about tcpdump is how to filter out SSH and telnet packets. We will study the basics of tcpdump filtering later in this guide, but for now just remember this syntax.

# tcpdump not port 22

“not port 22” is a filter specification that tells tcpdump to filter out packets with IP source or destination port 22. As you know port 22 is SSH port. Basically, when you tell tcpdump something like this, it will make tcpdump ignore all SSH packets – exactly what we needed.

Telnet on the other hand, uses port 23. So if you are connecting via telnet, you can filter that out with:

# tcpdump not port 23

Clear and simple!

Reading tcpdump‘s outputBACK TO TOC

By default tcpdump produces one line of text per every packet it intercepts. Each line starts with a time stamp. It tells you very precise time when packet arrived.

Next comes protocol name. Unfortunately, tcpdump understands very limited number of protocols. It won’t tell you the difference between packets belonging to HTTP and for instance FTP stream. Instead, it will mark such packets as IP packets. It does have some limited understanding of TCP. For instance it identifies TCP synchronization packets such as SYN, ACK, FIN and others. This information printed after source and destination IP addresses (if it IP packet).

Source and destination addresses follow protocol name. For IP packets, these are IP addresses. For other protocols, tcpdump does not print any identifiers unless explicitly asked to do so (see -e command line switch below).

Finally, tcpdump prints some information about the packet. For instance, it prints TCP sequence numbers, flags, ARP/ICMP commands, etc.

Here’s an example of typical tcpdump output.

17:50:03.089893 IP 69.61.72.101.www > 212.150.66.73.48777: P 1366488174:1366488582
(408) ack 2337505545 win 7240 <nop,nop,timestamp 1491222906 477679143>

This packet is part of HTTP data stream. You can see meaning of each and every field in the packet description in tcpdump’s manual page.

Here’s another example

17:50:00.718266 arp who-has 69.61.72.185 tell 69.61.72.1

This is ARP packet. It’s slightly more self explanatory than TCP packets. Again, to see exact meaning of each field in the packet description see tcpdump’s manual page.

Invocation continuedBACK TO TOC

Now, when we know how to invoke tcpdump even when connecting to the computer over some net, let’s see what command line switches are available for us.

Choosing an interfaceBACK TO TOC

We’ll start with a simple one. How to dump packets that arrived and sent through a certain network interface. -i command line argument does exactly this.

# tcpdump -i eth1

Will cause tcpdump to capture packets from network interface eth1. Or, considering our SSH/telnet experience:

# tcpdump -i eth1 not port 22

Finally, you can specify any as interface name, to tell tcpdump to listen to all interfaces.

# tcpdump -i any not port 22

Turning off name resolutionBACK TO TOC

As we debug networking issues, we may encounter a problem with how tcpdump works out of the box. The problem is that it tries to resolve every single IP address that it meets. I.e. when it sees an IP packet it asks DNS server for names of the computers behind IP address. It works flawlessly most of the time. However, there are two problems.

First, it slows down packet interception. It’s not a big deal when there are only few packets, but when there are thousands and tens of thousands it introduces a delay into the process. Amount of delay can be different, depending on the traffic.

Another, much more serious problem occurs when there is no DNS server around or when DNS server is not working properly. If this is the case, tcpdump spends few seconds trying to figure out two hostnames for each IP packet. This means virtually stopping intercepting the traffic.

Luckily there is a way around. There is an option that causes tcpdump to stop detecting hostnames and that is -n.

# tcpdump -n

And here are few variations of how you can use this option in conjunction with options that we have learned already.

# tcpdump -n -i eth1
# tcpdump -ni eth1 not port 22

Limiting number of packets to interceptBACK TO TOC

Here are few more useful options. Sometimes amount of traffic that goes in and out of your computer is very high, while all you want to see is just few packets. Often you want to see who sends you the traffic, but when you try to capture anything with tcpdump it dumps so many packets that you cannot understand anything. This is the case when -c command line switch becomes handy.

It tells tcpdump to limit number of packets it intercepts. You specify number of packets you want to see. tcpdump will capture that number of packets and exit. This is how you use it.

# tcpdump -c 10

Or with options that we’ve learned before.

# tcpdump -ni eth1 -c 10 not port 22

This will limit number of packets that tcpdump will receive to 10. Once received 10 packets, tcpdump will exit.

Saving captured dataBACK TO TOC

One of the most useful tcpdump features allows capturing incoming and outgoing packets into a file and then playing this file back. By the way, you can play this file not only with tcpdump, but also with WireShark (former Ethereal), the graphical packet analyzer.

You can do this with -w command line switch. It should be followed by the name of the file that will contain the packets. Like this:

# tcpdump -w file.cap

Or adding options that we’ve already seen

# tcpdump -ni eth1 -w file.cap not port 22

Changing packet size in the capture fileBACK TO TOC

By default, when capturing packets into a file, it will save only 68 bytes of the data from each packet. Rest of the information will be thrown away.

One of the things I do often when capturing traffic into a file, is to change the saved packet size. The thing is that disk space that is required to save the those few bytes is very cheap and available most of the time. Spending few spare megabytes of your disk space on capture isn’t too painful. On the other hand, loosing valuable portion of packets might be very critical.

So, what I usually do when capturing into a file is running tcpdump with -s command line switch. It tells tcpdump how many bytes for each packet to save. Specifying 0 as a packet’s snapshot length tells tcpdump to save whole packet. Here how it works:

# tcpdump -w file.cap -s 0

And with conjunction with options that we already saw:

# tcpdump -ni eth1 -w file.cap -s 0 -c 1000 not port 22

Obviously you can save as much data as you want. Specifying 1000 bytes will do the job for you. Just keep in mind that there are so called jumbo frames those size can be as big as 8Kb.

Reading from capture fileBACK TO TOC

Now, when we have captured some traffic into a file, we would like to play it back. -r command like switch tells tcpdump that it should read the data from a file, instead of capturing packets from interfaces. This is how it works.

# tcpdump -r file.cap

With capture file, we can easily analyze the packets and understand what’s inside. tcpdump introduces several options that will help us with this task. Lets see few of them.

Looking into packetsBACK TO TOC

There are several options that allow one to see more information about the packet. There is a problem though. tcpdump in general isn’t giving you too much information about packets. It doesn’t understand different protocols.

If you want to see packet’s content, it is better to use tools like Wireshark. It does understand protocols, analyzes them and allows you to see different fields, not only in TCP header, but in layer 7 protocols headers.

tcpdump is a command line tool and as most of the command line tools, its ability to present information is quiet limited. Yet, it still has few options that control the way packets presented.

Seeing Ethernet header for each packetBACK TO TOC

-e command line switch, causes tcpdump to present Ethernet (link level protocol) header for each printed packet. Lets see an example.

# tcpdump -e -n not port 22

Controlling time stampBACK TO TOC

There are four command line switches that control the way how tcpdump prints time stamp. First, there is -t option. It makes tcpdump not to print time stamps. Next comes -tt. It causes tcpdump to print time stamp as number of seconds since Jan. 1st 1970 and a fraction of a second. -ttt prints the delta between this line and a previous one. Finally, -tttt causes tcpdump to print time stamp in it’s regular format preceeded by date.

Controlling verbosityBACK TO TOC

-v causes tcpdump to print more information about each packet. With -vv tcpdump prints even more information. As you could guess, -vvv produces even more information. Finally -vvvv will produce an error message telling you there is no such option :D

Printing content of the packetBACK TO TOC

-x command line switch will make tcpdump to print each packet in hexadecimal format. Number of bytes that will be printed remains somewhat a mystery. As is, it will print first 82 bytes of the packet, excluding ethernet header. You can control number of bytes printed using -s command line switch.

In case you want to see ethernet header as well, use -xx. It will cause tcpdump to print extra 14 bytes for ethernet header.

Similarily -X and -XX will print contents of packet in hexadecimal and ASCII formats. The later will cause tcpdump to include ethernet header into printout.

Packet filteringBACK TO TOC

We already saw a simple filter. It causes tcpdump to ignore SSH packets, allowing us to run tcpdump from remote. Now lets try to understand the language that tcpdump uses to evaluate filter expressions.

Packet matchingBACK TO TOC

We should understand that tcpdump applies our filter on every single incoming and outgoing packet. If packet matches the filter, tcpdump aknownledges the packet and depending on command line switches either saves it to file or dumps it to the screen. Otherwise, tcpdump will ignore the packet and account it only when telling how many packets received, dropped and filtered out when it exits.

To demostrate this, lets go back to not port 22 expression. tcpdump ignores packets that either sourced or destined to port 22. When such packet arrives, tcpdump applies filter on it and since the result is false, it will drop the packet.

More qualifiersBACK TO TOC

So, from what we’ve seen so far, we can conclude that tcpdump understands a word port and understands expression negation with not. Actually, negating an expression is part of complex expressions syntax and we will talk about complex expressions a little later. In the meantime, lets see few more packet qualifiers that we can use in tcpdump expressions.

We’ve seen that port qualifier specifies either source or destination port number. In case we want to specify only the source port or only the destination port we can use src port or dst port. For instance, using following expression we can see all outgoing HTTP packets.

# tcpdump -n dst port 80

We can also specify ranges of ports. portrange, src portrange and dst portrange qualifiers do exactly this. For instance, lets see a command that captures all telnet and SSH packets.

# tcpdump -n portrange 22-23

Specifying addressesBACK TO TOC

Using dst host, src host and host qualifiers you can specify source, destination or any of them IP addresses. For example

# tcpdump src host alexandersandler.net

Will print all packets originating from alexandersandler.net computer.

You can also specify Ethernet addresses. You do that with ether src, ether dst and ether host qualifiers. Each should be followed by MAC address of either source, destination or source or destination machines.

You can specify networks as well. The net, src net and dst net qualifiers do exactly this. Their syntax however slighly more complex than those of a single host. This is due to a netmask that has to be specified.

You can use two basic forms of network specifications. One using netmask and the other so called CIDR notation. Here are few examples.

# tcpdump src net 67.207.148.0 mask 255.255.255.0

Or same command using CIDR notation.

# tcpdump src net 67.207.148.0/24

Note the word mask that does the job of specifying the network in first example. Second example is much shorter.

Other qualifiersBACK TO TOC

There are several useful qualifiers that don’t fall under any of the categories I already covered.

For instance, you can specify that you are interested in packets with specific length. length qualifier does this. less and greater qualifiers tell tcpdump that you are interested in packets whose length is less or greater than value you specified.

Here’s an example that demonstrates these qualifiers in use.

# tcpdump -ni eth1 greater 1000

Will capture only packets whose size is greater than 1000 bytes.

Complex filter expressionsBACK TO TOC

As we already saw we can build more complex filter expressions using tcpdump filters language. Actually, tcpdump allows exceptionally complex filtering expressions.

We’ve seen not port 22 expression. Applying this expression on certain packet will produce logical true for packets that are not sourced or destined to port 22. Or in two words, not negates the expression.

In addition to expression negation, we can build more complex expressions combining two smaller expression into one large using and and or keywords. In addition, you can use brackets to group several expressions together.

For example, lets see a tcpdump filter that causes tcpdump to capture packets larger then 100 bytes originating from google.com or from microsoft.com.

# tcpdump -XX greater 100 and \(src host google.com or src host microsoft.com\)

and and or keywords in tcpdump filter language have same precedence and evaluated left to right. This means that without brackets, tcpdump could have captured packets from microsoft.com disregarding packet size. With brackets, tcpdump first makes sure that all packets are greater than 100 bytes and only then checks their origin.

Note the backslash symbol (“\”) before brackets. We have to place them before brackets because of shell. Unix shell has special understanding of what brackets used for. Hence we have to tell shell to leave these particular brackets alone and pass them as they are to tcpdump. Backslash characters do exactly this.

Talking about precedence, we have to keep in mind that in tcpdump’s filter expression language not has higher precedence than and and or. tcpdump’s manual page has very nice example and emphasizes the meaning of this.

not host vs and host ace

and

not (host vs or host ace)

are two different expressions. Because not has higher precedence over and and or, filter from the first example will capture packets not to/from vs, but to/from ace. Second filter example on the other hand will capture packets that are not to/from vs and to/from ace. I.e. first will capture packet from ace to some other host (but not to vs). Yet second example won’t capture this packet.

Repeating qualifiersBACK TO TOC

To conclude this article, I would like to tell you one more thing that may become handy when writing complex tcpdump filter expressions.

Take a look at the following example.

# tcpdump -XX greater 100 and \(src host google.com or microsoft.com\)

We already saw this example, with one little exception. In previous example we had a src host qualifier before microsoft.com and now its gone. The thing is that if we want to use same qualifier two times in a row, we don’t have to specify it twice. Instead we can just write qualifier’s parameter and tcpdump will know what to do.

This makes tcpdump filter expression language much easier to understand and much more readable.

AfterwordBACK TO TOC

I hope you found this article useful. In case you have questions, suggestions or you would like to share your appreciation to the author ;-) , don’t hesitate to mail me to alexander.sandler@gmail.com

Did you know that you can receive periodical updates with the latest articles that I write right into your email box? Alternatively, you subscribe to the RSS feed!

Want to know how? Check out
Subscribe page

156 Comments

  1. No I didn’t :-) However I think I may do it in the future. In any case, please visit my web-site again :-)

  2. Mohit Singh says:

    Hi Alex!

    I am coordinator of GLUG-Meerut, India.

    This is excellent tutorial for newbies. A slight addition can be the actual outputs obtained by these commands, you can show only one or two lines of output only.

    This will be very useful for your readers and they’ll better appreciate the usage of tcpdump.

    Regards,
    MS

  3. @Mohit Singh
    Hi Mohit. Thanks for visiting.
    I’ll add output lines as you asked, but it will take some time. In any case please visit my web-site again :-)

  4. KT says:

    Hi Alex,

    An excellent session for newbies. I’ve bookmarked the site for reference and surely will help my soon debugging issue coming up.

    Thank you for your works.

  5. @KT
    You are most welcome. Thanks for a warm comment and for visiting. Please visit again and bring all your friends along ;-)

  6. raja says:

    Is there a way to capture all oracle sql traffic using tcpdump ? to see what is going on between the server and the oracle server.

  7. @raja
    I assume communication between the two goes over multiple ports. I think capturing everything and then filtering out unnecessary stuff with wireshark, should do the job for you.

  8. Billa says:

    Hi Alexander,

    Great tutorial :)

  9. Cliff Trueman says:

    I love the article; best way to learn Linux is by example.

  10. Destillat KW25 | duetsch.info - GNU/Linux, Open Source, Softwareentwicklung, Selbstmanagement, Vim ... says:

    […] tcpdump for Dummies […]

  11. Trinidad says:

    Fantastic post! Thanks.

  12. Arun says:

    Hi

    Great Work and Great help!

    Please clear some doubts and i am newbie.

    1.tcpdump is packet sniffer (wireshark) or filter (iptables).
    2. meaning for two options – not port 22 and -s 0
    3. whether its possible to reader the content of the packets in tcpdump , wireshark its possible.

    please help me out in this . thanks in advance

    Regards
    Arun

  13. @Arun
    1. It is a packet sniffer.
    2. not port 22 will filter OUT all connections on port 22 (SSH).
    -s 0 used when capturing packets. It tells tcpdump to write entire packet contents and not first 60 bytes as it does by default.
    3. tcpdump provides some basic abilities to view the traffic. If you want to see details, capture into file (-s0 -w ) and then open in wireshark.

    Hope it helps.

  14. Johnny says:

    Hi Alex,
    I’m interested in the statistics of the packets captured by tcpdump e.g. the delays, average lengths, through-puts, number of packets loss… Can I do it with tcpdump?
    Thanks a lot for the excellent tutorial.

  15. @Johnny
    Yes you can do it. tcpdump can produce timestamps (-t command line switch) telling when every packet has arrived. But tcpdump itself is not very useful when observing packets, so I suggest you to capture into a file and then review with wireshark – wireshark shows both timestamp and delta between packets.

  16. Sanyam Kamat says:

    tcpdump is a packet sniffer….
    is there a way to make it sniff only HTTP packets???
    and does it do any packet reconstruction???

  17. @Sanyam Kamat
    1. Yes. You can capture port 80.
    2. By packet reconstruction you mean constructing stream of data from individual packets, right? If so, then no, tcpdump can’t do that. What you can do is to capture using tcpdump and then “reconstruct” with wireshark.

  18. Sanyam Kamat says:

    @Alexander Sandler – thanks for replyin … act i wantd to know abt Packet reassembly…lik after capturin the packets how can we reassemble them…and if yes where is the actual code for it…

  19. raisa says:

    @Alexander Sandler – does tcpdump support packet reassembly?? If yes, then where can i find the code to do the same…

  20. @raisa
    @Sanyam Kamat
    tcpdump cannot reassemble packets. wireshark can. So capture with tcpdump and then week capture file into wireshark.

  21. Sanyam Kamat says:

    @Alexander Sandler – thanks for ur reply…we used wireshark to reassemble the packs..
    wat r ur thoughts on dsniff, libnids and libnets?

  22. @Sanyam Kamat
    Sorry, but I am afraid I am not familiar with these tools. Will study them though ;-)

  23. Vijay says:

    Hey alex, thanks for the great document! I was wondering if you have similar document on tethereal ?

  24. @Vijay
    Thanks for the comment. Sorry, but nothing for tethereal. But come again anyway – there’s other interesting stuff :-)

  25. Bernie says:

    Hi Alex, is it possible only to grab the “length” field from the tcpdump output?

    I become:
    00:05:5d:6d:a7:40 > 00:19:dc:e4:bc:7e, ethertype IPv4 (0x0800), length 273: 74.125.43.104.80 > 192.168.0.139.60519: P 8239:8446(207) ack 794 win 114

    but only need:
    length 273 – or something similar

    Now I do the job with cut and sed commands – but it’s a bit slow.
    Sorry for my bad english :-)

  26. @Bernie
    Unfortunately, tcpdump itself cannot do it. I’d recommend you to use tools like sed and bash, but since you say you already use them and they are slow for you, I think you should move to the next step, that is writing either perl or python script that does the job.
    I don’t know perl so I can’t tell you how to do it. Python on the other hand, is rather simple – you can use popen2 module to read tcpdump’s output and then you can parse it and output fields that you need.

  27. […] caused certain networking related problem. It is an excellent tool to learn new things. Referensi: TCP Dump For Dummies Contoh-contoh pemakaian tcpdump mulai dari yang simple sampai advanced ada di referensi atas. […]

  28. This article is great.
    I write advanced tcpdump tutorial:
    http://awarmanf.wordpress.com/2010/04/29/tcpdump-dan-wireshark-untuk-sniffing-network/
    In first alinea of my writing, I quotes your words and I refer the readers to start reading from this site.
    Have a look to my blog, unfortunately it is in bahasa indonesia.
    Sincerely.

  29. Raffy Arnaez says:

    great!

    the tcpdump filters are important to identify problems between tcp handshake, sync/ack and session-status

    Thanks!

  30. Arjun Reddy says:

    Hey Alex,
    Excellent post. My question is:

    when you get the report from wireshark and with tcpdump from the same machine, will they be the same? If not, what is misisng in tcpdump compared to wireshark and vice-versa?

  31. Patrick says:

    Hi Alex, if I only want to capture src, dst, and proto, but do not want to limit to a specific src, dst, and proto, should this work? tcpdump -n -i eth1 src host dst host dst port

  32. @Patrick
    I am not sure what you mean. When you capture traffic, you always capture source host/port and destination host/port – this is part of packet headers and capture them all.

  33. Cho says:

    Hi Alex,

    Thanks a lot for all the information provided in this site.

    I am currently working on a project that requires me to capture and store packet details in file and later perform analysis.I would like to use .net platform for d same.Could you advice me on whether i could use tcpdump or WinPcap??

    Thanks in advance:)
    Regards

  34. Maycon Belfort says:

    Hello, I need to capture the contents of files that are printed on the network. Does anyone have any idea how I do it? help me please!

    I thank you!

  35. @Cho
    I am afraid I have no idea how you can capture packets in .NET. Otherwise, winpcap is indeed the way to go.

  36. @Maycon Belfort
    I wish you were more specific about your needs. In general wireshark is what you need. However, how to use it, really depends on your situation.

  37. Maycon says:

    @Alexander Sandler – First, thanks for listening.
    Well what I want is to manage the contents of the files that users of the network to send print, preventing them from making use of company resources to print things unnecessary. If you can help me, I’m grateful.

  38. @Maycon
    Hmm… I think I can give you a direction that you can take further. First you will need a machine that captures everything that goes to printer.

    You will have to direct the traffic from printer to the machine. There are bunch of options how you can do that. For instance if your router supports port mirroring, I’d mirror printer port to the capturing machine. Another option is to use machine with two nics, bridge the nics together. The bridge will make the machine transparent and everything that is directed to the printer will go through.

    Capturing is a simple bit. In Linux you can use tcpdump. In windows wireshark will do the capturing.
    Next you have to convert TCP streams to actual files. On both Linux and Windows wireshark is what you need. To be honest I don’t know how exactly to do that with printer. There’s a chance that wireshark already knows how to do that. Otherwise try to google for it.

    Good luck.

  39. VS says:

    Hello Alexander,

    Thanks for writing such a helpful blog, very informative. I had a question which I wanted to discuss. Here it goes-

    I am capturing https network packets using tcpdump and dumping into a pcap file. I want to access and analyze the stored packet data later and do the following things-
    a)Enumerate all the IP addresses which are interacting with each other.
    b) For how long each of them is interacting.

    Both the things could be figured out using simple regular expressions which could be applied in any of the high-level language like Python or C. But the problem is I am unable to understand how to read this pcap file using any of these languages? Could libpcap help in this regard?

    Please give your suggestions.

    Kind Regards
    VS

  40. Uri London says:

    Thanks for this useful article.
    I found that the binary output of tcpdump contains text which suffices for my purposes. Thus I don’t need wireshark.

    I use it to find the direct links of those radio streams which make use of the annoying hide-and-seek windows encapsulation:
    after running tcpdump … -s 0 -w output
    I do for e.g
    strings output | grep asx

  41. charles says:

    this article is very useful and interresting, i have a query, just want to trace ARP packets using tcpdump, actually, i have a machine with eth0 and eth1 interfaces, and every one hour i have this situation:
    eth0 is down and eth1 up

    after another hour

    eth1 is down and th0 up

    i guess this is caused by an ARP time out thus i want to see this time out by using the tcpdump, could sommbody help me and describe how this could be done.

  42. isaac says:

    @charles

    you could try “tcpdump -i eth0 arp” which will print out arps on eth0 as long as eth0 is up. as soon as eth0 is down, tcpdump will exit.

  43. @VS
    Yes, you can do it with libpcap. There must be a good libpcap python binding, although I never used libpcap in python myself, so I hardly can recommend you one.

  44. @charles
    I never heart that ARP can somehow cause an interface to go down. It is some process or service in the system bringing the interface down. Try to see what process this is (see logs, add prints in scripts that bring interfaces down, etc).

  45. Pragya says:

    hi, i was analysing the output of the tcpdump command.
    For eg:
    16:45:49.494077 IP 192.168.1.2.46097 > 75.101.153.231.80: tcp 0
    16:45:49.723182 IP 192.168.1.2.46098 > 75.101.153.231.80: tcp 0
    16:45:49.836979 IP 75.101.153.231.80 > 192.168.1.2.46097: tcp 0
    16:45:49.837062 IP 192.168.1.2.46097 > 75.101.153.231.80: tcp 0
    16:45:49.837767 IP 192.168.1.2.46097 > 75.101.153.231.80: tcp 482
    16:45:50.062293 IP 75.101.153.231.80 > 192.168.1.2.46098: tcp 0
    16:45:50.062343 IP 192.168.1.2.46098 > 75.101.153.231.80: tcp 0
    16:45:50.182085 IP 75.101.153.231.80 > 192.168.1.2.46097: tcp 0
    16:45:50.184581 IP 75.101.153.231.80 > 192.168.1.2.46097: tcp 231
    16:45:50.184612 IP 192.168.1.2.46097 > 75.101.153.231.80: tcp 0
    16:45:50.185293 IP 75.101.153.231.80 > 192.168.1.2.46097: tcp 0

    Sometimes, its written tcp 0 and sometimes tcp 52(or some other length). What does this value signify??
    Also, I had a doubt about port numbers. The port for http is 80. So, all other IP addresses receive and send data through port 80, but my computer(192.168.1.2) receives data on random ports like 46097, 46098 etc. Isn’t my computer supposed to use only port 80. And if it uses random ports to receive ports to receive data then how does the computer identify that the data is an http one??

    Thanks,
    Pragya

    • Well, numbers that you see are indeed packet lengths. These numbers are in bytes.
      As for your second question, you have to understand that you need two ports to form a connection. One port number representing server side, is 80. Other port number, representing local side, is an arbitrary number from 1024 to 65,536.

  46. sumeet inani says:

    What a nice explanation. It is fascinating to see all headers of ethernet packet.
    $sudo tcpdump -i eth0 arp
    gives

    14:27:55.340818 ARP, Request who-has 192.168.8.92 tell 192.168.8.121, length 46

    None of IP address is mine. I am on LAN. Does this mean that every node in network sends broadcast message instead of LAN server routing packet directly to appropriate IP.

  47. @sumeet inani
    Well, it depends on many different things. For instance, ARP frames are often being broadcasted across the LAN. You may receive packets that were sent to some other computer if your machine and that other computer plugged into same bridge.

Leave a Reply

Prove you are not a computer or die *