3

I can't curl one of my installed software using the external EC2 ip address but if I curl using localhost:5000 (or 127.0.0.1:5000), it works fine. Any insights will be appreciated.

I've installed these 3 items:

  • Elasticsearch, port 9200        => I can curl using internal and external IP
  • Jenkins, port 8080                 => I can curl using internal and external IP
  • Python Flask app, port 5000 => I CAN'T curl using external IP. Internal IP works fine

Using the external IP address, I can curl the first two items but not the python flask application.

Here's the error below. I replaced the real ip address with "external_ip":

$ curl -v external_ip:5000
* Rebuilt URL to: external_ip:5000/
* Hostname was NOT found in DNS cache
*   Trying external_ip...
* connect to external_ip port 5000 failed: Connection refused
* Failed to connect to external_ip port 5000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to external_ip port 5000: Connection refused

Here's the curl version:

$ curl --version
curl 7.35.0 (x86_64-pc-linux-gnu) libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3

Here's the OS version:

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.1 LTS"

netstat shows all ports are being listened to but the port in question is linked to 127.0.0.1. How can I get this to be mapped to the external ip address?

$ sudo netstat -an | grep -E "5000|9200|8080"
tcp        0      0 127.0.0.1:5000          0.0.0.0:*               LISTEN
tcp6       0      0 :::9200                 :::*                    LISTEN
tcp6       0      0 :::8080                 :::*                    LISTEN

By the way, I ran into the same results using Vagrant.

Any ideas?

sftoparis
  • 43
  • 1
  • 1
  • 4
  • 1
    Connection refused generally means nothing is listening on the relevand IP:port pair, we already have [loads of Q&A](http://serverfault.com/search?q=user%3A9517+connection+refused+netstat) about this – user9517 Sep 13 '14 at 16:26

1 Answers1

6

Flask apps by default only listen on the local interface, if you want your app to be available on external addresses, start it as app.run(host='0.0.0.0')

Dennis Kaarsemaker
  • 19,277
  • 2
  • 44
  • 70