Ssh – Making proxy available on remote server through ssh tunneling

PROXYsshssh-tunnel

I know I can use ssh tunneling to create a "proxy" on my machine so that I can make all the traffic generated locally go through a remote server. Like this:

$ ssh -D 12345 myuser@remote_ssh_server

But what about if I need to create a "proxy" on the remote server, so that all the traffic that I send it will go through my local machine? Is this possible with ssh?

Essentially, I want to use my local internet connection with some specific commands to run remotely, as the server does not have direct access to the internet.

Best Answer

The simplest way to do this is one port and host at a time. For example, to forward traffic from remote:8001 to intraserver:80,

ssh -R 8001:intraserver:80 myuser@remote

But if you want to forward all traffic from remote, and you have an ssh server running on your local host,

ssh -R 2200:localhost:22 myuser@remote ssh -D 10800 -p 2200 localhost

Unwrapping that:

  • -R 2200:localhost:22 sets up a forward from remote:2200 to localhost:22.
  • ssh -p 2200 localhost runs ssh on remote, to connect to remote:2200, and so back to localhost:22 (tunneled over the first ssh connection).
  • -D 10800 tunnels SOCKS from remote:10800, over the connection from remote back to localhost.
Related Topic