Multiple SSH Tunnels

Posted Jul 17, 2008 // 3 comments
Steve:

This week I needed to set up connections to 4 different Windows servers, each hosted at the same hosting provider. They will be running different components of one application, so I’ll probably be accessing all of them at once. Simple enough, except that in order to connect to the servers I need to access the hardware VPN that is located in our office on the other side of the country!


I knew that I needed to set up a SSH tunnel from my laptop (a MacBook) to the servers, but I certainly did not want to open 4 different shells each time I wanted to connect to all the servers. Each of the 4 tunnels needs to pass through the same server located within the firewall at our office.


Thankfully, the ssh command allows you to specify multiple tunnels through the same server in one command. The command to do this is: ssh -L :: -L :: @ So, say that I wanted to set up local ports 10001 and 10002 to connect to a couple of servers at securedomain.com and tunnel through trusteddomain.com.


he command would then look like: ssh -L 10001:one.securedomain.com:3389 -L 10002:two.securedomain.com:3389 steve@tunnel.trusteddomain.com Hope this helps someone else out!

About Steve
Steve Ratay is a software developer for Phase2 Technology, specializing in the development of custom web sites. He has designed, developed and maintained a variety of Java and PHP websites and also implemented several content management and ...

more >

Read Steve's Blog

Comments

by Stuart (not verified) on Sun, 08/02/2009 - 17:16

Sure does!

Thats Steve, yes that is useful to me. Thanks for sharing and keeping it real! :0)

by James (not verified) on Wed, 08/12/2009 - 19:48

Tunnel multiple ports with one command

When tunneling a port through ssh, sometimes one port is not enough. Meaning, I need to be able to tunnel a few specific ports (i.e. 80, 514, 8080) or a range (10000 to 20000).

How would either of these be possible?

Thanks in advance.

by Anonymous (not verified) on Tue, 01/19/2010 - 16:29

reverse-tunnel multiple ports

I am reverse-tunneling multiple prots, but it does not work:

ssh -T -R 30065:localhost:30065 -R 5900:localhost:5900 -p 30064 xxx.xxx.xxx.xxx

I cannot get the two desired connections at the same time (one is VNC, the other is sftp?) authentication issues comeup like: fingerprint has changed or something like that, when I try initiate the 2nd service. any help appreciated

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <strong> <code> <p> <img> <ul> <ol> <li> <h2> <h3> <h4> <b> <u> <i>
  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.