Replica Set in MongoDB by using IPs instead of domains?
As per MongoDB documentation here To override and bind to other ip addresses, you can use the net.bindIp configuration file setting or the
--bind_ip command-line option to specify a list of hostnames or ip addresses.
For example, the following mongod instance binds to both the localhost and the hostname My-Example-Associated-Hostname, which is associated with the ip address 198.51.100.1:
mongod --bind_ip localhost,My-Example-Associated-Hostname
In order to connect to this instance, remote clients must specify the hostname or its associated ip address 198.51.100.1:
mongo --host My-Example-Associated-Hostname
mongo --host 198.51.100.1
Ensure that network traffic can pass securely between all members of the set and all clients in the network .
Consider the following:
- Establish a virtual private network. Ensure that your network
topology routes all traffic between members within a single site over
the local area network.
- Configure access control to prevent connections from unknown clients
to the replica set.
- Configure networking and firewall rules so that incoming and outgoing
packets are permitted only on the default MongoDB port and only from
within your deployment. See the IP Binding considerations.
WARNING NOTE: Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from
unauthorized access. For a complete list of security recommendations,
Checklist. At minimum, consider enabling
authentication and hardening
If you will specifies the replica set name and the ip binding through the --replSet and --bind_ip command-line options:
mongod --replSet "rs0" --bind_ip localhost,<hostname(s)|ip address(es)>
For , specify the hostname(s) and/or ip address(es) for your mongod instance that remote clients (including the other members of the replica set) can use to connect to the instance.
Alternatively, you can also specify the replica set name and the ip addresses in a configuration file:
bindIp: localhost,<hostname(s)|ip address(es)>
Note: Changed in version 3.6: Starting in MongoDB 3.6, MongoDB binaries, mongod and mongos, bind to localhost by default. If the
net.ipv6 configuration file setting or the --ipv6 command line option
is set for the binary, the binary additionally binds to the localhost