How to set mongod.conf bind_ip with multiple ip address

Solution 1:

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]

Solution 2:

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

Solution 3:

You can do that by:

bindIp: [172.31.60.184,127.0.0.1]

Remember to not put a space after the comma.

Solution 4:

Thanks for @wdberkeley and @anhlc brought up the clue.

I looked at the log file under /var/log/mongodb/mongod.log. It shows the failing reason for the problem.

2015-03-17T16:08:17.274-0400 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1, 192.168.184.155" }, storage: { dbPath: "/var/lib/mongodb" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2015-03-17T16:08:17.332-0400 I NETWORK  [initandlisten] getaddrinfo(" 192.168.184.155") failed: Name or service not known

So the mongo.conf file is sensitive to space, which I happened to add and should have noticed. Also just as @anhlc pointed out, 96.88.169.145 is not a valid IP address for VM. So that one also contribute to the error.

Great thanks for both of your help! Hope this may help if someone happened to run into the same problem.