SSH Tunneling

A SSH Tunnel allows you to send traffic to a remote machine through another machine.   I often use this to access instances on another network which my desktop can not see.  

Example:

Let's open a tunnel on our port 9009 which will reach port 443 on a remote machine
  • ssh -L 9009:localhost:443 root@192.168.252.10
    • This will open port 9009 on our local host and direct traffic on 9009 to port 443 on the remote machine 192.168.252.10

Generally I need to go further and use a remote machine as a gateway to reach another machine, so I'll open up a tunnel on the remote machine as well:

  • ssh -t -t -L 9009:localhost:9009 root@foo.example.com 'ssh -L 9009:localhost:443 root@192.168.252.10'
    • With this port 9009 on localhost will redirect to 9009 on foo.example.com which will redirect to 443 on 192.168.252.10