0

I'm using Ubuntu and trying to connect to a database server wich is accessed by a tunnel in my server wich is inside a router and I only have ssh connection to my server. Is there a way to do that?

For make things easier, I'll try to diagram it:

me -> connect through ssh (port 22) to my server in (serverip:12345)

myserver -> has a tunnel to database server

database server -> only accepts myserverip address

*serverip:12345 is a port forwarding from my router to myserver

Thanks in advance

UPDATE

Thanks for the help @Kondybas, I tried you suggestion but it didn't work. Maybe I wasn't clear enough.

I'll try again =D.

I am in my laptop and I have access to my server through ssh. My server is behind a router (no in the same network of my laptop), so to access my server I use:

ssh -p 12345 user@myserverip

My server already has a tunnel to a distant database:

ssh -L 1521:localhost:1521 user@mydbserverip

because when I'm in the same network of my server I can access the database with 192.168.0.X:1521

Since I can't touch in the router (the one who forward port 12345 to my server) and I can't create a direct tunnel to the database.

Is there a way to access the database from my laptop going through my server?

Thanks again.

0

2 Answers 2

1

You have to launch ssh in such way:

ssh -f user@server -p 12345 -L localhost:3306:dbserver.ip:3306 -N

Explanation:

ssh -f user@myserver -p 12345 - connect to the myserver on the port 12345

-L localhost:3306:dbserver.ip:3306 - all packets destinated to the localhost:3306 will be forwarded to the dbserver.ip:3306 through the myserver. You can use FQDN or IP for dbserver.

-N - no explicit or implicit commands will be issued in that session

0

What Kondybas told was correctly...I will only complement a little :D

After reading a lot and talking to a few people, the solution is:

ssh -p 12345 user@myserver -L 9999:127.0.0.1:3306

explaining:

  • -p 12345 is the port that we forwarded in our router in order to access myserver
  • user@myserver is the user and the ip address of myserver
  • -L 9999:127.0.0.1:3306 says that all connections in my localhost on port 9999 will be redirect to myserver (that's why I'm using the 127.0.0.1, because the tunnel is already created) in port 3306

this last part allows me to user the tunnel already created to mydbserver

1
  • That is not obvious because you mentioned that only myserver can connect to the dbserver. If you can ssh to the dbserver from everywhere, than things can be simpler, indeed.
    – Kondybas
    Commented Apr 5, 2015 at 12:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .