1

I have two computers within the same network. One of them is a server, which serves a publicly accessible website; the other one is for my daily use.

Both computers are using Microsoft technologies. (Windows Server 2019/Windows 10)

I have a MongoDB instance running on the server, and I want to connect it using my daily PC.

However, if I try to connect to the MongoDB instance (mongodb://192.168.50.33:27017, 192.168.50.33 is the local IP address of the server PC, 27017 is the port for the instance), it always timeout using

  • Google Chrome: If the connection works, I should see a message saying It looks like you are trying to access MongoDB over HTTP on the native driver port..
  • MongoDB Compass: If the connection works, I should be able to see the content inside the database.

I have tried/setup the following:

  • Setup an inbound firewall rule with the following properties:

    • Allow connections
    • Protocol: TCP
    • Ports:
      • Local: All ports
      • Remote: 27017
    • Scope: Any Local/Remote IP addresses
    • Apply to Domain, Private, Public
  • Checked the firewall log. Saw that the connection from my daily PC is allowed through the firewall.

  • Set up a port forwarding on the router (ASUS RT-AC58U) which connects to both of my computers with the following properties:

    • Port Range: 27017
    • Local Port: 27017
    • Local IP: 192.168.50.33
  • Set the net.bindIp of the configuration of the MongoDB instance to be 0.0.0.0

Any ideas?

RaenonX
  • 101
  • 3
  • 9

1 Answers1

3

bindIp value in mongodb config file should have the address of your server/lan as well to access.

net.bindIp=0.0.0.0,192.168.50.33

for more info you can visit the below link: https://mkyong.com/mongodb/mongodb-allow-remote-access/

Download the app from the below link and also check if you can ping to mongodb server from 27017: https://www.elifulkerson.com/projects/tcping.php

tcping.exe 192.168.50.33 27017

And use mongo client to check if you can connect, below is the command:

mongo --host 192.168.50.33 --port 27017

If this also does not help try starting the mongodb using the below commands and then try to access them:

mongod --bind_ip=192.168.50.33 --port=27017

mongod --bind_ip_all --port=27017 (works only if mongodb is 3.6 or greater)

Let me know the what happens.

Community
  • 1
  • 1
Prashanth Kumar B
  • 566
  • 10
  • 25
  • I changed the config file of the database to what you stated in the answer, still timing out. My firewall setup is quite similar to the link you provided. Still not working :( – RaenonX Jan 31 '20 at 01:52
  • Hmmm....Can you check if you can ping to mongodb system from the system you are trying to access through port number 27017, I have updated my answer for the application you can use to ping – Prashanth Kumar B Jan 31 '20 at 01:55
  • 4 Probes with all "No response" using tcping, NetwordTimeout caused by Socket operation timed out yielded by the mongo shell – RaenonX Jan 31 '20 at 02:05
  • ok try starting your mongodb using the commands mentioned in the answer, updated just now....! – Prashanth Kumar B Jan 31 '20 at 02:20
  • Still timed out for both of the commands. For the first one, I cannot connect it on the computer which has the database as expected. For the second one, it seems that the connection request was not received at the MongoDB side because the log did not have any updates when I try to connect the instance from my daily PC – RaenonX Jan 31 '20 at 02:56
  • Can you check and be sure if the port itself is open on windows server, to check you can use the below command: netstat -na | find "27017" Let me know what is the output – Prashanth Kumar B Jan 31 '20 at 03:03
  • Describe it in texts might be a mess so I uploaded the screenshot of it https://i.imgur.com/wDI5Ezi.jpg Thanks for your help in advance :) – RaenonX Jan 31 '20 at 04:47
  • Looks like only locahost(127.0.0.1) has port 27017 open, can you stop mongodb service and run this command (mongod --bind_ip=192.168.50.33 --port=27017) and then run this command (netstat -na | find "27017") let me know the output – Prashanth Kumar B Jan 31 '20 at 05:03
  • https://i.imgur.com/1L35txd.jpg Here's the screenshot after executing `mongod --bind_ip=192.168.50.33 --port=27017` – RaenonX Jan 31 '20 at 13:29
  • Sorry it was a weekend, was not near my laptop could not reply. ok now you should be able to connect to this machine from outside, if the port is open as TCP to accept connections on your windows server. were you...? – Prashanth Kumar B Feb 02 '20 at 22:11
  • Unfortunately no. After executing `mongod --bind_ip=192.168.50.33 --port=27017`, I attempted to connect to the instance via both LAN and WAN, both timed out. My firewall rule is set as stated in the question. It should be equivalent to "open as TCP to accept connections on your windows server." – RaenonX Feb 03 '20 at 00:10