Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set mongod.conf bind_ip with multiple ip address

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.

like image 593
yeelan Avatar asked Mar 17 '15 20:03

yeelan


Video Answer


2 Answers

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] 
like image 97
Joe Cheng Avatar answered Sep 19 '22 11:09

Joe Cheng


With the following version of MongoDB: MongoDB shell version v3.6.10

Reproducing Problem: When [127.0.0.1,xxx.xxx.xxx.xxx] is used we get the following error. Scalar option 'net.bindIp' must be a single value try 'mongod --help' for more information

Analysis This is because, according to MongoDB Documentation: https://docs.mongodb.com/manual/reference/configuration-options/#net.bindIP

net.bindIP is of type "string".

Solution for binding multiple IP Addresses

bindIp: "127.0.0.1,xxx.xxx.xxx.xxx" 

Note: No spaces after commas

like image 22
Sachin PC Avatar answered Sep 19 '22 11:09

Sachin PC