Tunneling mongodb using ngrok - mongodb

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:admin#5e825c82.ngrok.io/testDb");
I would like to know how to establish a connection to the MongoDb with ngrok.

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.
Sign up for an ngrok account at https://dashboard.ngrok.com/get-started
Run locally the command shown on this page in the box 3. Connect your account (eg. ngrok authtoken 123ABC456ETC)
Now try that command again (ngrok tcp 27017)

Related

How to Connect using Port Forwarding Database Postgrsql on Openshift 3

I Have a problem on Connect from Port Forwarding Database on Openshift :
Running Pods Postgresql :
I Try Connect to Container running the database to check process and psql command, then it works :
Next, I Try Port Forwarding for Try Connection from outside Openshift Cluster:
Then I Try Connect from Outside Cluster to connect Postgresql have Error: Connection Refuse
Im Using IP Based or Hostname / FQDN Not Working and Error Still Exist
And When I Try Check Firewall port it has been opened port 5432/TCP :
Anyone Can Help Me With This problem ?
Thanks
Note: Before I have Been Looking Documentation but Not Working Resolve the Problem
Source Documentation:
https://www.openshift.com/blog/openshift-connecting-database-using-port-forwarding
"psql: could not connect to server: Connection refused" Error when connecting to remote database
The oc port-forward command is forwarding from only your loopback interfaces.
If you are running your client on the same machine where the cluster is running, then use localhost as your "Host".
If you are running your client on a different machine, they you need more network redirection to get this to work. Please see this post for more information as well as work-arounds for your problem: Access OpenShift forwarded ports from remote host

php: fbird_connect(): Unable to complete network request to host "localhost". Failed to establish a connection [duplicate]

I'm trying to connect to a remote Firebird database "test" (alias already added). It is not an embedded server, and is installed on VM with IP 192.168.1.147.
Here is my connection string:
User=sysdba;Password=masterkey;Database=test;DataSource=192.168.1.147
However I got an error:
FirebirdSql.Data.FirebirdClient.FbException (0x80004005): Unable to complete network request to host "192.168.1.147". ---> Unable to complete network request to host "192.168.1.147".
I've done some research on that but haven't got a clue yet. Some help needed. Thanks
My IP address is 192.168.2.108, and I can ping that server IP successfully
Make sure that
Firebird is running
Firebird is listening on port 3050 on the specified IP (or on 0.0.0.0)
Your firewall allows access to port 3050
You're using the correct host name
For Linux, the Firebird port is closed by default. You need to modify RemoteBindAddress in /etc/firebird/2.5/firebird.conf from
RemoteBindAddress = localhost
to
RemoteBindAddress =
and restart service.
Make sure you have excluded tcp port 3050 in VMs' firewall.
Ok. I think your connection to firebird is faililing because the firebird client looks up the network service file by name and does not find gds_db in the services file.
If your connection string refers to the host by using IP, the Client might fail to identify it because it gethostbyname() and not by IP
Manually include this in the file and you should be fine.
C:\windows\system32\drivers\etc\services

How to configure HAProxy to forward requests to Mongo database

Is it possible to setup/use HAProxy to forwards requests to a mongo database? If so can someone provide a basic example of how to set this up in the haproxy.cfg file?
I tried this, but this doesn't work:
listen mongo
bind 10.123.45.6:27017
mode tcp
balance roundrobin
server mongo1 10.456.78.9:27017
Where 10.123.45.6 is the IP of instance w/ HAProxy installed.
Where 10.456.78.9 is the IP of instance w/ mongodb installed.
Screenshot when trying to invoke client via command line:
C:\Program Files\MongoDB\Server\3.6\bin>mongo "mongodb://10.123.45.6:27017"
MongoDB shell version v3.6.11
connecting to: mongodb://10.123.45.6:27017/?gssapiServiceName=mongodb
2020-01-23T15:53:41.707-0800 W NETWORK [thread1] Failed to connect to 10.123.45.6:27017 after 5000ms milliseconds, giving up.
2020-01-23T15:53:41.707-0800 E QUERY [thread1] Error: couldn't connect to server 10.123.45.6:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:263:13
#(connect):1:6
exception: connect failed
Your settings are right, however I am adding an example for you
listen port_27017
bind :27017
mode tcp
server mongodb-port 10.156.78.9:27017
It should connect, but just to confirm from where are trying to connect? Is it within the local network or somewhere from the cloud. Because as per RFC 1918 all the 10.0.0.0/8 belong to private network, if you are outside the network and trying to access the 10.123.45.6 it won't work.
And if it is within network, and try to tail the log of HAProxy and see if it is able to connect to the Mongo or not.
If it is outside, you need to connect to HAProxy using it's public IP address rather than private IP.

Not able to connect on Mongodb Atlas port

I'm using an M0 GCP instance.
I can connect to the cluster using this string:
'mongodb+srv://my_user:my_pass#my_cluster-mbsnz.gcp.mongodb.net/db?retryWrites=true&w=majority'
I'm trying to use another client where I need to pass host and port, but I can't connect.
I tried telnet to the port 27017, but for some reason I'm not able to connect directly on the port.
curl http://my_cluster-mbsnz.gcp.mongodb.net:27017
curl: (7) Failed to connect to my_cluster-mbsnz.gcp.mongodb.net port 27017: Connection timed out
or
telnet my_cluster-mbsnz.gcp.mongodb.net 27017
Trying 185.82.212.199...
^C -> After a long time waiting
What might be wrong ?
+srv urls use a DNS seed. On atlas, you can click into the cluster and you should be able to see the urls for your primary & your secondaries and use those urls to connect. You should also be able to use nslookup to get that info using part of that connection string, but it's probably simpler to just look up the urls through the UI.
https://docs.mongodb.com/manual/reference/connection-string/
In order to leverage the DNS seedlist, use a connection string prefix of mongodb+srv: rather than the standard mongodb:. The +srv indicates to the client that the hostname that follows corresponds to a DNS SRV record. The driver or mongo shell will then query the DNS for the record to determine which hosts are running the mongod instances.

EC2 Internal Sockets

I'm trying to have two process communicate through a socket connection. One of these is a python app, and the other is a php script.
I've created and tested the client/server combination on my home computer and it functions properly. However, when I deploy onto an EC2 instance (ubuntu 10.10 64bit ami + apache + php) I get an unable to connect to socket error (111 Connection Refused) from the php script. The python app is able to bind to the socket and listen to messages but the php script is unable to send messages.
I've opened the required ports in the amazon security group and I can connect to the port externally using telnet. However if I attempt to connect with telnet from within the server I get the same connection refused error.
How can I solve this issue?
Edit: Both processes are on the same instance
The issue had nothing to do with EC2 explicitly. I was not binding to localhost, but instead binding to my hostname. On a local network that was the same as my localhost ip, however on ec2 it was not. Switching to binding to localhost fixed the issue.