Linux tcp_tw_reuse = 2 — how is this set and what is the significance?

Hello,

While troubleshooting a connectivity issue across VPN and NAT, I decided to check some TCP settings and came across this:

root@vyos:~# cat /proc/sys/net/ipv4/tcp_tw_reuse
2

It’s possible that this is completely unrelated, but I would like to understand what this means. Does anyone know how and why this is set? I don’t see it /etc/sysclt.conf.

When checking Linux’s TCP manual, I see:

tcp_tw_reuse (Boolean; default: disabled; since Linux 2.4.19/2.6)

Allow to reuse TIME_WAIT sockets for new connections when it is safe from protocol viewpoint. It should not be changed without advice/request of technical experts.

And I believe boolean means 0 or 1, which leaves me wondering what “2” does.

If anyone has any insight on this, it would be very helpful.

Thanks in advance.

Link to the commit here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=79e9fed460385a3d8ba0b5782e9e74405cb199b1

This blog entry is very useful to understand how things work:

Thank you for this. The commit has more info than the TCP manual, which seemed to only allow for this to be boolean (1 or 0). I see that “2” applies to loopback only, which is interesting.

I thought maybe VyOS was setting this somewhere in runtime, since it was absent from sysctl.conf, but now I see in the diff that “2” is the default:

index 924bd51327b7..6841c74eac00 100644
--- a/[Documentation/networking/ip-sysctl.txt](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/ip-sysctl.txt?id=39dbc646fd2c67ee9b71450ce172cbd714d4e7fb)
+++ b/[Documentation/networking/ip-sysctl.txt](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/ip-sysctl.txt?id=79e9fed460385a3d8ba0b5782e9e74405cb199b1)
@@ -667,11 +667,15 @@ tcp_tso_win_divisor - INTEGER
building larger TSO frames.
Default: 3
-tcp_tw_reuse - BOOLEAN
- Allow to reuse TIME-WAIT sockets for new connections when it is
- safe from protocol viewpoint. Default value is 0.
+tcp_tw_reuse - INTEGER
+ Enable reuse of TIME-WAIT sockets for new connections when it is
+ safe from protocol viewpoint.
+ 0 - disable
+ 1 - global enable
+ 2 - enable for loopback traffic only
It should not be changed without advice/request of technical
experts.
+ Default: 2```

Much appreciated!

This doesn’t really talk about setting tcp_tw_reuse = 2 (which now I know is “loopback only”), but it looks like nice writeup for explaining the general idea of reusing TW sockets (tcp_tw_reuse =1 vs. tcp_tw_reuse = 0). Thanks for your reply!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.