Skip to content

Instantly share code, notes, and snippets.

@ionutzp
Forked from kennethkalmer/README.md
Created April 5, 2017 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ionutzp/96a9b8469adc34f364b48124489e7623 to your computer and use it in GitHub Desktop.
Save ionutzp/96a9b8469adc34f364b48124489e7623 to your computer and use it in GitHub Desktop.
Making sense of basic port forwarding with SSH tunnels

SSH tunnel example

We all know how to ssh to a remote box...

Basic SSH connection with ssh 99.88.77.66

                            99.88.77.66
 +-------+                            +--------+
 | LOCAL |----------------------------| REMOTE |
 +-------+                            +--------+

Forward tunneling example

Tunnel port 6000 to a remote server, through a gateway with ssh -L 6000:192.168.10.24:5984 99.88.77.66

                            99.88.77.66        192.168.10.10  192.168.10.24
 +-------+                            +--------+                          +-------+
 | LOCAL |----------------------------| REMOTE |--------------------------| OTHER |
 +-------+                            +--------+                          +-------+
         :6000 =========================================================> :5984

This allows us to access port 5984 on the a box behind the REMOTE, through port 6000 on localhost.

The -L flags are strange, but they describe the tunnel in the following way:

[bind_address:]port:host:hostport
|    LOCAL SIDE    | REMOTE SIDE |

Where:

  • LOCAL SIDE is where the connection is from, and bind_address defaults to localhost`.
  • REMOTE SIDE is from the point of view where the connection terminates, and can describe the network topology that the remote server has access to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment