How to set mongod.conf bind_ip with multiple ip address

yeelan picture yeelan · Mar 17, 2015 · Viewed 77k times · Source

I am a newbie for setting up the server environment and mongoDB. This may sounds something really simple, however, I really need your help on it.

I am trying to connect to my virtual machine which runs the mongodb instance from the local machine, which I believe should be similar to the production environment when I run it on a separate remote server.

The environment is as following:

  • Private IP for virtual machine: 192.168.184.155

  • Public IP for both local machine and virtual machine: 96.88.169.145


I changed the bind_ip in /etc/mongod.conf file from

bind_ip = 127.0.0.1

to

bind_ip = 127.0.0.1,192.168.184.155,96.88.169.145

After I restarted the mongod service, neither the virtual machine nor the local machine can access mongodb through mongodb command and giving me the following error.

MongoDB shell version: 3.0.1
connecting to: test
2015-03-17T16:02:22.705-0400 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-03-17T16:02:22.707-0400 E QUERY    Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
    at connect (src/mongo/shell/mongo.js:179:14)
    at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed

However, if I change the

bind_ip = 192.168.184.155

and restart the service, it works and I can access using mongo from my local machine. It seems just not work with multiple ip addresses. I tried to do look up in the mongodb document, however, they does mention that bind_ip takes a comma separated list, which really confused me.

Thanks for your help in advance.

Answer

Joe Cheng picture Joe Cheng · Jul 12, 2016

Wrap the comma-separated-Ips with brackets works in mongo 3.2.7 for me:

bindIp = [127.0.0.1, 192.168.184.155, 96.88.169.145]