Skip to main content
IT BIBLESign in

Blog

Reading a Failed TCP Connection in a Packet Capture

A connection that fails does so in one of three ways, and tcpdump shows which one in about ten lines. Here is how to read the handshake and know which box to look at next.

RackGhostDwayne
· 6 min read

When a connection fails, the capture will tell you which of three things happened. You only have to know what each one looks like.

I see people jump to the firewall logs, or to a reboot, before they have looked at a single packet. The logs show what a box decided. The capture shows what actually crossed the wire. When the two disagree, I trust the wire.

The command

Start small. Capture on the client, filter to one host and one port, and turn off name lookups so the output does not stall on DNS:

sudo tcpdump -ni eth0 'host 192.168.20.50 and tcp port 443'

The -n matters more than it looks. A capture that pauses to resolve names makes a clean timeline hard to read, and if DNS is part of your problem you have just added a second problem.

Now try to connect from another terminal, with curl or nc. The flags in square brackets are what you read:

  • [S] is a SYN, the client asking to open a connection.
  • [S.] is a SYN-ACK, the server agreeing.
  • [.] is a plain ACK.
  • [R] or [R.] is a reset, the connection refused or torn down.
  • [P.] is data being pushed, with an ACK riding along.

A healthy handshake is three lines. SYN out, SYN-ACK back, ACK out. After that, data. Everything else is a variation on a failure of those three lines.

Story one: the SYN goes out and nothing comes back

This is what it looks like. The addresses and timestamps are illustrative:

10:02:11.100 IP 192.168.10.5.51514 > 192.168.20.50.443: Flags [S], seq 1001, length 0
10:02:12.103 IP 192.168.10.5.51514 > 192.168.20.50.443: Flags [S], seq 1001, length 0
10:02:14.107 IP 192.168.10.5.51514 > 192.168.20.50.443: Flags [S], seq 1001, length 0

Same sequence number, spaced about one second, then two, then four. That is the client retransmitting the same SYN with a doubling timer. Nobody is answering.

Silence means the packet was dropped somewhere, or it never arrived, or the answer never made it back. It does not say who dropped it. A firewall rule with a drop action looks like this. So does a missing route, a dead cable, a wrong VLAN on a switch port, or a host that is simply off.

So the next step is to move the capture. Run the same filter on the far end, or on the firewall interface closest to the destination. If the SYN shows up there, the problem is the destination host or its own firewall. If it does not, the packet died in between, and you bisect the path the way you would bisect a bad cable run: test the midpoint, then half of what is left.

And yes, check the physical layer before you start bisecting. Look at the link light and the port counters. I have spent a good while on a firewall rule that was fine and a patch cord that was not.

Story two: the SYN goes out and a reset comes back

10:05:40.220 IP 192.168.10.5.51600 > 192.168.20.50.443: Flags [S], seq 2002, length 0
10:05:40.221 IP 192.168.20.50.443 > 192.168.10.5.51600: Flags [R.], seq 0, ack 2003, length 0

This is a fast, definite answer, and it is good news in a grim sort of way. The packet reached something, and that something said no. Think of knocking on a door and hearing someone say there is nobody here by that name. The building exists, the hallway is fine, and the apartment is wrong.

Typically it means the host is up but nothing is listening on that port. The service is stopped, or bound to 127.0.0.1 only, or listening on a different port than you assumed. On the server, ss -ltn shows what is bound and to which address. A firewall set to reject, not drop, also produces a reset or an ICMP unreachable message, so check for that before you blame the service. If you see an ICMP "admin prohibited" reply instead of a reset, a firewall is answering on purpose.

Notice the time as well. A reset arriving a millisecond later tells you the path is short and healthy. You have just ruled out most of the network without touching a config.

Story three: the handshake completes and then it stalls

10:09:02.500 IP 192.168.10.5.51700 > 192.168.20.50.443: Flags [S], seq 3003, length 0
10:09:02.512 IP 192.168.20.50.443 > 192.168.10.5.51700: Flags [S.], seq 9009, ack 3004, length 0
10:09:02.512 IP 192.168.10.5.51700 > 192.168.20.50.443: Flags [.], ack 9010, length 0
10:09:02.530 IP 192.168.10.5.51700 > 192.168.20.50.443: Flags [P.], seq 1:518, ack 1, length 517
10:09:03.560 IP 192.168.10.5.51700 > 192.168.20.50.443: Flags [P.], seq 1:518, ack 1, length 517

The three-way handshake worked, so the path works in both directions at least for small packets. Then the client sends its first data and keeps resending it. The server's reply is not getting back, or the data is not getting there.

Two causes account for most of what I have seen. The first is asymmetric routing, where the reply takes a different path and a stateful firewall on that path has never seen the SYN, so it discards the reply. The second is MTU. Small packets pass, full-size ones vanish, and the ICMP message that should tell the sender to shrink them gets filtered along the way. The tell is that pings work and big transfers hang. On a tunnel, I check the MTU first.

To test it, send full-size packets with fragmentation forbidden and shrink them until they pass:

ping -M do -s 1472 192.168.20.50

That is 1472 bytes of payload plus 28 bytes of headers, which fills a 1500 byte link. Lower the number until replies come back and you have found the real limit.

Two ways a capture misleads you

Where you capture matters. A capture on the client shows what the client sent, not what arrived. If you only look at one point, you only know about one point. For anything that crosses a firewall, I want captures on both of its interfaces, and I write down the times.

The other trap is checksums. On a host with checksum offload, tcpdump can show outgoing packets with a bad checksum, because the network card fills it in after the capture point. It looks alarming and is usually harmless. If the far end receives and answers those packets, you have your answer. I would not chase it unless the other side stays silent.

For anything longer than a few lines, write the capture to a file and open it in Wireshark on your desk:

sudo tcpdump -ni eth0 -w /tmp/fail.pcap 'host 192.168.20.50'

Wireshark flags retransmissions and resets for you, but you should be able to do the reading by eye first. The tool is faster, and the eye is what you have when you are on a console at a customer site with nothing else installed.

Try it

On a network you own, pick a service you can start and stop. Connect while it is running and save the three-line handshake. Stop it and connect again, and you will see the reset. Then add a drop rule on a firewall in front of it and watch the SYN retransmit with nothing coming back. Three tests, ten minutes, and you will know the three stories on sight. Write each one in the binder next to the command that produced it.

That is where I would start, and I would start with the cable.

Dwayne

networkingtcpdumptroubleshooting
Share

Have a question about this guide?

Create a free account to ask the community and join the discussion. Members who run the real thing answer every day.