Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tunneling mongodb using ngrok

I have a MongoDb hosted locally in my machine and runs successfully in port localhost:27017. The database has a user name and password with a collection named, "testDb". In the code, I am able to access the database successfully using localhost.

I am trying to access this MongoDb from a remote desktop using ngrok. I hace implemented the port forwarding and the following response is shown in the command prompt.

Forwarding https://5e825c82.ngrok.io -> http://localhost:27017

I also tried changing the port => Forwarding https://5e825c82.ngrok.io -> http://localhost:28017

Both ports failed with the following Error message: The connection to http://5e825c82.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:28017. Make sure that a web service is running on localhost:28017 and that it is a valid address. The error encountered was: dial tcp [::1]:28017: connectex: No connection could be made because the target machine actively refused it.

// Works fine
MongoClient client = new MongoClient("mongodb://admin:admin@localhost:27017/testDb");

// Fails:
MongoClient client = new MongoClient("mongodb://admin:[email protected]/testDb");

I would like to know how to establish a connection to the MongoDb with ngrok.

like image 474
deeepss Avatar asked Jul 26 '19 12:07

deeepss


People also ask

Are Ngrok tunnels safe?

The communication between the ngrok edge and agent is secure and encrypted. Traffic from the user to the ngrok edge, and from the ngrok agent to the upstream service rely on the protocol you are using for encryption. For protocols that support end to end encryption using TLS, we provide a TLS tunnel option.

Does Ngrok support FTP?

FTP Server: ngrok tcp 21. SFTP Server: ngrok tcp 22.


1 Answers

MongoDB uses TCP not HTTP.

Try following command :

ngrok tcp 27017

(note the tcp, not http which I think is what you used)


There are a couple of extra steps you need to do for some reason when you use TCP, and ngrok will prompt you and tell you what you need to do when you try the above command.

  1. Sign up for an ngrok account at https://dashboard.ngrok.com/get-started
  2. Run locally the command shown on this page in the box 3. Connect your account (eg. ngrok authtoken 123ABC456ETC)

enter image description here

  1. Now try that command again (ngrok tcp 27017)
like image 55
kris Avatar answered Oct 11 '22 23:10

kris