Is listening on a port on the localhost of a server the same as listening on that port of the server's public IP address?

6,061

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:
6,061

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    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?

  • Kromey
    Kromey about 10 years
    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.
  • Daniel B
    Daniel B about 10 years
    That’s certainly true. However, for dynamic IP setups like EC2, there’s simply no other easy way.