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#
无法重用第一次成功后,后面都报错