How to verify TCP keep alive on Linux

2019-08-01 05:05发布

I want to set tcp keep alive on my linux machine. So what I am doing is running a script

if [ `/sbin/sysctl -n net.ipv4.tcp_keepalive_time` != 200 ] ; then
   /sbin/sysctl -w net.ipv4.tcp_keepalive_time=200;

But I still have issues with connections to amazon's redshift. Can someone please help and show me how I can check if tcp keep alive is actually set or not?

1条回答
太酷不给撩
2楼-- · 2019-08-01 05:20

To check if keep alive is active open a connection, don't exchange any data and verify with tcpdump or similar that packets gets regularly exchanged on the connection, even if no real data get exchanged.

But maybe you just confuse keep-alive with timeout:

  • Keep alive: detect if the connection is still active, e.g. that data could be exchanged if necessary. This will detect loss of network connectivity etc. Keep alive is done on the TCP layer.
  • Timeout: connections gets closed after some inactivity. This is done at the application layer.

In both cases you will not detect the problem until you try to read or write on the socket.

查看更多
登录 后发表回答