How to forward local server on XXXX port to sever outside firewall on port XXXX

1

Using ssh -R 9333:localhost:9333 remotehost.com

I'd like to be able to navigate to this via Chrome/Firefox/IE without have to use socks.

http://domain.com:9333

jbcurtin

Posted 2013-01-05T17:05:38.027

Reputation: 113

I think you have your forwarding backwards. Which host is your server running on? – CodeGnome – 2013-01-05T17:36:59.933

The dev-server is running locally on my machine. I'd like to push it to a foreign machine that is not behind a firewall. – jbcurtin – 2013-01-05T17:46:29.410

Answers

1

After "-R 9333:localhost:9333" your 9333 port forwards to 9333 of the lo0 of the remotehost. (lo0 is usally the localhost). So if you application listens 9333 on lo0, you can navigate it by simply typing on the ssh client side:

http://localhost:9333

dchirikov

Posted 2013-01-05T17:05:38.027

Reputation: 134

How can I use eth0 rather the lo0? – jbcurtin – 2013-01-05T17:52:00.210

"ssh -R 9333:remotehost.com:9333 remotehost.com". But you should check the name resolution of the 'remotehost.com' on the remotehost side: # host remotehost.com. You should also be sure than your application listens needed port: # netstat -na | grep :9333 – dchirikov – 2013-01-05T18:00:48.970

tcp 0 0 127.0.0.1:9333 0.0.0.0:* LISTEN tcp6 0 0 ::1:9333 :::* LISTEN – jbcurtin – 2013-01-05T18:04:12.590

I guess now I need to figure out how to access it from: domain.com:9333. Any thoughts? – jbcurtin – 2013-01-05T18:04:52.387

If I got you right you should use -L instead or -R: ssh -L 9333:localhost:9333 remotehost.com and then navigate to http://localhost:9333 on the client side – dchirikov – 2013-01-05T18:24:28.967

Other way around, I want to expose my local to my remote. Think port forwarding. – jbcurtin – 2013-01-05T18:29:32.560

With ssh -R 9333:localhost:9333 remotehost.com you forward local 9333 to remote 9333. So if your local app is binded to localhost:9333 on the client side it can receive requests from remotehost.com. ssh -L 9333:localhost:9333 remotehost.com allows you to navigate localhost:9333 on the client side and get access to app which is binded to localhost:9333 on the remotehost – dchirikov – 2013-01-05T18:44:04.840

ssh -R 9333:remotehost.com:9333 ssh -g -L 9334:127.0.0.1:9333 -- 'g' allows me to bind to all interfaces and it does not work for -R. This is apparently by design and the manual is not updated. I can access it on domain.com:9334 – jbcurtin – 2013-01-05T18:56:09.420

let us continue this discussion in chat

– dchirikov – 2013-01-05T19:05:22.037

Finally I catch what you want: enable Gateway ports ("GatewayPorts yes") in /etc/ssh/sshd_config, restart sshd and connect to 'ssh -R 9333:remotehost.com:9333 remotehost.com' – dchirikov – 2013-01-05T19:29:35.543