Pcornel
Networking · Network & Protocols › TCP, UDP & Transport

TCP Keepalive Evidence

Cheat sheet · https://pcornel.dk/topic.php?topic=315

Back to the Topic

Answer

TCP keepalive is an optional feature that sends a small probe on an idle connection at intervals, to check that the other end still answers. It is off unless the application enables it.

Remember

The default idle time before the first probe is two hours — far longer than the idle timeout of most firewalls and NAT devices. For a keepalive to hold such a device's state, its interval must be shorter than that timeout. Probes are answered by the operating system, so they do not show that the application is alive.

First checks

  • sysctl net.ipv4.tcp_keepalive_time net.ipv4.tcp_keepalive_intvl net.ipv4.tcp_keepalive_probes — host defaults.
  • ss -to state established — a timer:(keepalive,…) entry shows it is active on a connection.
  • tcpdump on the idle connection — probes and their answers.
  • The idle timeouts of every firewall, NAT device and load balancer on the path.

Commands

ss -to

Verify in this order

application enables keepalive → idle time shorter than the shortest timeout on the path → probe sent on an idle connection → acknowledged by the peer → middlebox state refreshed → connection usable when next needed

Where it usually breaks

physical/link dependency → local object state → peer/control state → policy → forwarding/adjacency → end-to-end result

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=315

Confirmation

Confirm action

Continue?