We Recommend

bash Cookbook: Solutions and Examples for bash Users bash Cookbook: Solutions and Examples for bash Users
bash Cookbook teaches shell scripting the way Unix masters practice the craft. It presents a variety of recipes and tricks for all levels of shell programmers so that anyone can become a proficient user of the most common Unix shell -- the bash shell -- and cygwin or other popular Unix emulation packages.


Posted By

Juanje on 05/14/08


Tagged

ssh reverse tunnel


Versions (?)


Reverse ssh tunnel


Published in: Bash 


This is very useful with dinamic IP connections. You can connect from the host with the dinamic IP, leave the tunnel open to other machine with ssh access and fixed IP and then connect to this machine on specific port (22000 in the example) to connect to the host with dinamic IP.

Also it can be useful in case you need access to a host which is inside a local network and you can't access from outside, but from this host you can connect to outside.

  1. # Reverse ssh tunnel:
  2. # Host to access -> destination.host.net ; user=dest_user
  3. # Source host -> source.host.net ; user=src_user
  4. dest_user@destination.host.net$ ssh -R 22000:localhost:22 -f -N src_user@source.host.net
  5. src_user@source.host.net$ ssh -p 22000 dest_user@localhost

Report this snippet 

You need to login to post a comment.