This answer is not solely related with flask, but should be applicable for all cannot connect service from another host issue.
netstat -ano | grep <port>
to see if the address is 0.0.0.0 or ::. If it is 127.0.0.1 then it is only for the local requests.Today I run my flask app as usual, but I noticed it cannot connect from other server. Then I run netstat -ano | grep <port>
, and the local address is ::
or 0.0.0.0
(I tried both, and I know 127.0.0.1 only allows connection from the local host). Then I used telnet host port
, the result is like connect to ...
. This is very odd. Then I thought I would better check it with tcpdump -i any port <port> -w w.pcap
. And I noticed it is all like this:
Then by checking iptables --list
OUTPUT section, I could see several rules:
these rules forbid output tcp vital packets in handshaking. By deleting them, the problem is gone.