net.ipv4.tcp_tw_reuse = 1 重用time_wait

net.ipv4.tcp_tw_reuse = 1

開啓tcp_tw_reuse 

net.ipv4.ip_local_port_range = 50001 50001
node2:/root/test#python connect1.py 
response:15
node2:/root/test#python connect1.py 
response:15
node2:/root/test#python connect1.py 
response:15
node2:/root/test#python connect1.py 
response:15
node2:/root/test#python connect1.py 
response:15

net.ipv4.tcp_tw_reuse = 1
node2:/root/test#sysctl -w net.ipv4.ip_local_port_range="50001 50001"
net.ipv4.ip_local_port_range = 50001 50001
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   
tcp        0      0 192.168.137.3:50001         192.168.137.2:8080          TIME_WAIT   

此時可以重用TCP連接


關閉tcp_tw_reuse 

net.ipv4.tcp_tw_reuse = 0
node2:/root/test#sysctl -w net.ipv4.ip_local_port_range="50001 50001"
net.ipv4.ip_local_port_range = 50001 50001


就一直報錯 
node2:/root/test#python connect1.py 
response:15
node2:/root/test#python connect1.py 
Traceback (most recent call last):
  File "connect1.py", line 6, in <module>
    s.connect(("192.168.137.2",8080))
  File "/usr/local/python27/lib/python2.7/socket.py", line 227, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 99] Cannot assign requested address
node2:/root/test#python connect1.py 
Traceback (most recent call last):
  File "connect1.py", line 6, in <module>
    s.connect(("192.168.137.2",8080))
  File "/usr/local/python27/lib/python2.7/socket.py", line 227, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 99] Cannot assign requested address
node2:/root/test#

無法重用第一次成功後,後面都報錯

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章