Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

basically my setup looks something like this...


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

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

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


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.