Octet

What are the TCP flags and when is each one set?

Show the answer

Say this first

There are eight in common use. SYN opens a connection and carries the initial sequence number. ACK says the acknowledgment field is valid and is set on every segment after the first SYN. FIN closes one direction gracefully. RST aborts the connection immediately. PSH asks the receiver to hand data to the application without waiting. URG marks urgent data and is almost unused. ECE and CWR carry explicit congestion notification signals.

Go deeper

What each flag means

FlagtcpdumpMeaning
SYNSSynchronize sequence numbers. Consumes one sequence number.
ACK.Acknowledgment number is valid
FINFNo more data from this side. Consumes one sequence number.
RSTRAbort. No ACK is expected and the receiver drops the connection state.
PSHPPush buffered data up to the application now
URGUUrgent pointer is valid
ECEEECN echo: a packet was marked CE (or, in a SYN, "I support ECN")
CWRWCongestion window reduced: sender has reacted to ECE

Common combinations in a capture

  • [S] client SYN, [S.] SYN-ACK, [.] pure ACK.
  • [P.] data with ACK, the normal data segment.
  • [F.] FIN with ACK, a graceful close.
  • [R] or [R.] reset. [R.] in reply to a SYN means the port is closed.

Capturing only control segments

Shell
tcpdump -ni eth0 'tcp[tcpflags] & (tcp-syn|tcp-fin|tcp-rst) != 0'

Traps

  • Saying PSH is required for data to be delivered. Receivers deliver data without it. It is a hint.
  • Thinking a RST gets acknowledged. It does not; the receiver validates it and tears the connection down.
How did you do?Book 5.2 Reliable Byte Stream (TCP)