Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have installed mongoDB on a redhat virtual machine on EC2.

The server is running perfectly locally, I can connect and execute commands, etc. Now, I tried connecting remotely from another virtual machine on EC2 but I can't get to connect regardless how much I'm trying. At first I thought it was a problem of security groups, so I tried enabling all ports from within the group (both virtual machines belong to the same secirity groups) I also enabled connections in the iptables file (and yes, restarted the service) but it still doesn't work... Any ideas on what the problem could be?

the error I get is:

MongoDB shell version: 2.0.2
connecting to: ec2-XXXX.eu-west-1.compute.amazonaws.com/test
Thu Jan  5 13:55:32 Error: couldn't connect to server ec2-XXXX.eu-west-1.compute.amazonaws.com shell/mongo.js:86
exception: connect failed

Thank in advance.

Regarding the "bind_ip" setting, well.. there is no default value for that, I mean there even is no bind_ip line on the mongodb.conf, by default. I was probably expecting something like bind_ip = so that I could comment it out, but it wasn't there, so I tried with bind_ip = but still, it's not working either.

share|improve this question

4 Answers 4

up vote 5 down vote accepted

SOLVED! to anyone who is using EC2 default redhat installation, you need to run this command:


share|improve this answer
Does this work only for redhat? I mean I have Ubuntu installed on EC2 and just wondering to access to MongoDB remotely and ended up here. Thanks –  Maziyar Mar 24 '13 at 11:57

Hopefully this helps. You need to explicitly tell mongodb to listen on non-localhost devices. By default it runs only on localhost.

From http://www.mongodb.org/display/DOCS/Security+and+Authentication:

IP Address Binding By default, a mongod server will listen on all available IP addresses on a machine. You can restrict this to a single IP address with the 'bind_ip' configuration option for mongod.

Typically, this would be set to, the loopback interface, to require that mongod only listen to requests from the same machine (localhost).

To enable listening on all interfaces, remove the bind_ip option from your server configuration file.

Update: I guess I was confused myself. I thought the default behavior was different than what was described above. (Maybe it used to be?) In any case, you should check your mongo config file to make sure that you have it configured as you expect.

share|improve this answer
oh yes, I checked on that too, regarding the "bind_ip" setting, well.. there is no default value for that, I mean there even is no bind_ip line on that, by default. I was probably expecting something like bind_ip = but it wasn't there, so I tried with bind_ip = but still, it's not working... –  Enrico Tuttobene Jan 6 '12 at 0:32
On Ubuntu, in the /etc/mongod.conf file, it says to simply remove the line that sets bind_ip altogether, and that will allow mongo to listen to all interfaces. (Commenting out this line fixed it for me). –  KEW May 23 '14 at 21:32
This did it for me , commenting out the bind_ip line worked. Thanks. Can't believe I wasted half hour for this –  blueskin Jul 31 at 15:30

Glad to see that the firewall modification solved the issues. Don't forget the other EC2 recommendations (noatime on filesystem, communication across regions and others) here:


There is also an excellent whitepaper on how to scale and deploy on EC2:


share|improve this answer

If you are using aws, make sure that the security group allows port 27017. I wasted two hours of my life figuring that out.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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