3

I am trying to setup my MongoDB dev environment using Azure VM. The VM is up and running MongoDB 2.6.6, and I can SSH to the VM and run MongoDB just fine..

However, I am unable to connect to Mongo from any external client (i.e. cmd shell mongo client, or robomongo). I'm using the public IP given to me, and using the default port. I've also tried to edit the /etc/mongodb.conf to specify the port number (port=27017), and have restarted the service.. but that didn't seem to make a difference at all..

David Makogon
  • 69,407
  • 21
  • 141
  • 189
Eyal Zinder
  • 614
  • 1
  • 8
  • 21

2 Answers2

6

I'm assuming this will be moved to ServerFault. In the meantime: There are two things required for external access, if you just spun up a new MongoDB instance:

  1. In mongod.conf, the default configuration for bind_ip is 127.0.0.1, which means mongod is bound to the local interface. Comment out this line to listen on all interfaces
  2. Azure-specifically: Make sure you created an input endpoint to allow external traffic to reach the MongoDB VM. You can use any port for the external-facing side, and just have it map to 27017 internally. From a convention perspective, It makes sense to use 27017 both externally and internally, since that's the default MongoDB port.
David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • Can you add more details about "2 Azure-specifically" ? – Roman Borovets Mar 13 '18 at 12:35
  • I answered this in 2014, when "Classic" VMs were the only option and you had to explicitly define a port (an input endpoint) as part of the VM's configuration in Azure. This is now part of a VM's Network Security Group (with VMs created via Resource Manager). There is plenty of documentation about this. Point is, you still need to open a port externally to the VM, allowing inbound traffic, if you want to reach it from outside of your local VNet. – David Makogon Mar 13 '18 at 12:40
  • Thanks! I had an issue because I was trying run mongo not as service but as manually start - so I had to use --bind_ip_all parameter – Roman Borovets Mar 13 '18 at 12:55
2

The port that mongodb uses is not open for external access. One way you can access it from the client is to open ssh tunnel. Default port for mongodb is 27017: ssh -f -L 27017::27017

Read more on ssh tunneling here: http://blog.trackets.com/2014/05/17/ssh-tunnel-local-and-remote-port-forwarding-explained-with-examples.html

Gennadiy
  • 326
  • 1
  • 3