4 Responses to “SSH Tunneling across multiple hosts in Linux”

Accidentily, I learned about this while getting worked in a couple days ago. But I learned a few other tricks as well:

add -f, which means that ssh goes into the background after connecting, so you don’t have to leave your terminal window open

In your example, you tunnel twice for a single host, to get back to port 80. Instead, you can use -D and no tunnel, which will create a SOCKS proxy. Execute the command, configure the proxy in your browser, and you can reach any host that is reachable by Server A. If you need to SSH forward to server B, or anything else that can’t use a SOCKS proxy, then you can suffice with a single tunnel (since you don’t need to go back to the specific port).


The is a disadvantage in this approach. You are setting up two tunnels. One from local to A and one from A to B. That means that you would need an (Open)SSH deamon on your server B.

However in your situation you say that server B is accessible from Server A meaning that you actually don’t need the second tunnel right? Wouldn’t it be easier to just tunnel a non-localhost connection through server A? Something like this would probably work.

ssh -t -t -L8081:b.server.example.com:80 [email protected]

This helped. Thanks a lot for the clear post on SSH Tunneling

hey,thanks for your post,i have a problem,when i try to tunnel,i after connecting to second server.i try to reach a website,and in terminal i get “channel 3: open failed: connect failed: Connection refused”

i am trying to tunnel through main server of our department(university) to tunnel through a linux pc. it’s obvious that i don’t have root privilages on any of these systems.:D can you help me please?:)

Leave a Reply