I want to open a connection to a remote MySQL database. This database is in a private subnet on a different network, so I cannot directly open a connection to it. Remote SSH access is also completely disabled on the MySQL server.
My current process is this:
I open an SSH tunnel through a publicly available server, HOST_1. From that tunnel, I open an SSH connection to a server (HOST_2) which is on the same subnet as the MySQL server (MYSQL_HOST). Using the SSH session which I have open at that point (on HOST_2), I use the MySQL client to open a connection to MYSQL_HOST.
Here's a super-duper crude diagram of what's currently done:
What I want to do, is use my local computer's MySQL client to connect to 127.0.0.1:3306 and have the connection tunneled all of the way through from HOST_1, to HOST_2, and then to MYSQL_HOST, as though I were having the MySQL server running from 127.0.0.1 in the first place.
Again, I cannot open an SSH tunnel into the MYSQL_HOST from HOST_2, so no tunneling from there. I need to figure out how to forward the MySQL client connection through the SSH tunnel to HOST_2 and then have HOST_2 forward the MySQL client connection to MYSQL_HOST.
I thought I could maybe use redir
or nc
to achieve this. I'm unsure as to how, though.
There are a couple of questions that I've read, but don't understand everything enough to put the information together to get the answer I'm looking for:
- An SSH tunnel via multiple hops
- UDP traffic through SSH tunnel
- https://unix.stackexchange.com/questions/267090/reroute-mysql-connection-through-external-machine
I know there is information in this page again, which would help me, but I don't know how to use it: http://sshmenu.sourceforge.net/articles/transparent-mulithop.html
Thanks!