Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in AWS by (12.9k points)

This is a very basic Amazon EC2 question, but I'm stumped so here goes.

I want to launch an Amazon EC2 instance and allow access to HTTP on ports 80 and 8888 from anywhere. So far I can't even allow the instance to connect to on those ports using its own IP address (but it will connect to localhost).

I configured the "default" security group for HTTP using the standard HTTP option on the management console (and also SSH).

I launched my instance in the default security group.

I connected to the instance on SSH port 22 twice and in one window launch an HTTP server on port 80. In the other window I verify that I can connect to HTTP using the "localhost".

However when I try to access HTTP from the instance (or anywhere else) using either the public DNS or the Private IP address I het "connection refused".

What am I doing wrong, please?

Below is a console fragment showing the wget that succeeds and the two that fail run from the instance itself.

--2012-03-07 15:43:31--  http://localhost/

Resolving localhost... 127.0.0.1

Connecting to localhost|127.0.0.1|:80... connected.

HTTP request sent, awaiting response... 302 Moved Temporarily

Location: /__whiff_directory_listing__ [following]

--2012-03-07 15:43:31--  http://localhost/__whiff_directory_listing__

Connecting to localhost|127.0.0.1|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: unspecified [text/html]

Saving to: “__whiff_directory_listing__”

[ <=>

                                                                                                               ] 7,512       --.-K/s   in 0.03s   

2012-03-07 15:43:31 (263 KB/s) - “__whiff_directory_listing__” saved [7512]

[ec2-user@ip-10-195-205-30 tmp]$ wget http://ec2-50-17-2-174.compute-1.amazonaws.com/

--2012-03-07 15:44:17--  http://ec2-50-17-2-174.compute-1.amazonaws.com/

Resolving ec2-50-17-2-174.compute-1.amazonaws.com... 10.195.205.30

Connecting to ec2-50-17-2-174.compute-1.amazonaws.com|10.195.205.30|:80... failed:          

Connection refused.

[ec2-user@ip-10-195-205-30 tmp]$ wget http://10.195.205.30/

--2012-03-07 15:46:08--  http://10.195.205.30/

Connecting to 10.195.205.30:80... failed: Connection refused.

[ec2-user@ip-10-195-205-30 tmp]$ 

closed

1 Answer

0 votes
by (18.2k points)
selected by
 
Best answer

You need to bind to a particular IP address when you send or listen. There are a few special addresses:

  • Localhost: 127.0.0.1
  • Any address: 0.0.0.0

These addresses are used to listen on ANY or more commonly, ALL addresses on the host.

So, when you set up your server that listens to localhost, you are telling the service that you want to use the special reserved address that can only be reached by users of this host. And while it exists on every host, making a connection to localhost will only just reach the host you are making the request from.

if you want the service to be reachable from everywhere(either on a local host or on all interfaces) you should specify 0.0.0.0

Related questions

0 votes
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

Browse Categories

...