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


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


For instance, to connect to through from your local port 3306

ssh -L


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


Popular posts from this blog

Check MySQL query history from command line

Installing chocolatey on Windows

Fixed: ImportError: No module named