Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I wanna connect to a group of machines using a specific machine using ssh tunneling. But in all solutions found, I need to specify a entry per machine in my ssh config file. I would like to use a wildcard in this way:

   Host *.mydomain.com
   // some magic here

For now, the best solution found was:

http://magazine.redhat.com/2007/11/27/advanced-ssh-configuration-and-tunneling-we-dont-need-no-stinking-vpn-software/

share|improve this question
    
Does the tunnel server allow executing commands (specifically netcat, nc and/or socat), or is it strictly tunneling-only? –  grawity May 7 '12 at 18:19
    
yes! it can execute commands! –  Jonhnny Weslley May 7 '12 at 18:21
add comment

1 Answer 1

up vote 1 down vote accepted

If you can run programs such as nc or netcat or socat on your tunnel server, you could use a ProxyCommand instead of a port forward:

# Only necessary if it matches the *.mydomain.com wildcard. Useless otherwise.
Host tunnelbox.mydomain.com
    ProxyCommand none

Host *.mydomain.com
    ProxyCommand ssh tunnelbox.mydomain.com nc %h %p
    #ProxyCommand ssh tunnelbox.mydomain.com ncat %h %p
    #ProxyCommand ssh tunnelbox.mydomain.com socat stdio tcp:%h:%p
    #ProxyCommand ssh tunnelbox.mydomain.com netcat %h %p

Uncomment the apropriate ProxyCommand, depending on what tools the tunnel server has installed.


Note that this will set up and tear down a separate SSH connection for every tunnel established, which means connecting will be slower than via SOCKS. (It won't affect performance after connection, however.)

If your SSH version supports it, you could enable connection multiplexing:

Host tunnelbox.mydomain.com
    ControlMaster no
    ControlPath none

Host *.mydomain.com
    ControlMaster auto
    ControlPath ~/.ssh/S.%l.%r@%h:%p
    ControlPersist 10m
share|improve this answer
    
thanks @grawity! SOCKS rocks! –  Jonhnny Weslley May 7 '12 at 18:41
add comment

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.