4

I am trying to bind multiple IP to mongodb config file, one is 0.0.0.0 and other is 127.0.0.1. I did the following change in configuration file

/etc/mongod.conf

# network interfaces
net:
  port: 27017
  bindIp: "0.0.0.0,127.0.0.1"

Than I reloaded the configuration by the following command

sudo mongod --config /etc/mongod.conf

Than checked if the server is listening on localhost as well or not by the following command.

netstat -tlpn

It shows the output only for 0.0.0.0

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      -

Why is it not listening to localhost as well?

  • 4
    The IP address 0.0.0.0 means all IP v4 addresses (which includes 127.0.0.1). You could achieve the same outcome by not specifying any bindIp address, as "bind to all IP addresses" is the default behaviour as at MongoDB 3.2. Have you tried connecting to mongod via localhost, and if so was there any error? What are you trying to achieve with multiple IP addresses? The bindIp configuration determines what IP address(es) mongod listens on if your server has multiple addresses, but you still need to configure appropriate firewall settings. – Stennie Nov 29 '15 at 3:21
2

had the same issue and the thing is everywhere it's written that you have to bind them like this

bindIp : 127.0.0.1,192.168.0.50

but that doesn't work.

The MongoDB version 3.2.x have the following configuration and its working for me.

    bindIp : [127.0.0.1,192.168.0.50]

    example :

# network interfaces
net:
      port: 27017
      bindIp : [127.0.0.1,10.12.2.1,10.12.65.1]
| improve this answer | |
1

The IP addresses and/or full Unix domain socket paths on which mongod should listen for client connections. You may attach mongod to any interface. To bind to multiple addresses, enter a list of comma-separated values.

EXAMPLE
localhost,/tmp/mongod.sock

WARNING: Before you bind to other ip addresses, consider enabling access control and other security measures listed in Security Checklist to prevent unauthorized access.

Note: Starting in MongoDB 3.6, mongod bind to localhost (127.0.0.1) by default. See Default Bind to Localhost.

To bind to all IPv4 addresses, enter 0.0.0.0.

To bind to all IPv4 and IPv6 addresses, enter 0.0.0.0,:: or alternatively, use the net.bindIpAll setting.

Note : --bind_ip and --bind_ip_all are mutually exclusive. That is, you can specify one or the other, but not both.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.