Correct bindIP for mongodb config file

December 22, 2014 4.4k views

Hi,

I am trying to setup mongodb replica set as follows:

  1. Primary database on local machine
  2. Secondary database on DO droplet I am not clear what bindIP to use for config files for mongodb on local machine and on remote server (DO droplet). It looks like there is local bindIP: 127.0.0.1 and my droplet: 192.241.xxx.xx. Which one is used for which config file? My YAML file looks as follows for local machine:
systemLog:
    destination:file
    path:"C:\\data\\log\\mongodb.log"
    logAppend:true
processManagement:
    fork:true
net:
    bindIp:127.0.0.1
    port:27017
storage:
    dbPath:"C:\\data"
replication:
    replSetName:"data"
2 Answers

Yes, it's a typical desktop setup. Yes, behind wireless router.
I checked my IP using whatsmyip.org - it's 104.5.xx.xxx, while when I run ipconfig on my machine, it's 192.168.x.x. It means that I don't have static IP as you mentioned. What are the possible solutions?

I am thinking of talking to my ISP and getting static IP or as you mentioned use port forwarding (I am not familiar with it though) to make it static that way.

Thank you for mentioning about security and firewalls. Actually, the reason for not putting this database on remote server is security. I thought that this database will be connected to network only during certain times.

Setting bindIp to 127.0.0.1 will only bind to the local loopback interface. You need to set that to an IP address that is accessible to the server. Is this local machine just a desktop setup? Is it behind a router? You'll most likely need to set up some port forwarding in order to have an externally and stable IP address.

You'll also want to read about the security consideration in the MongoDB documentation about making the database accessible externally. You most likely want to to set up firewall rules that only allow connections from whitelisted IP addresses.

  • Yes, it's a typical desktop setup. Yes, behind wireless router.
    I checked my IP using whatsmyip.org - it's 104.5.xx.xxx, while when I run ipconfig on my machine, it's 192.168.x.x. It means that I don't have static IP as you mentioned. What are the possible solutions?

    I am thinking of talking to my ISP and getting static IP or as you mentioned use port forwarding (I am not familiar with it though) to make it static that way.

    Thank you for mentioning about security and firewalls. Actually, the reason for not putting this database on remote server is security. I thought that this database will be connected to network only during certain times.

Have another answer? Share your knowledge.