tcp_fin_timeout doesn’t control TIME_WAIT

Doing some tcp tuning and noticed a ton of TIME_WAIT connections.  Many online guides suggested setting /proc/sys/net/ipv4/tcp_fin_timeout to 15 but netstat with timers was still counting down from 60:

Proto Recv-Q Send-Q Local Address               Foreign Address             State       Timer
tcp        0      0 localhost.locald:cslistener localhost.localdomain:53113 TIME_WAIT   timewait (57.46/0/0)
tcp        0      0 TIME_WAIT   timewait (57.55/0/0)

Turns out you can’t lower TIME_WAIT on linux from 60 seconds since it’s hard coded in the source:

#include /net/tcp.h
#define TCP_TIMEWAIT_LEN (60*HZ) /* how long to wait to destroy TIME-WAIT

The temp workaround is to enable tcp_tw_recycle or better, tcp_tw_reuse.

BTW, BSD doesn’t do this and does use TCP_TIMEWAIT_LEN.