linux下tcp keepalive相关参数调整测试

首先说明下面三个和keepalive相关的内核参数以及默认的值 # sysctl -a | grep keepalive # 在会后一次发送数据包后多久向对方发起探测 net.ipv4.tcp_keepalive_time = 7200 # 在没有收到对方确认时,会按照这个时间间隔再次探测 net.ipv4.tcp_keepalive_intvl = 75 # 在没有收到对方确认时,进行探测的次数 net.ipv4.tcp_keepalive_probes = 9 下面通过在本地环境上测试这些参数,首先将本地的默认keepalive参数进行修改 # sysctl -a | grep keepalive net.ipv4.tcp_keepalive_intvl = 5 net.ipv4.tcp_keepalive_probes = 9 net.ipv4.tcp_keepalive_time = 20 下载并编译带keepalive功能支持的netcat命令行工具 git clone https://github.com/cyberelf/netcat-keepalive.git cd netcat-keepalive/ make linux 运行tcpdump进行抓包 tcpdump -iany port 18888 启动服务端监听 ./nckl-linux -v4K -l 18888 使用nc去连接 nc -v -p55666 localhost 18888 可以看到抓包内容如下 root@debian:/home/blue# tcpdump -iany port 18888 tcpdump: verbose…