How to set up bindIp for a replica set?

Posted March 31, 2020 1k views

I am using the Ubuntu 18.04 MongoDB one click installation droplet. I have setup three droplets, and want to set up a replica set.
I was trying to follow some tutorials:


and here

I am stuck at setting a bindIp, and whenever I add the IP of my other droplets to bindIp, mongod won’t start, failing with this error:

Mar 31 15:52:01 systemd[1]: mongod.service: Main process exited, code=exited, status=48/n/a
Mar 31 15:52:01 systemd[1]: mongod.service: Failed with result 'exit-code'.

To be clear, this works:

# network interfaces
  port: 27017

but this doesn’t

# network interfaces
  port: 27017

Pinging each of those individually does work though. How do I set this up? Do I need to configure a private network?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @deformercoding

We have documentation to configure remove access for mongodb, Please feel free to check it out:

In the /etc/mongod.conf file make changes to bindIP as below to three mongodb nodes when you are setting up replication.

In mongodb1 server

# network interfaces
  port: 27017

In mongodb2 server

# network interfaces
  port: 27017

In mongodb3 server

# network interfaces
  port: 27017

Once you made these changes, restart mongod service on all 3 nodes.

Always when you are binding to a non-localhost, please make sure to secure the database by enabling authentication.

Hope this helps!


by Mark Drake
MongoDB doesn't have authentication enabled by default, meaning that any user with access to the server where the database is installed can add and delete data without restriction. In order to secure this vulnerability, this tutorial will walk you through creating an administrative user and enabling authentication. You'll then test to confirm that only this administrative user has access to the database.