1
votes

Case 1. I installed mongo on my machine (Mac OS), and mongo is configured with bind-ip : 127.0.0.1. A remote machine in LAN can connect to my mongodb using my IP. (Wrong observation : See UPDATE section)

Case 2. I installed mongo on Azure Ubuntu VM, mongo configured with bind-ip:127.0.0.1. No remote machine from the same VNet can connect to that mongo using private vnet IP.

MongoDB Network Setting (both case 1 and case 2):

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1  

Exception (Case 2):

2018-04-03 06:35:29.948 INFO 44518 --- [72.17.1.4:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server 172.17.1.4:27017

com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.4.1.jar!/:na] at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongodb-driver-core-3.4.1.jar!/:na] at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) ~[mongodb-driver-core-3.4.1.jar!/:na] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151] Caused by: java.net.ConnectException: Connection refused (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_151] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_151] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_151] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_151] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_151] at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_151] at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57) ~[mongodb-driver-core-3.4.1.jar!/:na] at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongodb-driver-core-3.4.1.jar!/:na] ... 3 common frames omitted

Whats is different in Azure VM that it behaves differently from a Mac OS installation?

Note: Changing the bindIp to the IP (172.17.1.4) or 0.0.0.0 works.

UPDATE:

Case 1: The remote access on my local machine's mongo was because of the distribution I picked which was configured to allow remote connections.

1
Based on my knowledge, 127.0.0.1 only works inside the machine, do you ensure you could access Mogodb outside your MAC OS?Shui shengbao
See this link, By default, MongoDB bind to local interface only, it will restrict the remote connections. If you don’t care about security, just comment out to accept any remote connections (NOT Recommend).Shui shengbao
yes @ShengbaoShui-MSFT , with Mac OS , remote machines can connect. When I install on Window or Ubuntu, remote cannot connect. It seems like a issue with Mac OS, unrelated to Mongo or Azure. Whats your opinion?Mohitt
On Azure, I suggest you configure like bind_ip = 127.0.0.1,172.17.1.4.Shui shengbao
In fact, if you want to a service could remote access, you could not configure listen it on 127.0.0.1, you should set it listen on VM's private IP or 0.0.0.0.Shui shengbao

1 Answers

2
votes

Based on my knowledge, 127.0.0.1 only works inside machine. You could check this blog.

By default, MongoDB bind to local interface only, it will restrict the remote connections. If you don’t care about security, just comment out to accept any remote connections (NOT Recommend).

I suggest you could configure Mongodb like bind_ip = 127.0.0.1,172.17.1.4.