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 need to connect to a DB server which accepts connections on port 1521, I can only access this from a remote machine which I need to ssh in to through another gateway.

ie from home

home $ ssh user@gateway

gateway $ ssh desktop

desktop $ < I now have access to port 1521 on host dbserver >

What are the commands I need to use for this, so that I would then connect to localhost:1521 on home pc for db connections

share|improve this question

1 Answer 1

Two ways of chaining:


  1. Connect from home to gateway, forwarding localhost:1521 on home via gateway to localhost:PORT.

  2. Connect from gateway to desktop, forwarding localhost:PORT on gateway via desktop to dbserver:1521.

home$ ssh -ftL 1521:localhost:PORT gateway ssh -NL PORT:dbserver:1521 desktop

PORT can be 1521 or any other port.


  1. Connect from home to gateway, forwarding localhost:PORT on home via gateway to desktop:22.

  2. Connect from home to desktop using the established tunnel via gateway, forwarding localhost:1521 on home via desktop to dbserver:1521.

home$ ssh -fNL PORT:desktop:22 gateway
home$ ssh -fNL 1521:dbserver:1521 -o "HostkeyAlias=desktop" -P PORT localhost
DB connection can be made now

(The -fN options tell SSH to connect, establish tunnels, then continue running in background.)


The second method is more useful, since it allows you to reach desktop directly from home (using the running tunnel) for all kinds of connections.

share|improve this answer
    
Thanks for posting that answer, I now realise I'm actually up against an altogether bigger problem as the dbserver just listens on that port, it immediately opens another port for communication. Think this is trickier than I can handle... –  Alasdair Feb 8 '12 at 16:56

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.