This example is related to MongoDB but the core issue is with SSH tunneling, MongoDB stuff should add value though
Hi,
I'm attempting to bring up a local MongoDB node which is part of a ReplicaSet based in a data-centre. TCP/IP will be tunneled over SSH from local to data-centre.
All boxes, local and data-centre, are running CentOS.
This works fine when creating a tunnel on data-centre box1 to local node using:
ssh -v -4 -f -N -o TCPKeepAlive=no -o ServerAliveInterval=15 -L27017:127.0.0.1:27017 -g a_user@server_i_have_ssh_access_to
box1 can access the local node Mongo shell with command (cmd 1):
mongo --host localhost --port 27017
box2 can also access the local node Mongo shell with command (cmd 2):
mongo --host box1 --port 27017
box2 in the data-centre can also connect to the box1:27017, the forwarded port of my local node.
however, it would be much preferable, simpler, and should be possible to setup a reverse forward between local node and box1 on the same ports as above. Using the command:
ssh -v -4 -f -N -o TCPKeepAlive=no -o ServerAliveInterval=15 -R27017:127.0.0.1:27017 -g a_user@box1
now i can connect from box1 to local node using cmd 1 above, however, cmd 2 fails with:
Error: couldn't connect to server box1:27017} (anon):1139 exception: connect failed
Any ideas?