Skip to content

Instantly share code, notes, and snippets.

@Icebreaker454
Created November 27, 2017 20:16
Show Gist options
  • Save Icebreaker454/edbfc1214c6b97b44e86189f1b726a93 to your computer and use it in GitHub Desktop.
Save Icebreaker454/edbfc1214c6b97b44e86189f1b726a93 to your computer and use it in GitHub Desktop.

Basics

  • $LOCAL_HOST: 'localhost' or hostname from local network
  • $LOCAL_PORT: open port on local machine
  • $REMOTE_HOST: remote hostname visible from remote network
  • $REMOTE_PORT: port on $REMOTE_HOST

Forward Tunnel: map port from remote machine/network on local machine

ssh -L $LOCAL_PORT:$REMOTE_HOST:$REMOTE_PORT $USER@$SERVER

Reverse Tunnel: make local port accessable to remote machine

ssh -R $REMOTE_PORT:$LOCAL_HOST:$LOCAL_PORT $USER@$SERVER

A quick example

Let's say I have a work computer and I can ssh to it from my home computer. At work, there's a private(internal) network with our test server. test.privatenetwork.co There's a CI app (jenkins) running on test.privatenetwork.co:8080 and I want to access it from my home computer. Since I can't access it directly, as test.privatenetwork.co is not visible to my DNS, I will create a SSH tunnel. So I type

ssh -L 8080:test.privatenetwork.co:8080 my_work_user@my_work_server

Which means "Make port 8080 on test.privatenetwork.co as seen from my_work_server available on localhost:8080"

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