/proc/sys/net/ipv4/tcp_keepalive_time"; 2. Edit the "/etc/sysctl.conf" file, the syntax is "net.ipv4.tcp_keepalive_time=specified value"."/> /proc/sys/net/ipv4/tcp_keepalive_time"; 2. Edit the "/etc/sysctl.conf" file, the syntax is "net.ipv4.tcp_keepalive_time=specified value".">

Home  >  Article  >  Operation and Maintenance  >  What to do if the TCP connection is not released in Linux

What to do if the TCP connection is not released in Linux

WBOY
WBOYOriginal
2022-07-13 10:53:153503browse

Solution: 1. You can quickly release the port connection by modifying the keepalive configuration to an appropriate value. Use echo to set "set tcp_keepalive_time". The syntax is "echo "specify value" > /proc/sys/ net/ipv4/tcp_keepalive_time"; 2. Edit the "/etc/sysctl.conf" file, the syntax is "net.ipv4.tcp_keepalive_time=specified value".

What to do if the TCP connection is not released in Linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What should I do if the tcp connection in Linux is not released?

Problem description

During development and testing, I found that the connection was refused when the server port was disconnected and then connected again. .

Analysis: Check the port occupancy on the server, assuming the port is 8080.

netstat -anp |grep 8080

It is found that port 8080 is occupied (the ip is the local ip and it is determined to be the last connection) and the status is ESTABLISHED. However, the connection has actually been disconnected, but the server has not disconnected. Check the TCP keepalive configuration.

sysctl -a |grep keepalive

Found to be the default configuration

net.ipv4.tcp_keepalive_time = 7200
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_intvl = 75

By default, a keepalive detection packet will be sent to confirm the connection status after the connection has been idle for 7200 seconds or 2 hours.

Solution

Solution:

1. By modifying the keepalive configuration to an appropriate value (such as changing to 200 seconds), the port connection can be quickly released .

Temporary modification, set tcp_keepalive_time through echo.

echo "200" >  /proc/sys/net/ipv4/tcp_keepalive_time

2. To take effect permanently, edit /etc/sysctl.conf, add or modify it to

net.ipv4.tcp_keepalive_time = 200

and then execute the command to make the modified configuration take effect

Recommended learning: Linux video tutorial

The above is the detailed content of What to do if the TCP connection is not released in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn