Port forwarding to local port return ERR_CONNECTION_REFUSED with aws ec2
I'm trying to do port forwarding to access my local machine port 8888 by using the public address of my aws ec2 machine. (xxxx.compute.amazonaws.com:8888)
I tried this :
ssh -R 8888:localhost:8888 [email protected]
I have no error messages, but it just doesnt work.
netstat -ant
before ssh port forwarding :
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 172.31.xxx.xxx:22 124.122.xxx.xxx:12902 ESTABLISHED
tcp6 0 0 :::22 :::* LISTEN
netstat -ant
after ssh port forwarding :
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:8888 0.0.0.0:* LISTEN
tcp 0 0 172.31.xxx.xxx:22 209.141.xxx.xxx:53296 TIME_WAIT
tcp 0 368 172.31.xxx.xxx:22 124.122.xxx.xxx:1095 ESTABLISHED
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:8888 :::* LISTEN
But I keep having ERR_CONNECTION_REFUSED
in my browser. Even doing it on my simple apache2 server doesn't work : ssh -R 8888:localhost:80
.
I also have these inbound rules on aws ec2 : 8888 TCP 0.0.0.0/0
and i even added 8888 TCP ::/0
, 8888 UDP ::/0
and 8888 UDP 0.0.0.0/0
but same problem.
Solution 1:
The remote server is listening to 8888 on localhost only so you won't be able to connect to that from an external browser. That was also the case when I tried it - but I changed /etc/ssh/sshd_config on the EC2 to set GatewayPorts yes
, restarted sshd, and it now works ok for me.