Configure MongoDB DB Replica Sets using IP Addresses - mongodb

Can I configure MongoDB DB replica sets using IP addresses alone instead of host names?
Usually an IP address can be used almost everywhere a host name is expected. But our main Mongo DB expert led me to believe that we must use hostnames sharing a common domain such as: db1.domain.com, db2.domain.com...
Documentation for replica set rs.initiate() does not say anything about this.

You can use IP addresses in replica set config however domain names are preferable:
The host field specifies the master mongod instance, and holds a resolvable hostname, i.e. IP address, or a name from a host file, or preferably a fully qualified domain name.
Host is defined here

Related

Change Hostnames and IP Addresses with another host - Does it require a DNS update?

I have a new Linux database server I am working on with a certain hostname and ipaddress. I want to change it's hostname and ipaddress with my old Linux database server's at the time of going live with the new server. I understand this requires only update on the new server's hosts file.
My team says it would need a DNS update. I don't see why it would require a DNS update. Because a DNS is a mapping between hostname and ipaddress and it hasn't changed.
Could anyone clarify?
Thank You, Madhuri Dara
normally, yes indeed, a DNS is a mapping between IP addresses and hostname.
However, I would also recommend to delete the old one an re-create them to perform a re-discovery of the routes.
The best option for you would be here to have a DNS manager into your domain, this way, you could modify them here, instead of into your DNS file in each machine.

AWX ansible - Allow inventory duplicate host

AWX version 13.
I have a few inventories, each one can have a many hosts and I will be adding a lot more hosts over time. Some hosts have unique IP's, while others share the same IP. Each host I've set a variable in the variables section with the ssh port to use when connecting to it for the job and this works well.
To work around the issue I'm creating a unique DNS record for the hosts that share the same IP and using the DNS in the host field for that host, but there has to be a better way.
How can I share or have AWX ignore the duplicate host IP/dns and let me save the duplicate host record?

What is IP binding in mongodb?

I am trying to learn how to implement replication in mongodb.
I have gone through the mongodb docs on the same topic and I understand most of it. However I do not really understand everything about ip binding
According to the docs the bindip is
The hostnames and/or IP addresses and/or full Unix domain socket paths
on which mongos or mongod should listen for client connections.
According to the same docs net.port is:
The TCP port on which the MongoDB instance listens for client
connections.
I can see the differences from the two definitions and I understand net.port well enough. But I do not understand what net.bindIp really is and how it works. So here are my questions
What is the difference between socket paths and TCP ports in regard to mongodb listening for client connections?
The docs say that when net.bindIpAll is set to true: "the mongos or mongod instance binds to all IPv4 addresses (i.e. 0.0.0.0)." Where do this "IPv4 addresses" come from? Why are they many? What is the advantage of binding to all of them?
Why not just use port to access my mongodb instance why do I need bind an ip address?
in MongoDB the configuration item net.bindIp allows the administrator to specify which network adapter the MongoDB process should listen for traffic on (by IP Address). For a multi-homed system (multiple network cards) traffic can be managed by specifying the IP Address related to a specific network card for both performance and security. If the IP address 0.0.0.0 is specified then all network adapters will be used. To bind to all adapters using IPv6 then specify ::,0.0.0.0 instead. See https://docs.mongodb.com/manual/core/security-mongodb-configuration/ for details.
The advice I have always received is to NEVER use a hostname or DNS name, but instead ALWAYS use an IP Address.

MongoDB Replica set with external addresses

Here is my problem. Mongodb works perfectly on my debian 8 server, but I want to do a replica set with external addresses... Here is my problem :
- I have two VPS on a different network
- I followed a tutorial on internet but I have an error message "either all host names in a replica set configuration must be localhost"
Here is a part of my mongodb config :
net:
port: 27017
bindIp: 51.X.X.1, 167.X.X.4
I didn't bind any localhost address. What could I do ? Do I have do do something special to make it works ?
Best Regards
The error message suggests your replica set config includes a localhost address, which was likely added by the default config in rs.initiate() if you didn't explicitly specify localhost anywhere.
You can check the output of rs.conf() to review the current replicate set configuration. Since you want to specify a public hostname I would include your desired config for rs.initiate() rather than relying on the defaults when you initiate the replica set. I'd also recommend following the tutorials in the MongoDB documentation for your server version, as third party tutorials may be outdated or miss important details.
If you want to correct your existing configuration, you could copy the the current replica set config as reported by rs.conf(), edit the hostname or IP address, and then pass the updated configuration document to rs.reconfig().
NOTE: before binding to external IPs, please review the MongoDB Security Checklist and ensure you have configured appropriate security measures like access control, authentication, network encryption (TLS/SSL), and firewall rules. Ideally you would have a VPN/VPC for private communication between your replica set members rather than directly using public networks.

configure mongodb only accept remote connection comes from LAN

mongodb has bind ip but it is not so practical due to when new server add, it need shutdown db and add the new server ip into bind ip list and restart db. This is unacceptable because all other servers need to relaunch either.
In almost all deployment, servers machine and db machine are in same LAN. So can mongodb be configured as only accept ranges of ip of [172.16.0.0 - 172.31.255.255], [192.168.0.0 - 192.168.255.255], [10.0.0.0 - 10.255.255.255]?
These 3 ranges ip is LAN ip
The bind_ip configuration value only determines which IP address(es) your MongoDB server is listening to. It does not control access from remote IPs -- that is the job of a firewall.
The address ranges you have listed as requiring remote access are all private IP address space which means these networks are not directly reachable/routable outside your LAN. Assuming you can route traffic between your private networks you should not need to bind to multiple IP addresses.
Given you are allowing access from a broad range of IP addresses, you should also read the Security section of the MongoDB manual (in particular, the Security Checklist and tutorial on enabling Access Control).
bindIp can accept multiple comma separated values. See the "Security considerations" section Here
Other than that you might want to consider configuring your firewall, maybe iptables if it runs on Linux machine.
Hope this helps