I have a port that is blocked by a process I needed to kill. (a little telnet daemon that crashed). The process was killed successfully but the port is still in a 'FIN_WAIT1' state. It doesn't come out of it, the timeout for that seems to be set to 'a decade'.
The only way I've found to free the port is to reboot the entire machine, which is ofcourse something I do not want to do.
$ netstat -tulnap | grep FIN_WAIT1
tcp 0 13937 10.0.0.153:4000 10.0.2.46:2572 FIN_WAIT1 -
Does anyone know how I can get this port unblocked without rebooting?
You should be able to set the timeout with
/proc/sys/net/ipv4/tcp_fin_timeout
.There really doesn't seem to be any way to clear the socket manually.
It seems that tcp_orphan_retries setting controls how many attempts will be done before a server-less port is released. It was 0 here, after setting it to 1 the ports were gone.
HTH
/proc/sys/net/ipv4/tcp_fin_timeout
is the timeout of the FIN-WAIT-2 state, not FIN-WAIT-1. You should go with the tcpkill route or you can try to play with the keepalive times under/proc/sys/net/ipv4/tcp_keepalive_*
to force a kill by the SO.Running these steps under root ID and it cleared for me:
Capture the kernel setting to change in a variable
Temporarily set the max orphans to 0
Check to make sure that problematic port is no longer in use
Wait a bit and repeat above step if needed until above command returns no lines
Reset the tcp_max_orphans kernel parameter back to the original value from the variable above
You application has closed its side of the connection, the socket is now waiting for the remote side to confirm that close. If you have a problem with a lot of those sockets being held in FIN_WAIT1 then you should follow Manni's advice above.
On linux kernel >= 4.9 you can use the
ss
command from iproute2 with key -Kss -K dst 192.168.1.214 dport = 49029 the kernel have to be compiled with CONFIG_INET_DIAG_DESTROY option enabled.
via https://unix.stackexchange.com/a/511691/43898
Maybe tcpkill would help? More here: http://www.cyberciti.biz/howto/question/linux/kill-tcp-connection-using-linux-netstat.php
this may help: