≡ Menu

Linux increasing or decreasing TCP sockets timeouts

Some time it is necessary to increase or decrease timeouts on TCP sockets. You can use /proc/sys/net/ipv4/tcp_keepalive_time to setup new value.

The number of seconds a connection needs to be idle before TCP begins sending out keep-alive probes. Keep-alives are only sent when the SO_KEEPALIVE socket option is enabled. The default value is 7200 seconds (2 hours).

For example set value to 2400 seconds:

echo 2400 > /proc/sys/net/ipv4/tcp_keepalive_time

You can make changes to /proc filesystem permanently using /etc/sysctl.conf

Further reading

  • See man page of ip(7) and tcp(7) for more details.
  • Securing and Optimizing Linux book (by OpenNA), network optimization chapter
Share this on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 2 comments… add one }
  • KryDos January 29, 2015, 7:48 am

    Thank you for this note.

    But I still have a question
    tcp_keepalive_time means that socket connection will be killed in 2 hours (by default) in any case or if socket connection is not active (messages are not sending)?

  • Wellington Torrejais da Silva December 31, 2015, 12:09 pm

    Thanks!

Security: Are you a robot or human?

Leave a Comment