Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon AWS EC2 ports: connection refused

I have just created an EC2 instance on a brand new AWS account, behind a security group, and loaded some software on it. I am running Sinatra on the machine on port 4567 (currently), and have opened that port in my security group to whole world. Further, I am able to ssh into the EC2 instance, but I cannot connect on port 4567. I am using the public IP to connect:

shakuras:~ tyler$ curl **.***.**.***:22
SSH-2.0-OpenSSH_6.2p2 Ubuntu-6ubuntu0.1
curl: (56) Recv failure: Connection reset by peer
shakuras:~ tyler$ curl **.***.**.***:4567
curl: (7) Failed connect to **.***.**.***:4567; Connection refused

But my webserver is running, since I can see the site when I curl from localhost:

ubuntu@ip-172-31-8-160:~$ curl localhost:4567
Hello world! Welcome

I thought it might be the firewall but I ran iptables and got:

ubuntu@ip-172-31-8-160:~$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

I'm pretty lost on what is going on here. Why can't I connect from the outside world?

like image 841
trlemburg Avatar asked Mar 11 '14 18:03

trlemburg


People also ask

Why is my EC2 instance refused to connect?

The following are common causes for this error: The host reached the instance but there was no service listening on the SSH port. A firewall blocked and was set to reject the package instead of dropping it.

Why am I unable to connect to a port on an EC2 Windows?

The following issues can prevent a connection to an EC2 Windows instance on a specific port: The service that uses the port isn't running on the instance. Windows Firewall is blocking traffic to the port. A security group is blocking traffic.

How do I enable ports on AWS?

On the AWS Elemental Server web interface, go to the Settings page and choose Firewall. You must turn on the node firewall before you can make any changes to the ports. In the Firewall Settings, choose Firewall On. (Optional) To enable a port, choose Accept for that port.


3 Answers

This sounds like issue with the Sinatra binding. Could check this and this and even this link which talks about binding Sinatra to all IP addresses.

like image 68
slayedbylucifer Avatar answered Sep 21 '22 16:09

slayedbylucifer


Are you sure that the web server is listening on other interfaces than localhost? Check the output of netstat -an | grep 4567

If it isn't listening on 0.0.0.0 then that is the cause.

like image 39
RasmusW Avatar answered Sep 21 '22 16:09

RasmusW


You are listening on 127.0.0.1 based on your netstat command. This is what the output should be something like this:

tcp        0      0 :::8080                     :::*                        LISTEN

Can you post your Sinatra configs? What are you using to start it ?

like image 21
Rico Avatar answered Sep 22 '22 16:09

Rico