Question I would like to know how to tunnel requests made on a server (debian) to port 80 on my laptop using ssh tunneling.
Problem I can open up a tunnel with the following command that does not behave quite as I would like:
ssh -R 4445:localhost:80 sam@example.com
After running this and getting a shell at example.com, the following command executes as expected returning the web page being hosted on my laptop:
wget localhost:4445
However, when trying to run this same command using example.com:4445 rather than localhost:4445, I get a connection refused.
Extra info: I also tried writing a forwarding rule using shorewall:
DNAT net $FW:127.0.0.1:4445 tcp 4446
and then tried
wget example.com:4446
When wget fails in any of the above cases, I get this:
--2011-02-16 13:48:26-- http://example.com:4446/
Resolving example.com... 70.90.XXX.XX
Connecting to example.com|70.90.XXX.XX|:4446... failed: Connection refused.
Any ideas on where to go from here? Also, if there is different / better way to achieve this effect I am completely open to the idea.
EDIT Thanks for the suggestions!
Tried the following:
ssh -R example.com:4445:localhost:80 sam@example.com
and
ssh -R :4445:localhost:80 sam@example.com
Then when running the same wget as above came back with the same error. I should maybe mention that this server has two interfaces (eth0 public eth1 private).
EDIT
I am a moron 🙁 Had to set
GatewayPorts yes
in sshd_config. Thanks for the help everyone!
Best Answer
ssh is configured for security reasons to make the new tunnels to listen on localhost. You have to use:
From the man page of openssh: