前两天aiming说有个内部访问php接口的服务器经常会收到rst。起初就怀疑是time_wait之类的东西作怪,但是一直想着会是client端time_wait的问题,于是陷入了死胡同。。。刚才突然想起貌似client端去请求server端http接口,主动断开的一方应该是server端,是server端进入了time_wait。顺着这个思路,经过试验,终于发现了问题的所在。
实验中用到的工具:tcpdump,curl,hping(你需要对他们进行一定的了解才能理解下面的内容)
实验中的client:sd-pt-cs00.bj(10.180.2.251)
实验中的server:sd-pt-xman00.bj(10.180.2.243)
我们首先模拟client请求server端http
[root@client]# curl "sd-pt-xman00.bj"
#得到若干内容
同一时间在server端抓到的包如下
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
00:04:45.820164 IP (tos 0x0, ttl 64, id 10936, offset 0, flags [DF], proto TCP (6), length 60)
sd-pt-cs00.bj.57979 > sd-pt-xman00.bj.http: Flags [S], cksum 0xc4ea (correct), seq tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
00:04:45.820164 IP (tos 0x0, ttl 64, id 10936, offset 0, flags [DF], proto TCP (6), length 60)
sd-pt-cs00.bj.57979 > sd-pt-xman00.bj.http: Flags [S], cksum 0xc4ea (correct), seq 2862922835, win 14600, options [mss 1460,sackOK,TS val 1309251307 ecr 0,nop,wscale 6], length 0
00:04:45.820217 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 60)
sd-pt-xman00.bj.http > sd-pt-cs00.bj.57979: Flags [S.], cksum 0xd192 (correct), seq 3280914721, ack 2862922836, win 14480, options [mss 1460,sackOK,TS val 4054807901 ecr 1309251307,nop,wscale 7], length 0
00:04:45.820217 IP (tos 0x0, ttl 64, id 10937, offset 0, flags [DF], proto TCP (6), length 52)
#此处省略若干行
00:04:45.821854 IP (tos 0x0, ttl 64, id 10942, offset 0, flags [DF], proto TCP (6), length 52)
sd-pt-cs00.bj.57979 > sd-pt-xman00.bj.http: Flags [F.], cksum 0x2ad1 (correct), seq 168, ack 3080, win 364, options [nop,nop,TS val 1309251309 ecr 4054807902], length 0
00:04:45.822037 IP (tos 0x0, ttl 64, id 48260, offset 0, flags [DF], proto TCP (6), length 52)
sd-pt-xman00.bj.http > sd-pt-cs00.bj.57979: Flags [.], cksum 0x2bc2 (correct), seq 3080, ack 169, win 122, options [nop,nop,TS val 4054807903 ecr 1309251309], length 0
可以算出来,最后server端针对client的fin包的ack值为169+2862922835=2862923004
接下来查看server端对这次链接的time_wait
Read More →