1. Overview

TCP (Transmission Control Protocol) ensures the reliability and transfer of data between the sender and the receiver. However, in some cases, the connection between two devices can become broken, resulting in a “timeout” error. In Linux, TCP timeouts are used to set an estimated time the system should wait for a response from the receiver before the connection is broken. Timeouts, if not set, default to 60 seconds.

In this tutorial, we go over the steps to check for TCP timeouts in Linux. Before we begin, it’s important to note that the specific steps may vary depending on our Linux version and the distribution you have installed.

2. What Is a TCP Timeout?

A TCP timeout in Linux refers to the time a system waits for a response to be acknowledged before the connection is terminated.

The TCP keepalive timeout prevents broken connections from being left open indefinitely. The default timeout value can be adjusted in the Linux kernel configuration.

3. How to Check TCP Timeouts

We can check TCP timeouts using the network tools as highlighted earlier or using file definitions by changing the value in the keep_alive_time. Let’s look at these options and more in extra detail.

Firstly, check the set timeout value.

The fastest way to get the timeout value is to use the current system timeout stored in the /proc/sys/net/ipv4/tcp_keepalive_time file. To check the value, we can open a terminal window and run the following command:

$ cat /proc/sys/net/ipv4/tcp_keepalive_time

This returns the number of seconds the operating system will wait for data to be acknowledged before closing the connection.

Secondly, we need to check the keepalive setting.

This controls the number of keepalive probes sent before the connection is closed. To check the value, we can run the following command:

$ cat /proc/sys/net/ipv4/tcp_keepalive_probes

The above command returns the number of keepalive probes sent before the connection is closed.

The interval between keepalive probes is also an important setting to check. This setting controls the amount of time between each keepalive probe. To check the value, we should run the following:

$ cat /proc/sys/net/ipv4/tcp_keepalive_intvl

This returns the amount of time in seconds between each keepalive probe.

4. Modifying the TCP keepalive

The TCP timeout value can be adjusted in Linux by modifying the relevant kernel parameters. There are several methods for adjusting TCP timeouts, including using the sysctl command and editing the relevant configuration files:

sysctl -w net.ipv4.tcp_keepalive_time=value

We can replace the value with the desired timeout value in seconds. This change will only persist until the next reboot. To make the change permanent, we can add the following line to the /etc/sysctl.conf file:


Finally, we apply the changes by running the following command:

$ sudo sysctl -p

It ensures all the changes get saved in the system for future use when handling other TCP connections.

5. Conclusion

In this tutorial, we looked at different ways to check for TCP timeouts in Linux using various system files. Understanding the duration of active connections and verifying the default timeout value can help us identify and resolve timeout issues in our network.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.