Configure Flask dev server to be visible across the network

前端 未结 14 2463
面向向阳花
面向向阳花 2020-11-21 05:57

I\'m not sure if this is Flask specific, but when I run an app in dev mode (http://localhost:5000), I cannot access it from other machines on the network (with

14条回答
  •  我寻月下人不归
    2020-11-21 06:53

    This answer is not solely related with flask, but should be applicable for all cannot connect service from another host issue.

    1. use netstat -ano | grep 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.
    2. use tcpdump to see if any packet is missing. If it shows obvious imbalance, check routing rules by iptables.

    Today I run my flask app as usual, but I noticed it cannot connect from other server. Then I run netstat -ano | grep , 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 -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.

提交回复
热议问题