Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between mongos "bind_ip" and "bind_ip_all"

Tags:

mongodb

What is the difference between bind_ip and bind_ip_all when running mongos?

I know you can specify a list of ips with bind_ip so what is the point of bind_ip_all?

like image 238
tom dinh Avatar asked Nov 01 '25 21:11

tom dinh


2 Answers

From MongoDB Official documentation

net.bindIpAll

If true, the mongos or mongod instance binds to all IPv4 addresses (i.e. 0.0.0.0). If mongos or mongod starts with net.ipv6 : true, net.bindIpAll also binds to all IPv6 addresses (i.e. ::).

mongos or mongod only supports IPv6 if started with net.ipv6 : true. Specifying net.bindIpAll alone does not enable IPv6 support.

NOTE

net.bindIp and net.bindIpAll are mutually exclusive. Specifying both options causes mongos or mongod to throw an error and terminate.

like image 174
Mani Avatar answered Nov 03 '25 11:11

Mani


net.bindIpAll or --bind_ip_all binds all available IP addresses of the host.

With net.bindIp or bind_ip you can specify on which IP address the MongoDB shall listen. This can be useful when your computer has multiple network interfaces and you don't want to expose your MongoDB to certain interfaces. For example, you may run a bigger server which has the "normal" network interface (which typically has the same alias as the hostname of the machine) but also dedicated interfaces for managing the server or connection to backup systems.

In some databases you can use dedicated interface for synchronization/replication to separate these internal connections from normal connections of your application. However, MongoDB does not provide this feature and as of 2024 there are no plans for it, either.

net.bindIp: localhost binds only to the loopback interface, which means you can connect only from the local computer to mongod/mongos. Connections from remote computers are not possible.

net.bindIpAll, net.bindIp: ::,0.0.0.0, net.bindIp: "*" are all equivalent. Some people run into difficulties when providing a list of IP addresses. Thus, personally I prefer net.bindIpAll

Be aware of IPv4 vs. IPv6 address. By default net.bindIp: localhost and net.bindIpAll binds only to IPv4 address. Set net.ipv6: true or --ipv6 if you like to bind IPv4 and IPv6 address, see for example (MongooseServerSelectionError: connect ECONNREFUSED ::1:27017).

like image 29
Wernfried Domscheit Avatar answered Nov 03 '25 13:11

Wernfried Domscheit