12

for mongoDB 4.0.3, unable to add multiple ips in bindIp

following config works for localhost

net:
   port:27017
   bindIp:127.0.0.1

Following works for logging from other ip:

net:
       port:27017
       bindIp:0.0.0.0

following doesn't work

   bindIp:127.0.0.1 10.0.0.10
   bindIp:127.0.0.1,10.0.0.10
   bindIp:"127.0.0.1,10.0.0.10"
   bindIp:"127.0.0.1 10.0.0.10"
   bindIp:[127.0.0.1,10.0.0.10]
   bindIp:[127.0.0.1, 10.0.0.10]

any ip other than 0.0.0.0 or 127.0.0.1 gives error for bindIP

If I try following:

bindIp:10.0.0.10
ERROR: child process failed, exited with error number 48

this MongoDB Doc doesnt help

Any help will be appreciated.

cartman619
  • 552
  • 4
  • 17

4 Answers4

8

Use ; I used in Mongo 4.2.2 version

 net:
   port: 27017
   bindIp: 127.0.0.1;10.0.1.149
paul
  • 519
  • 6
  • 13
  • Awesome!Using Mongodb version 4.4.4. Only this solution worked for me. – owgitt Feb 26 '21 at 09:20
  • I tried this for 4.4.6, I am able to restart the server without any problem -until here seems fine your answer, but is impossible do the connection through the `mongo` command even from the server itself - do the following - https://stackoverflow.com/a/67605049/3665178 – Manuel Jordan May 19 '21 at 14:18
  • If I am correct your query are 1.After restart you could not access Mongo : Please check Public IP, may be it change. 2. how to access mongo from server terminal: sudo mongo --host localhost --username EXISTINGUSERNAME --password EXISTINGPASSWORD --authenticationDatabase admin – paul May 21 '21 at 15:54
7

The documentation you linked actually does have the answer to this. If you go here, you will see that the indicate:

To bind to multiple addresses, enter a list of comma-separated values.

EXAMPLE

localhost,/tmp/mongod.sock

I applied this in my environment and can see that mongod is listening on local and the designated IP.

root@aqi-backup:~# netstat -pano | grep 27017
tcp        0      0 10.0.1.149:27017        0.0.0.0:*               LISTEN      12541/mongod         off (0.00/0/0)
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      12541/mongod         off (0.00/0/0)

Here is my mongod.conf file (relevant section).

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,10.0.1.149
technicallynick
  • 1,562
  • 8
  • 15
  • 2
    One thing I did find is that you can't bind to an IP that isn't bound to an interface. The mongod service simply won't start if you typo the IP. – technicallynick Oct 25 '18 at 18:19
1

The only way that I found was open for all on MongoDB and control IPs t by firewall to specifics ips. net: port:27017 bindIp:0.0.0.0

0

Here Is The Simplest Configuration of BindIp Value for MongoDB above 4.X version mentioned by subhash sautiyal

  1. vim /etc/mongod.conf

  2. bindIp: 127.0.0.1;182.58.65.45;165.165.66.8

  3. sudo service mongod restart

  • Do those IPs map back to something the person asking the question is using? Is that always the location of the config file? – user20042973 Oct 17 '22 at 22:51