How and where do I configure configure TCP keepalive on CentOS 7?

My attempts to find it:

[michael@devserver ~]$ cat /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
# For more information, see sysctl.conf(5) and sysctl.d(5).
[michael@devserver ~]$ cat /usr/lib/sysctl.d/* | grep keep
[michael@devserver ~]$ cat /run/sysctl.d/* | grep keep
cat: /run/sysctl.d/*: No such file or directory
[michael@devserver ~]$ cat /etc/sysctl.d/* | grep keep
[michael@devserver ~]$ cat /usr/lib/sysctl.d/* | grep keep
[michael@devserver ~]$ ls /proc/sys/net/ipv4/ | grep tcp_keep
[michael@devserver ~]$ cat /proc/sys/net/ipv4/tcp_keep*
[michael@devserver ~]$ whereis tcp_keepalive
tcp_keepalive:[michael@devserver ~]$ whereis tcp_keepalived
tcp_keepalived:[michael@devserver ~]$ whereis keepalive
keepalive:[michael@devserver ~]$ whereis keepalived
keepalived:[michael@devserver ~]$ ls /etc | grep keep
[michael@greenbeantech ~]$
  • You were on the right track with your first search: tldp.org/HOWTO/TCP-Keepalive-HOWTO/usingkeepalive.html
    – Jeff Schaller
    Jul 9, 2017 at 0:49
  • @JeffSchaller Thanks Jeff! So, it is not a daemon which I original expected, right? Is it now standard build into the kernel? I seem to be able to write a new value using the "procfs"? interface. Is there not a conf file? The rest of the document described /etc/init.d/bla which doesn't apply to Centos 7 which uses systemctl, right? Jul 9, 2017 at 1:30

1 Answer 1


The TCP Keepalive HOWTO refers to two methods for configuring TCP keepalives:

  • the procfs interface

  • the sysctl interface

As you already found, you can update the values by writing a new number to the corresponding /proc file, for example:

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

or via sysctl:

sysctl -w net.ipv4.tcp_keepalive_time=600

... although neither of those changes survive a reboot.

To make the change persist across reboots, you want to place the values in (or via) /etc/sysctl.conf. I don't have a CentOS system in front of me, but it's possible that /etc/sysctl.conf is linked to from a file in /etc/sysctl.d/.

My recommendation would be to create a file in /etc/sysctl.d/ with contents in the format:


The sysctl files are read in numeric order, so if you want your values to take precedence, heed the warning you already saw:

To override only specific settings, add a file with a lexically later name in /etc/sysctl.d/ and put new settings there.

  • Thanks Jeff. As described in my initial post, I already looked in /etc/sysctl.conf and /etc/sysctl.d/, but nothing related to keepalive. I just recently tried sudo grep -r /etc -e tcp_keepalive_time, and it returns no results. I've also tried just using part of the work (i.e. "keepalive"), but still doesn't seem to be specified in /etc/ anywhere. Jul 11, 2017 at 14:18
  • Then you have the default settings; I assumed you were looking to override them.
    – Jeff Schaller
    Jul 11, 2017 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.