How to Allow Remote Connections to Flask Web Service

Flask is a pretty good web framework for Python based on Werkzeug, Jinja 2 and good intentions. It is lightweight, which can help you easily and quickly set up a web application starting from scratch.

For how to build up a web service, please follow the quickstart guide.


After successfully finishing your web service, you can run it with your Python interpreter. Make sure to not call your application because this would conflict with Flask itself.

For example, your service script is saved in file Start the service with the following command.

$ python
* Running on

Now head over to, and you should see your service.

You can accees the running service from the localhost. But you may cannot access this service from any other remote machines, such as


There may be serveral reasons that cause this kind of error.

Please make sure that your HTTP service is listenning on or everywhere ( ) by checking the output of

$ netstat -tupln | grep ':5000'
tcp 0 0* LISTEN 5423/python

If not, please bind the host to an address other than localhost.

Just as the doc said,

If you run the server you will notice that the server is only accessible from your own computer, not from any other in the network. This is the default because in debugging mode a user of the application can execute arbitrary Python code on your computer.

If you have debug disabled or trust the users on your network, you can make the server publicly available simply by changing the call of the run() method to look like this:

# runs on its own IP address'')


# This tells your operating system to listen on all public IPs.'')

Remember to restart the service manually after each change to your code.

If it is, allow the traffic using iptables:

$ iptables -I INPUT -p tcp --dport 5000 -j ACCEPT