11

I have an EC2 instance (Ubuntu 14). I've defined port 27017 in its security group to be accessed from anywhere.

I'm trying to connect from my PC (Windows 10) to the EC2 instance, but getting the following error:

MongoDB not running on the provided host and port

which is not true since I've made sure that MongoDB is running.

These were the settings I specified:

enter image description here

I've also tried to use SSH (which is also defined in the sercurity group and works well through terminal), but got the following error:

Error creating SSH Tunnel: (SSH) Channel open failure: Connection refused

These were the settings I specified:

enter image description here

Alon
  • 10,381
  • 23
  • 88
  • 152

2 Answers2

19

Alon,
Checkpoints

  1. See if there is a need to change the bind_ip variable at the /etc/mongodb.conf file.
    By default, it is locked to localhost.
    Try setting the value to 0.0.0.0 or assign the IP that will be able to connect the DB to it.
  2. Port is allowed in security group attached to EC2 (You mentioned its done)
  3. Not using private IP to connect (I guess, you are using the right one as you connected through terminal)
  4. Rare case, OS firewall

I guess point 1 should do the trick. Rest points for future reference

[Update 1]
Doc link for bindIp
https://docs.mongodb.com/manual/reference/configuration-options/#net-options

raevilman
  • 3,169
  • 2
  • 17
  • 29
  • On which machine? If on the client then I use Windows so I don't think I have a path such like etc/mongodb.conf – Alon Mar 23 '18 at 10:09
  • The machine on which MongoDb is installed. This conf file will be under where MongoDb is installed. – raevilman Mar 23 '18 at 10:22
  • I've commented this line, but no change, still getting the same error. – Alon Mar 23 '18 at 12:35
  • Did you try the other way, providing the value e.g. 0.0.0.0? Check this https://stackoverflow.com/questions/17588876/mongodb-conf-bind-ip-127-0-0-1-does-not-work-but-0-0-0-0-works – raevilman Mar 23 '18 at 13:11
  • Awesome great! I'll update the answer for future reference. – raevilman Mar 23 '18 at 14:59
2

I am putting this as an answer although it is meant as a comment to the answer by raevilman above but I do not have the necessary reputation to post comments yet.

If you set the bind_ip variable to 0.0.0.0 as mentioned, MongoDB accepts connections from all IP addresses. This might be a security risk if you do not use access control.

On the other hand, if I am not wrong, the idea of a SSH tunnel is for that, in this case MongoDB, the entering connection comes from localhost so no change in the configuration should be necessary.

That said, I came here because I could not connect either. I got the error 'Error creating SSH Tunnel: Timed out while waiting for forwardOut'.

In my case the solution was to put 'localhost' in the hostname field at the top instead of the host IP.

Bastian
  • 68
  • 7