I can't seem to wrap my head around the concept of ssh tunneling. The situation I'm currently in is that I have:
- Server A, which can be accessed through ssh, and inside it there's a mysql db accessed through
- Server B, which has ssh access to A.
- MySQL instance C which has access to B. I can only access the db server, not the server itself, so I am unable to ssh anywhere from C. I can only connect to any port on B.
My goal is MySQL replication from A to C, where A is the master, and C - the slave. How should I proceed if I wanted to connect from C to A. I imagine it something like this diagram:
C ─────────B:B_PORT────────> B │││ |/─────tnl A:22────┘││ A_db <────localhost:3306─────┘│ |\─────tnl A:22──────┘
So far I tried to run this on B
sudo ssh -L B_PORT:localhost:3306 A_user@A_ip -f -N but I still can't seem to access A from C, when connecting to B_PORT.
EDIT: Also tried
ssh -L B_PORT:localhost:3306 A_user@A_ip -f -N -g as suggested by @larsks with no avail. His explanation leads me to believe there might be issues within the network
My journey so far
- Create tunnel on B with
ssh -L B_PORT:localhost:3306 A_user@A_ip -f -N -g
- Connect C to B.
- netstat on B shows multiple SYN_RECV connections from C to B
- If I try to connect to B_PORT from B I get this
packet_write_wait: Connection to A port 22: Broken pipe ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
- ssh connection is dropped on B and tunnel needs to be reopened
- Fiddled around with security groups and other network rules. Enabled network inbound and outbound from and to C and everything is working!