如何在Linux上查看/更改套接字连接超时? [英] How to view/change socket connection timeout on Linux?
问题描述
在Java中创建套接字时:
When creating a Socket in Java:
new Socket(host, port);
Socket构造函数将在返回之前尝试连接到 host:port .在Windows上,对于无法访问的主机,此操作几乎立即失败,但对于Linux,套接字可能需要5分钟的超时时间.
The Socket constructor will try to connect to host:port before returning. On Windows, this fails almost immediately for unreachable hosts but for Linux it can take up to 5 minutes for the Socket to timeout.
我知道,如果我可以控制创建套接字,则可以:
I'm aware that if I have control over creating the Sockets, I can do:
Socket s = new Socket();
s.bind(..);
s.connect(.., timeout);
,但我希望操作系统使用合理的默认值.有没有办法在Linux上更改此设置?
but I'd rather have the OS use a reasonable default value. Is there a way to change this setting on Linux?
谢谢
推荐答案
我认为您要/proc/sys/net/ipv4/tcp_syn_retries
.默认值通常为5或6,大约需要3分钟.
I think you want /proc/sys/net/ipv4/tcp_syn_retries
. The default is usually 5 or 6 which comes out to around 3 minutes.
请注意,这些是系统范围的.
Note that these are system-wide.
这篇关于如何在Linux上查看/更改套接字连接超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!