TCP keepalive is an optional mechanism in which the operating system sends small probe segments on an otherwise idle connection. If the peer answers, the connection is alive. If several probes go unanswered, the connection is closed and the application gets an error.
Why it matters
Without traffic, a half-dead connection can stay open for hours, for example after a client lost power or a NAT entry expired. Keepalive detects that and frees resources. It also keeps firewall and NAT state alive, since those devices drop idle mappings after a time. It is not the same as HTTP keep-alive, which is about reusing a connection for further requests.
Example
Linux defaults are conservative, so probing starts after two hours of idleness. Tune them per system:
sysctl net.ipv4.tcp_keepalive_time # idle seconds before first probe
sysctl net.ipv4.tcp_keepalive_intvl # seconds between probes
sysctl net.ipv4.tcp_keepalive_probes # failed probes before closing
Applications must enable it on the socket (SO_KEEPALIVE) and can often override the timing. Check your platform's documentation, because defaults differ.
Common mistakes
- Expecting keepalive to work when the application never enabled it on the socket.
- Using the 2-hour default behind a cloud gateway that drops idle flows after a few minutes.
- Confusing it with HTTP keep-alive.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.