LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   SSH Tunnel Through 2 machines? (https://www.linuxquestions.org/questions/linux-newbie-8/ssh-tunnel-through-2-machines-564389/)

philosophia 06-25-2007 12:11 PM

SSH Tunnel Through 2 machines?
 
I run an ssh tunnel so that i can connect to my sql server ssh

ssh -L1433:sql-dev:1433 -l user server.com

I'm currently at a remote location - I can't log onto server.com from here. But I can log onto server2.com, from which I can log onto server.com.

Is there a way I can tunnel through server2 in order to establish my tunnel to server.com so that I can connect from this remote location?

acid_kewpie 06-25-2007 12:14 PM

you can do tunnels on two seperate connections, sure.

philosophia 06-25-2007 12:29 PM

how would this ssh command look? i'm having trouble getting my head around it.

acid_kewpie 06-25-2007 04:13 PM

well nothing special, just another normal tunnel. assuming you want to acces a tcp port that is only reachable via a box which itself you can only reach via sshing to another

your client command: ssh -L 1234:localhost:2345 remotebox1
your ssh from remotebox1: ssh -L 2345:remotebox3:3456 remotebox2

so you then connect to localhost:1234 and that ends up hitting 2345 on the first box you ssh to. that traffic then gets forwarded from port 2345 on the box through the 2nd box and onwards to the third system which is runnign the service you actually want.

but then hang on... you can connect from your client to box1, that ssh connection doesn't necessarily need to do anything special as you can also presumably hit any port on the box, not just 22? assumign that that's the case, you only need to establish the tunnel on the 2nd command... "ssh -L 1234:remotebox3:3456 remotebox2" so you then connect to port 1234 on box1 (instead of the client machien itself as in the first example) and then direct to box 3.


All times are GMT -5. The time now is 01:27 PM.