Reputation: 703
I have two machines say A and B
on B I have a virtual machine running ( lets say its VB ) . Unfortunately , the VB has a static local IP address ( 192.168.79.1 ) which can't be changed .
I am successfully able to ssh in the following way
A -> B B -> VB
I tried to setup ssh port forwarding on B ( port 7777) to forward to VB (port 22) .But somehow its not happening .
Should I be using -L or -R ?
I tried many ways..
ssh -R 7777:192.168.79.1:22 [email protected]
ssh -L 7777:192.168.79.1:22 [email protected]
ssh -L 7777:192.168.79.1:22 -l root localhost
May be I did not understand the syntax properly or am I missing something silly ?
I want to connect to A->VB ( via some xyz port on B ) . Please guide me how to set this up .
BTW , all the machines need a username and password..I did not yet add the keys (so please consider this also).
Thanks!!
Upvotes: 2
Views: 1458
Reputation: 42915
You address the wrong host to setup your tunnel. What you are trying to do is actually not port forwarding, that is usually done on a firewall level. Instead you try to setup a tunnel to expose your ssh server on VB under some port xyz on system B. For this you have to ssh into that system B, not into VB. So something like this:
ssh -L7777:192.168.79.1:22 some_user@<B>
So user 'some_user' sshs into host B and does nothing else there (<B>
has to be replaced with Bs ip address or name), except he additionally creates a 'ssh tunnel' you can now use to connect through:
ssh root@<B>:7777
Have a try, you well see that you are actually login in into VB because your request is tunneled through to port 22 on host VB in a transparent manner. So B acts as a tunnel relay.
But this is a little annoying for everyday usage. Think of finding a solution on firewall level using iptables instead. That saves you from having to create the ssh tunnel before using it. Alternatively there are also utilities like plasmoids and the like to setup an ssh tunnel in a more convenient way.
Upvotes: 3