Monday, April 9, 2018

SSH Port Forwarding (tunnel) in Linux for Proxy etc.

Dynamic:

Dynamic port forwarding turns your SSH client into a SOCKS proxy server. To use dynamic port forwarding with the default SOCKS port:

ssh -C -D 1080 yourRemoteServer:port
ssh -C -D 1080 yourRemoteServer (when you use the default port 22)
ssh -C -D 1080 -i yourKeyFile.pem ec2-user@yourEC2
  • The -D option specifies dynamic port forwarding. 1080 is the standard SOCKS port. Although you can use any port number, some programs will only work if you use 1080. 
  • The -C option enables compression, which speeds the tunnel up when proxying mainly text-based information (like web browsing), but can slow it down when proxying binary information (like downloading files).
Now you have a SOCKS proxy server: localhost:1080

Static:

For instance, to connect to mysql.i88.ca:3306 through tennel.i88.ca from your local port 3306

ssh -L 3306:mysql.i88.ca:3306 superman@tennel.i88.ca

Both:

You could add:
 -N      Do not execute a remote command.  This is useful for just forwarding ports (protocol version 2 only).

See also:

How to connect to remote MySQL server by SSH tunnel


Featured Post

British-based startup ARC unveiled its first motorcycle model in Milan this week

One being described as fast, advanced and expensive. The so-called Vector costs more than $100,000