In Linux, TCP keepalive parameters are:
tcp_keepalive_intvl
tcp_keepalive_probes
tcp_keepalive_timeTheir default values are:
tcp_keepalive_time = 7200 (seconds)
tcp_keepalive_intvl = 75 (seconds)
tcp_keepalive_probes = 9 (number of probes)
This means that the keepalive process waits for two hours (7200 secs) for socket activity before sending the first keepalive probe, and then resend it every 75 seconds. If no ACK response is received for nine consecutive times, the connection is marked as broken.
For example, to reduce the value of /proc/sys/net/ipv4/tcp_keepalive_time from 7,200 (2 hours) to 900 (15 Min) we can use the command:
echo 900> /proc/sys/net/ipv4/tcp_keepalive_time On many flavors of Linux, the tool to manipulate TCP Keepalive setting is
sysctl.
Example:sysctl -w net.ipv4.tcp_keepalive_time=300
The above two methods of changing TCP Keepalive are
temporary and will only last until the system is rebooted.
A more
permanent change to TCP Keepalive will require a change to the
/etc/sysctl.conf file.
Example:
To make a permanent change to decrease TCP Keepalive time before testing to 300 seconds (5 minutes), edit /etc/sysctl.conf file and add:
net.ipv4.tcp_keepalive_time=300
Note: Changing TCP keepalive parameters in Linux will require root user permissions