Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I set up a free Amazon EC2 instance in order to use a Node app outside of my localhost environment.

The instance is allocated a public IP address at launch, mine for example being 54.187.31.42. Does this mean that if, within my launched Node program on the EC2, I'm listening for connections at http://localhost:8080, the server is listening for the connections at 54.187.31.42:8080 ?

Or is there more to it than that?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

No, listening sockets on localhost (127.0.0.1 or ::1 on IPv6-enabled systems) are only accessible from the very same system they were created on.

To configure a program to listen on all interfaces, you'd usually use 0.0.0.0 or ::. According to a quick Google search this should also be valid for node.js.

share|improve this answer
    
Thanks man. I'll accept this when time's up. –  user317572 Apr 22 at 21:35
1  
Note that it's often considered best practices to not use 0.0.0.0/::, as the are frequently not "future-proof". That said, though, better than 9 times out of 10 it isn't really a problem, just keep it in mind if you later add a second IP and then wonder why a second web server can't start up on it. –  Kromey Apr 22 at 21:55
    
That’s certainly true. However, for dynamic IP setups like EC2, there’s simply no other easy way. –  Daniel B Apr 23 at 5:22
    
Also it's worth to mention that if your app is configured to listen on 0.0.0.0, there still can be firewalls, like iptables which block the port for the outside world, or in your case, there is definitely a firewall between your EC2 instance and the outside world, in which you have to enable forwarding to the port in the Amazon management console. –  r1pp3rj4ck Apr 23 at 9:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.