{"id":13638,"date":"2023-04-12T06:54:35","date_gmt":"2023-04-12T06:54:35","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=13638"},"modified":"2023-04-28T09:46:27","modified_gmt":"2023-04-28T09:46:27","slug":"how-to-configure-tcp-keepalive-settings-on-linux-centos-rhel-fedora","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-configure-tcp-keepalive-settings-on-linux-centos-rhel-fedora\/","title":{"rendered":"How to Configure TCP keepalive Settings on Linux (CentOS, RHEL, Fedora)"},"content":{"rendered":"<p>TCP keepalive is a mechanism used to determine if a network connection between two hosts is still active. It does this by periodically sending &#8220;keepalive&#8221; packets over the connection. If there&#8217;s no response after a certain number of attempts, the connection is considered dead and will be closed. This can help in detecting and cleaning up stale connections.<\/p>\n<p>In this short guide, we will show you how to configure TCP keepalive settings on CentOS, RHEL, and Fedora systems. By following these steps, you can fine-tune the keepalive settings to suit your specific network requirements.<\/p>\n<h2>Step 1: Examine Current TCP Keepalive Settings<\/h2>\n<p>Before modifying the TCP keepalive settings, it&#8217;s helpful to examine the current settings. To do this, run the following commands in the terminal:<\/p>\n<pre>\r\nsysctl net.ipv4.tcp_keepalive_time\r\nsysctl net.ipv4.tcp_keepalive_intvl\r\nsysctl net.ipv4.tcp_keepalive_probes\r\n<\/pre>\n<p>These commands will display the current values for the following settings:<\/p>\n<pre>\r\nnet.ipv4.tcp_keepalive_time: The time (in seconds) that a connection must be idle before the first keepalive packet is sent.\r\nnet.ipv4.tcp_keepalive_intvl: The interval (in seconds) between keepalive packets if no response is received from the remote host.\r\nnet.ipv4.tcp_keepalive_probes: The number of unacknowledged keepalive packets that must be sent before the connection is considered dead.\r\n<\/pre>\n<h2>Step 2: Modify TCP Keepalive Settings<\/h2>\n<p>To modify the TCP keepalive settings, you can use the sysctl command followed by the -w flag. Here&#8217;s an example of how to set the tcp_keepalive_time to 600 seconds:<\/p>\n<pre>\r\nsudo sysctl -w net.ipv4.tcp_keepalive_time=600\r\n<\/pre>\n<p>Similarly, you can modify the other two settings as needed. For example, to set the tcp_keepalive_intvl to 60 seconds and the tcp_keepalive_probes to 5 attempts, run:<\/p>\n<pre>\r\nsudo sysctl -w net.ipv4.tcp_keepalive_intvl=60\r\nsudo sysctl -w net.ipv4.tcp_keepalive_probes=5\r\n<\/pre>\n<p>Keep in mind that these changes will only persist until the next system reboot. To make these changes permanent, proceed to the next step.<\/p>\n<h2>Step 3: Make TCP Keepalive Settings Permanent<\/h2>\n<p>To make the TCP keepalive settings permanent, you need to add them to the \/etc\/sysctl.conf file. Open the file with a text editor, such as nano or vi:<\/p>\n<pre>\r\nsudo nano \/etc\/sysctl.conf\r\n<\/pre>\n<p>At the end of the file, add the following lines, adjusting the values to your desired settings:<\/p>\n<pre>\r\nnet.ipv4.tcp_keepalive_time = 600\r\nnet.ipv4.tcp_keepalive_intvl = 60\r\nnet.ipv4.tcp_keepalive_probes = 5\r\n<\/pre>\n<p>Save the file and exit the text editor. The changes will take effect after the next system reboot.<\/p>\n<h3>Conclusion<\/h3>\n<p>In this guide, we have demonstrated how to configure TCP keepalive settings on CentOS, RHEL, and Fedora systems. By adjusting the keepalive time, interval, and probe settings, you can optimize your system&#8217;s ability to detect and clean up stale network connections.<\/p>\n<p>Please feel free to leave comments and suggest improvements to this guide. Your feedback is valuable and helps us improve our content for our audience.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TCP keepalive is a mechanism used to determine if a network connection between two hosts is still active. It does this by periodically sending &#8220;keepalive&#8221; packets over the connection. If&#8230;<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[996],"tags":[1244,1370,1977,1713,1976],"class_list":["post-13638","post","type-post","status-publish","format-standard","hentry","category-linux","tag-centos","tag-fedora","tag-keepalive","tag-rhel","tag-tcp"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/13638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=13638"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/13638\/revisions"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=13638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=13638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=13638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}