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

1
  • Are you using the private IP? Is there an Elastic IP attached to EC2?
    – raevilman
    Mar 23, 2018 at 8:34

2 Answers 2

19
+200

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

5
  • 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, 2018 at 10:09
  • The machine on which MongoDb is installed. This conf file will be under where MongoDb is installed.
    – raevilman
    Mar 23, 2018 at 10:22
  • I've commented this line, but no change, still getting the same error.
    – Alon
    Mar 23, 2018 at 12:35
  • Did you try the other way, providing the value e.g. 0.0.0.0? Check this stackoverflow.com/questions/17588876/…
    – raevilman
    Mar 23, 2018 at 13:11
  • Awesome great! I'll update the answer for future reference.
    – raevilman
    Mar 23, 2018 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.