Skip to content

Instantly share code, notes, and snippets.

@kennethkalmer
Last active April 1, 2020 19:41
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kennethkalmer/11258140 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
@ranaldobowker
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment