Från wiki.soltec.se
Hoppa till: navigering, sök

How To Create a SSH tunnel from your laptop (SRC) through multiple hosts to a target (TGT) host

Use Virtual Box for virtualisation from your windows laptop.

from VM to TGT

Create the tunnel from your vbox VM to the TGT server
- On the vbox vm or cygwin host create a tunnel to the IP and port number of the TGT server that you wish to access.
-> $ ssh -L *:7777:<TGT IP>:8181 < TGT IP>
- The < - L * > allows connections from any interface.
- 7777 is the port on your localhost/VM that is configured to connect to port 8181 of the TGT host.
- Leave the connection open in it's own terminal window for your connection to work.

from Laptop to VM

Create the tunnel from your laptop to your VM
- On your laptop use PuTTy to create a tunnel to your vbox/cygwin VM instance.
- Load/create a connection to your VM with the following configuration
-> IP: Port: 22
- Under <Connection> - < SSH > - < Tunnels > add the port on your laptop that you want to use to forward to the port you setup in the previous step on your VM
-> Laptop Port: 5555 (as an example)
-> VM Port: 7777 (created in step #1)
-Enter the above info in the cfg box as per below.
-> Source port: 5555
-> Destination: IP of your VM instance e.g.
- Click on < Apply >
MediaWiki-PIC-PuTTY Tunnel.jpg

Test Connection

Test your connection by opening a BUI on your laptop and entering the following in the URL
You should see the web page presented by your TGT server on a browser direct from your laptop.

Simple script for VM to TGT

# Tunnel to TGT from this VM using port 7777
echo "Connect to TGT"
read -p "TGT IP number? " IPNR
read -p "TGT Port number? " PORT
ssh -L *:7777:$IPNR:$PORT $IPNR