cartman619
cartman619

Reputation: 552

bind multiple IP in mongoDb 4.x.x

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.

Upvotes: 12

Views: 7867

Answers (4)

Subhash Sautiyal
Subhash Sautiyal

Reputation: 51

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

Upvotes: 0

paul
paul

Reputation: 469

Use ; I used in Mongo 4.2.2 version

 net:
   port: 27017
   bindIp: 127.0.0.1;10.0.1.149

Upvotes: 8

Suporte GEE2
Suporte GEE2

Reputation: 11

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

Upvotes: 1

technicallynick
technicallynick

Reputation: 1592

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

Upvotes: 7

Related Questions