Error
Error Code: 230

MongoDB Error 230: DNS Resolution Failure

📦 MongoDB
📋

Description

MongoDB Error 230, 'DNS Host Not Found', indicates that the MongoDB client or server cannot resolve the hostname or IP address it is trying to connect to. This typically occurs when a hostname specified in a connection string or configuration is incorrect, unreachable, or cannot be translated to an IP address by the DNS system.
💬

Error Message

D N S Host Not Found
🔍

Known Causes

4 known causes
⚠️
Misconfigured Connection String
The hostname or IP address specified in the MongoDB connection string contains a typo, is incorrect, or refers to a non-existent host.
⚠️
Unresponsive DNS Server
The DNS server configured for the client or MongoDB server is down, unreachable, or failing to resolve the target hostname.
⚠️
Network Firewall Blocking DNS
Firewall rules on the client, server, or intermediate network devices are preventing DNS queries or blocking access to the target host.
⚠️
Missing DNS Record
The requested hostname does not have a corresponding A or CNAME record in the configured DNS server, or the record is outdated.
🛠️

Solutions

4 solutions available

1. Verify MongoDB Connection String Hostname easy

Ensure the hostname in your MongoDB connection string is correct and resolvable.

1
Locate your MongoDB configuration file (e.g., `mongod.conf`, `mongos.conf`) or the application code that establishes the MongoDB connection.
2
Examine the `uri` or `connectionString` parameter. Check for typos in the hostname or domain name.
mongodb://your_correct_hostname:27017/your_database
3
Use a command-line tool to test DNS resolution for the hostname specified in your connection string. Replace `your_hostname` with the actual hostname from your connection string.
ping your_hostname
4
If `ping` fails or returns an unknown host error, verify the DNS records for that hostname with your network administrator or DNS provider.

2. Check Local DNS Resolver Configuration medium

Ensure the server running MongoDB can correctly resolve hostnames using its configured DNS servers.

1
On the server experiencing the error, identify the system's DNS resolver configuration file. This is typically `/etc/resolv.conf` on Linux/macOS or found in Network Adapter settings on Windows.
2
Examine the `nameserver` entries in the configuration file. These should point to valid and reachable DNS servers.
nameserver 8.8.8.8
nameserver 8.8.4.4
3
Test connectivity to the specified DNS servers.
ping 8.8.8.8
4
If the DNS servers are unreachable or not responding, update the `nameserver` entries to point to known working DNS servers (e.g., public DNS like Google's 8.8.8.8 or your organization's internal DNS servers).
5
After updating the configuration, restart the MongoDB service to ensure it picks up the new DNS settings. The command to restart depends on your operating system and init system (e.g., `systemctl restart mongod`, `service mongod restart`).
sudo systemctl restart mongod

3. Configure Host File Entries for Static Resolution medium

Manually map hostnames to IP addresses in the system's host file for critical connections.

1
Identify the IP address of the MongoDB server or replica set/sharded cluster members.
2
Locate the system's host file. On Linux/macOS, it's typically `/etc/hosts`. On Windows, it's `C:\Windows\System32\drivers\etc\hosts`.
3
Add an entry to the host file mapping the IP address to the hostname used in your MongoDB connection string. For example, if your connection string uses `mongo-cluster.example.com` and its IP is `192.168.1.100`:
192.168.1.100 mongo-cluster.example.com
4
Save the host file. Changes to the host file usually take effect immediately, but a restart of the MongoDB service might be beneficial to ensure it re-reads the configuration.
sudo systemctl restart mongod

4. Verify Network Firewall Rules medium

Ensure firewalls are not blocking DNS queries or MongoDB traffic.

1
Check firewalls on the client machine attempting to connect to MongoDB.
2
Verify that outbound DNS queries (typically UDP/TCP port 53) are allowed from the client to the configured DNS servers.
3
Check firewalls on the MongoDB server(s). Ensure that inbound connections on the MongoDB port (default 27017) are allowed from the client's IP address.
4
If using a cloud provider (AWS, Azure, GCP), review their respective security group or network firewall rules. Ensure that rules permit DNS traffic and MongoDB port access between the relevant instances.
🔗

Related Errors

5 related errors