Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I wonder if anyone is able to help me with multiple tunnel hops for servers...

basically my setup looks something like this...

[desktop01]=====[server01]=====[server02]---------[machine01]
                                         \--------[machine02]
                                          \-------[machine03]
                                           \------[machine04]

I want to setup some ssh tunnels so that from my desktop I can ssh directly to machine01 through 04 without having to ssh to each box in between in turn...

So desktop01 can only see server01, server02 can only accept connections from server01 and machines 01 to 04 only accept connections from server02.

Can anyone help as im really stuck with this.

Thank you in advance :)

share|improve this question

3 Answers 3

Well, you could construct something like the following with port fowardings:

(Syntax: lport:remotehost:rport, which means "Forward port lport on the local machine to rport on the remote machine)

 [server01]            [server02]
 22001:server02:22001  22001:machine01:22  
 22002:server02:22002  22002:machine02:22  
 22003:server02:22003  22003:machine03:22  
 22004:server02:22004  22004:machine04:22  

You can then just do an ssh -p 22001 usernamefrom_machine01@server01 to connect to machine01 with the relevant username.

To construct the port forwardings, use either the -L option of ssh or configure it with the help of your ~/.ssh/config file.

For details, see man ssh and man ssh_config.

share|improve this answer

This was answered with several options over at superuser.com http://superuser.com/questions/96489/ssh-tunnel-via-multiple-hops

share|improve this answer

The following configuration in ~/.ssh/config allows you to dynamically setup jump hosts by separating them with the % symbol:

Host *%*
    ProxyCommand ssh $(echo %h | cut -d%% -f2-) nc $(echo %h | cut -d%% -f1) %p

You could then run ssh machine01%server02%server01 and it would connect to machine01 via server01 and server02. (This doesn't work so well when you need to specify non-default usernames unfortunately.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.