I know there are tons of posts about not being able to connect to an AWS ec2 instance, but this is not quite the same. It is similar to What causes the 'Connection Refused' message? but that was not able to solve my problem.
I have quite a lot of experience with ec2 instances, but it is the first time I try it with REHL.
Here is my setup:
- I have a machine A with an apache server listening on port 80
- Machine A is also connected to an AWS EC2 server S with a reverse tunnel:
ssh -v -NTR 1101:localhost:80 someUser@myAwsIp -o ExitOnForwardFailure=yes
- Server S has the following port forwarding:
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 1101
In simple words, all traffic coming into S on port 80 should go to A on port 80.
But it's not working.
That is to say, when I run curl myAwsIp:80
from a machine B, curl returns with "connection refused".
Some basic facts:
- I am sure the ip is correct since I ssh into the server to run these commands
- I have no iptables rules to drop anything. Both 'filter' and 'nat' tables are entirely set to ACCEPT (except the rule mentioned above)
- I have opened port 80 on my EC2 Management Console. It looks like this:
Ports Protocol Source
80 tcp 0.0.0.0/0 22 tcp 0.0.0.0/0
- I am not very familiar with semanage, but from searching online I saw that it could be a problem.
When I run
semanage port -l | grep 80
I can see the line "http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000" which should be enough to let curl requests through, right?
My debugging has shown that:
- the httpd server is running and listening on the right port because when I am logged in on S and I run
curl localhost:1101
I get my webpage - the forwarding should be working because when I run
nc -kl 1101
on S (instead of the ssh port forwarding) and when I runcurl myAwsIp:80
from my machine B, I get an incoming connection request on netcat.
But still when I run curl myAwsIp:80
from my machine B, curl returns with "connection refused" (without nc running of course)
What am I missing??? Thanks for your help! This is frustrating! Note that this exact same setup was working on another AWS EC2 instance but with Amazon-linux installed... is there so much difference between the two?