I could not understand what bind_ip
in mongodb is. I could make a remote connection from desktop to the EC2 machine by having bind_ip = 0.0.0.0
, but could not make it work with bind_ip = 127.0.0.1
.
Please explain me what bind_ip is and why it works for 0.0.0.0
and not for 127.0.0.1
.
For reference from mongodb docs:
bind_ip
Default: All interfaces.
Set this option to configure the mongod or mongos process to bind to and listen for connections from applications on this address. You may attach mongod or mongos instances to any interface; however, if you attach the process to a publicly accessible interface, implement proper authentication or firewall restrictions to protect the integrity of your database.
You may concatenate a list of comma separated values to bind mongod to multiple IP addresses.
Before binding your server to 0.0.0.0, please be clear about the security implications of those changes: Your server will be publicly exposed to all IPs on the whole internet. Be sure to enable authentication on your server!
You can't access your machine when you bind it to 127.0.0.1
on EC2. That's not a bug, it's reasoned by the network interface bindings.
127.0.0.1
will only bind to the loopback interface (so you will only be able to access it locally), while 0.0.0.0
will bind it to all network interfaces that are available.
That's why you can access your mongodb on EC2 when you bind it to 0.0.0.0
(as it's available through the internet now) and not via 127.0.0.1
.
For local servers (like a WAMP or a local mongodb server) that won't look different to you, but for that case you should also thing that binding to 0.0.0.0
for local servers might make them available over all network interfaces (so it might be public for someone who knows your IP, if there is no firewall!)
Read on a similar question on Server Fault here.