Read a packet capture with tcpdump
Read packet captures with tcpdump -r and tell three failures apart: a DNS name that doesn’t exist, a refused connection and packets dropped by a firewall.
When the logs disagree and everyone says "it works on my machine", a packet capture settles it: it's a record of what actually went over the wire. On a real server you'd make one with sudo tcpdump -i eth0 -w capture.pcap port 443 while the problem happens. Here someone already has: ~/captures holds four. (They're pretend captures, made for this page.)
One line of tcpdump
tcpdump -nr captures/good.pcap-r reads a file and -n shows numbers instead of names. Each line is one packet:
08:41:07.020000 IP 10.0.0.5.51516 > 203.0.113.80.80: Flags [S], seq 1000, ... time who.port > who.port: what
The last number in each address is the port. Your laptop (10.0.0.5) uses a random high port; the server's is 80 for http, 443 for https, 53 for DNS.
The flags
| Flags | Means |
|---|---|
[S] | SYN: "can we talk?" |
[S.] | SYN-ACK: "yes" |
[.] | ACK: "got it" |
[P.] | data (PUSH) |
[F.] | FIN: "I'm done" |
[R.] | RESET: "no", or "go away" |
A good connection starts with [S], [S.], [.], the three-way handshake, then data. In good.pcap you can also see the DNS question before it (A? example.com.) and its answer.
What failure looks like
- No answer at all: the same
[S]goes out again and again, a second apart, then 2, 4, 8. Nothing comes back. Something dropped it. - A refusal:
[S]goes out and[R.]comes straight back. The machine is there; nothing listens on that port. - DNS: the question goes out and the answer says
NXDomain: no such name. No connection is even tried.
Filters
Add a filter after the file to see only some packets: port 443, host 10.0.0.1, tcp, udp, joined with and, or and not. -c 5 stops after five packets, and -A prints what's inside them as text, which shows HTTP requests and answers:
tcpdump -nr captures/good.pcap -A port 80Your turn
The checkout failed on Monday, Tuesday and Wednesday, each time for a different reason. Read each capture with tcpdump -r and move it into the folder for its cause: captures/dns, captures/refused or captures/dropped.
Your task
The checkout failed on Monday, Tuesday and Wednesday, each time for a different reason. Read each capture with tcpdump -r and move it into the folder for its cause: captures/dns, captures/refused or captures/dropped.
- Read all three captures (not done yet)
- The dropped one is in dropped/ (not done yet)
- The refused one is in refused/ (not done yet)
- The DNS one is in dns/ (not done yet)
The checklist ticks itself off as you work in the terminal: any way that gets the result counts.
Hints come one at a time, then one way to do it. Try each before the next.
What this lesson uses, in one place.
tcpdump -r- Read a capture file
tcpdump -n- Numbers, not names
tcpdump -A- Show the contents as text
Every everyday command on one page: the Linux commands cheat sheet.