Which keepalive mechanism should PuTTY prioritize for NAT traversal: TCP keepalives or application-level SSH keepalives
0 reputation · 06 Dec 2022, 07:22 UTC
0 reputation · 06 Dec 2022, 07:22 UTC
PuTTY implements two distinct keepalive mechanisms in the Connection panel. The 'Enable TCP keepalives' option sets the SO_KEEPALIVE socket option, which relies on OS-controlled timing often spanning hours. The 'Seconds between keepalives' setting sends null SSH packets at user-defined intervals measured in seconds.
TCP keepalives operate at the transport layer without consuming SSH bandwidth but may fire too infrequently to maintain NAT or stateful firewall mappings. Application-level keepalives reliably refresh network state at the cost of generating continuous background traffic. However, application-level keepalives can mask genuinely broken connections by making sessions appear alive even when the network path has failed.
The PuTTY documentation does not establish a precedence or interaction model when both options are enabled simultaneously. The unresolved decision centers on selecting the appropriate mechanism given conflicting requirements: NAT timeout constraints demand frequent state refresh while operational needs favor rapid failure detection.
There is no documented guidance on which approach to prioritize or how to configure both options for optimal behavior across different network environments.
32275 reputation · 06 Dec 2022, 16:02 UTC
When both options are enabled, PuTTY should prioritize application‑level SSH keepalives (null packets). They refresh NAT and stateful firewall mappings at the interval you set, while OS‑controlled TCP keepalives typically fire far too late to keep those mappings alive.
PuTTY treats the two mechanisms independently:
Seconds between keepalives setting sends null packets at the user‑defined interval.Enable TCP keepalives checkbox simply sets the socket SO_KEEPALIVE flag; the kernel then sends its own keepalive packets based on the OS defaults (often 2–3 hours).Seconds between keepalives to a value that is less than half of that timeout. For example, if the NAT times out after 5 minutes, use 120–150 seconds.Enable TCP keepalives checked to keep the OS‑level fallback in case the SSH keepalive is disabled or the server drops the session silently.Connection > Keepalives diagnostics to log when keepalives are sent.What is the exact NAT timeout value of the gateway between your client and the SSH server? Knowing that number lets you set the SSH keepalive interval precisely.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.