Resetting the IP address

Before you go through the process of creating a replica and deploying a replica set, you will need to reconfigure mongod to run on an IP address other than localhost (127.x.x.x). This can be accomplished by using the --bind_ip flag when starting mongod (where a.b.c.d is the target IP address):

mongod --bind_ip a.b.c.d

To bind to all IP addresses on this server, you can use this option:

mongod --bind_ip_all 

The recommended approach is to modify the mongod configuration file on the impacted servers. Here are three possibilities:

If you want to have MongoDB listen with ... Then enter this into the MongoDB config file
...a specific IP address, a.b.c.d

net:     bindIp: a.b.c.d

...only specific network interfaces, ...

Get MongoDB 4 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.