I need to forward internet traffic from a local machine to a remote machine, routing traffic through an intermediary SSH server on the way. The remote machine is firewalled and running a SOCKS5 proxy which accepts incoming connections on, for example, port 9999. The local machine is also firewalled and using a socks5 proxy via an ssh tunnel to a remote SSH server.

I'm able to accomplish this using the browser on the intermediary server configured to use the remote proxy, but I want to be able to do the same thing except using the browser on the local machine instead.

I can point my browser to the local socks5 proxy to forward the traffic to the SSH server, using "SSH -D [PORT] -C [SSH ADDRESS] -l [username]" to create the proxy and connect to SSH server. But what I haven't figured out is how to tunnel the traffic from the SSH server to the remote proxy. I'm confused by the syntax of SSH and the -R -L ProxyCommand and Connect commands.

I essentially need this:

|(L)Browser|->|(L)SOCKS5|-->|SSH server|-->|(R)SOCKS5|->|(R)Machine|-> internet

  • Cool story. So what have you tried so far? :) – EEAA Aug 11 '15 at 2:38
  • In the proxy configuration of the browser leave everything blank but the entry for Socks which should be the address and port of the local socks proxy. Also the "Use this proxy server for all protocols" should be cleared. – Brian Aug 11 '15 at 2:42

A good idea would be to use iptables as a port forwarder.

If my memory serves me right, IPTables can take traffic on a port and forward it through a SOCKS proxy on the same system. You can use this to create an SSH tunnel from the local computer, through the SSH Server and to the computer at the other end.

  • I'm on my phone, so if someone could put some examples that'd be helpful. – Quinton M. Aug 11 '15 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.