MongoDB bind_ip won't work unless set to 0.0.0.0

Edit: I do not know wether I was simply wrong with my answer or if the behavior of bind_ip was changed, but it is possible to bind to multiple, distinct IPs

bind_ip:127.0.0.1,10.0.0.1,8.8.8.8

So, most likely, one of the IP addresses mongod was assigned to bind to did not exist on the machine in question.


You can bind mongod only to one IP, with 0.0.0.0 being the alias for "listen on all available network interfaces".

So either use

bind_ip=127.0.0.1

to listen to the loop back interface or

bind_ip=<someIP>

to listen to that IP only or

bind_ip=0.0.0.0

to listen to all available IPs on the system.

If you need to listen to several specific IPs, it is very likely that your system design is somehow screwed.


I had the same issue just because of the silly mistake.

There was commented line and space problem.

What I did wrong

# network interfaces
net:
  port: 27017
 #bindIp: 127.0.0.1
bindIp: privateIp

instead of

net:
  port: 27017
  bindIp: 10.1.2.4

for bind to multiples ips

bindIp: [127.0.0.1,10.128.0.2]

hopefully this answer helpful for someone.


Mongo 3.6.2 Community

The solution for me was to edit the section of /etc/mongod.conf

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,192.168.1.240   # No brackets, No spaces, only comma separated

#security

Then save and do this to restart and verify the service:

> service mongod restart
> service mongod status

No failure here, now verify that someone is listening:

> netstat -a |grep :27017

tcp   0   0  yourhostname:27017   0.0.0.0:*     LISTEN
tcp   0   0  localhost:27017      0.0.0.0:*     LISTEN

Now connect using your favorite Mongo tools or command line.

Some results of different formatting in /etc/mongod.conf

  • comma and space results in only the first IP being bound.
  • space only separator results in only the first IP being bound
  • [ ] surround results in failure to start mongod

Tags:

Mongodb