I have a server in my home network (cannot port forward) and a VPS on the WAN. I need requests on a certain port, to, not from, the VPS to be forwarded to my home server. I have an SSH tunnel which works fine if I send the request to localhost
on VPS. However I want requests forwarded to VPS's localhost
from internet be sent to my home server through the tunnel. And it needs to be bi-directional.
I have seen this question, however it doesn't work for me. It is quite possible that I did something incorrectly.
My exact procedure:
On server a
, my home server, I ran this command to set up the tunnel:
ssh -v -N -R 2222:localhost:22 [email protected]
I ran the following command on server b
(VPS):
iptables -t nat -A PREROUTING -p tcp --dport 2223 -j DNAT --to-destination 127.0.0.1:2222
And tried to ssh
from another machine:
ssh [email protected] -p 2223
I set GatewayPorts yes
in sshd_config
however I am still finding the same problem:
ssh: connect to host server-b.com port 2223: Connection refused.
GatewayPorts
setting on the VPS serversshd_config
. This can allow the remote port 2222 to bind to all IP addresses and so be visible without NATting.GatewayPorts
toyes
however it is still not functioning.