随机端口启动TCP请求

时间:2017-08-02 02:07:13

标签: linux tcp centos superuser time-wait

随机端口在centos 6.8上的两个服务器程序之间启动TCP请求。

# netstat -an|grep 6001
tcp        0      0 0.0.0.0:6001                0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:52470             127.0.0.1:6001              TIME_WAIT   
tcp        0      0 127.0.0.1:52599             127.0.0.1:6001              TIME_WAIT   
tcp        0      0 127.0.0.1:52428             127.0.0.1:6001              TIME_WAIT   
tcp        0      0 127.0.0.1:52640             127.0.0.1:6001              TIME_WAIT   
tcp        0      0 127.0.0.1:50038             127.0.0.1:6001              ESTABLISHED 
tcp        0      0 127.0.0.1:6001              127.0.0.1:50038             ESTABLISHED 
tcp        0      0 127.0.0.1:52510             127.0.0.1:6001              TIME_WAIT   
tcp        0      0 127.0.0.1:52559             127.0.0.1:6001              TIME_WAIT

有些TIME_WAIT总是存在,我不明白为什么。

# tcpdump -ni lo port 6001
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
08:55:01.001341 IP 127.0.0.1.50038 > 127.0.0.1.6001: Flags [P.], seq 12:24, ack 1, win 1024, options [nop,nop,TS val 9066110 ecr 9056110], length 12
08:55:01.001358 IP 127.0.0.1.6001 > 127.0.0.1.50038: Flags [.], ack 24, win 512, options [nop,nop,TS val 9066110 ecr 9066110], length 0
08:55:02.947977 IP 127.0.0.1.50038 > 127.0.0.1.6001: Flags [P.], seq 24:42, ack 1, win 1024, options [nop,nop,TS val 9068056 ecr 9066110], length 18
08:55:02.947987 IP 127.0.0.1.6001 > 127.0.0.1.50038: Flags [.], ack 42, win 512, options [nop,nop,TS val 9068056 ecr 9068056], length 0
08:55:08.107233 IP 127.0.0.1.53349 > 127.0.0.1.6001: Flags [S], seq 4256285474, win 65495, options [mss 65495,sackOK,TS val 9073216 ecr 0,nop,wscale 7], length 0
08:55:08.107255 IP 127.0.0.1.6001 > 127.0.0.1.53349: Flags [S.], seq 3307774380, ack 4256285475, win 65483, options [mss 65495,sackOK,TS val 9073216 ecr 9073216,nop,wscale 7], length 0
08:55:08.107271 IP 127.0.0.1.53349 > 127.0.0.1.6001: Flags [.], ack 1, win 512, options [nop,nop,TS val 9073216 ecr 9073216], length 0
08:55:08.107294 IP 127.0.0.1.53349 > 127.0.0.1.6001: Flags [F.], seq 1, ack 1, win 512, options [nop,nop,TS val 9073216 ecr 9073216], length 0
08:55:08.107370 IP 127.0.0.1.6001 > 127.0.0.1.53349: Flags [.], ack 2, win 512, options [nop,nop,TS val 9073216 ecr 9073216], length 0
08:55:08.108237 IP 127.0.0.1.6001 > 127.0.0.1.53349: Flags [F.], seq 1, ack 2, win 512, options [nop,nop,TS val 9073217 ecr 9073216], length 0
08:55:08.108248 IP 127.0.0.1.53349 > 127.0.0.1.6001: Flags [.], ack 2, win 512, options [nop,nop,TS val 9073217 ecr 9073217], length 0
08:55:12.001197 IP 127.0.0.1.50038 > 127.0.0.1.6001: Flags [P.], seq 42:54, ack 1, win 1024, options [nop,nop,TS val 9077109 ecr 9068056], length 12
08:55:12.001206 IP 127.0.0.1.6001 > 127.0.0.1.50038: Flags [.], ack 54, win 512, options [nop,nop,TS val 9077110 ecr 9077109], length 0
08:55:16.859786 IP 127.0.0.1.53391 > 127.0.0.1.6001: Flags [S], seq 127196351, win 65495, options [mss 65495,sackOK,TS val 9081968 ecr 0,nop,wscale 7], length 0
08:55:16.859797 IP 127.0.0.1.6001 > 127.0.0.1.53391: Flags [S.], seq 1018026274, ack 127196352, win 65483, options [mss 65495,sackOK,TS val 9081968 ecr 9081968,nop,wscale 7], length 0
08:55:16.859809 IP 127.0.0.1.53391 > 127.0.0.1.6001: Flags [.], ack 1, win 512, options [nop,nop,TS val 9081968 ecr 9081968], length 0
08:55:16.859827 IP 127.0.0.1.53391 > 127.0.0.1.6001: Flags [F.], seq 1, ack 1, win 512, options [nop,nop,TS val 9081968 ecr 9081968], length 0
08:55:16.860234 IP 127.0.0.1.6001 > 127.0.0.1.53391: Flags [F.], seq 1, ack 2, win 512, options [nop,nop,TS val 9081969 ecr 9081968], length 0
08:55:16.860254 IP 127.0.0.1.53391 > 127.0.0.1.6001: Flags [.], ack 2, win 512, options [nop,nop,TS val 9081969 ecr 9081969], length 0
08:55:22.001768 IP 127.0.0.1.50038 > 127.0.0.1.6001: Flags [P.], seq 54:66, ack 1, win 1024, options [nop,nop,TS val 9087110 ecr 9077110], length 12
08:55:22.001777 IP 127.0.0.1.6001 > 127.0.0.1.50038: Flags [.], ack 66, win 512, options [nop,nop,TS val 9087110 ecr 9087110], length 0

端口53349和53391,TCP请求从何处开始?请帮忙。

1 个答案:

答案 0 :(得分:0)

  

随机端口在两个服务器程序之间启动TCP请求

正确。客户端端口是随机分配的。

  

有些TIME_WAIT总是存在,我不明白为什么。

因为他们总是这样做,所以在第一次结束时。它是TCP的一个定义部分。请参阅RFC 793

  

端口53349和53391,TCP请求从哪里开始?

在本地使用这些端口的最后。如果您要问哪一行:

8:55:08.107233 IP 127.0.0.1.53349 > 127.0.0.1.6001: Flags [S], seq 4256285474, win 65495, options [mss 65495,sackOK,TS val 9073216 ecr 0,nop,wscale 7], length 0

08:55:16.859786 IP 127.0.0.1.53391 > 127.0.0.1.6001: Flags [S], seq 127196351, win 65495, options [mss 65495,sackOK,TS val 9081968 ecr 0,nop,wscale 7], length 0

(S表示SYN)。