How do I set up two hop ssh tunneling

Posted on 2011-10-14
Medium Priority
Last Modified: 2012-08-13
I have a gateway system which is connected by vpn to a remote server.  I can ssh (or vnc) to the gateway from my host system and then ssh (or vnc) to the remote.  I would like to do this in one step, by creating a tunnel from the host system to the remote via the gateway.

I can create a local tunnel on the gateway system using ssh:
  [host] $ ssh gateway
  eager@gateway's password: ********
  [gateway] $ ssh -N -L 1234:remote:22 -f remote
  eager@remote's password: *******
  [gateway] $ ssh localhost -p 1234
  eager@localhost's password: *******   [password for remote]
  [remote] $

If I try to connect to the gateway port 1234 from the host system, it fails:
  [host] $ ssh gateway -p 1234
  ssh: connect to host gateway port 1234: Connection refused

Is there a way to set up a two hop tunnel:
  host:1234 ==> gateway:1234 ==> remote:22

Can this be done with SSH?  Or VPN?  
Question by:eager

Accepted Solution

parparov earned 2000 total points
ID: 36969540
You are doing it the wrong way.

The correct tunnel setting would be:
[host] $ ssh -N -f -L 1234:remote:22 gateway
eager@gateway's password: ******
[host] $ ssh -p 1234 localhost
eager@remote's password:

Open in new window


Author Comment

ID: 36969628
Thanks.  That was my confusion.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re involved with your company’s wide area network (WAN), you’ve probably heard about SD-WANs. They’re the “boy wonder” of networking, ostensibly allowing companies to replace expensive MPLS lines with low-cost Internet access. But, are they …
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question