How to fix DNSHostNotFound: Failed to look up service "_mongodb._tcp.cluster0.mongodb.net" in MongoDB

MongoDBBEGINNERMEDIUMUpdated Dec 22, 2025ยท 165 views

This DNS lookup error occurs when your system cannot resolve MongoDB Atlas SRV records, typically due to DNS server limitations or network configuration issues preventing mongodb+srv:// connections.

Quick fix

Fixes DNSHostNotFound: Failed to look up service "_mongodb._tcp.cluster0.mongodb.net"

# Edit resolv.conf
sudo nano /etc/resolv.conf

# Add Google DNS
nameserver 8.8.8.8
nameserver 8.8.4.4

# Or Cloudflare DNS
nameserver 1.1.1.1
nameserver 1.0.0.1
  1. Verify the MongoDB Atlas cluster exists and is active
  2. Switch to Google Public DNS or Cloudflare DNS
  3. Use standard connection string instead of SRV format
  4. Update MongoDB driver to latest version
mongodb โ€” error
# Edit resolv.conf
sudo nano /etc/resolv.conf
# Add Google DNS
nameserver 8.8.8.8
nameserver 8.8.4.4
# Or Cloudflare DNS
nameserver 1.1.1.1
nameserver 1.0.0.1
DNSHostNotFound: Failed to look up service "_mongodb._tcp.cluster0.mongodb.net"

What this error means

This error occurs when MongoDB drivers attempt to use the mongodb+srv:// connection string format but cannot resolve the DNS SRV records required for cluster discovery. MongoDB Atlas uses DNS SRV records (Service records) prefixed with _mongodb._tcp to automatically discover all replica set members in a cluster. When your system's DNS resolver cannot look up these special SRV records, the connection fails immediately. The mongodb+srv:// protocol is a convenience feature that allows MongoDB drivers to query DNS for the full list of hosts in your cluster, eliminating the need to hardcode every replica set member in your connection string. However, this requires a DNS server that supports SRV record lookups, which some ISP-provided DNS servers and restrictive network environments do not provide. This error is most commonly seen with MongoDB Atlas connections but can occur with any MongoDB deployment using SRV-based connection strings.

Typical symptoms

  • Connection to MongoDB Atlas fails immediately with DNSHostNotFound error
  • Application cannot connect when using mongodb+srv:// format
  • Connection works locally but fails in certain network environments (Docker, Kubernetes, corporate networks)
  • Standard mongodb:// connections work but mongodb+srv:// connections do not
  • Error message includes "_mongodb._tcp" in the service name

Common causes

  1. ISP DNS server does not support SRV record lookups required by mongodb+srv:// protocol
  2. Corporate firewall or network policy blocking DNS SRV queries
  3. DNS resolver configuration in Docker or Kubernetes not supporting SRV lookups
  4. Outdated MongoDB driver version that does not properly handle SRV connections
  5. Network environment using DNS server that filters or blocks certain record types
  6. Typo in the connection string hostname or cluster name
  7. MongoDB Atlas cluster is paused, deleted, or the hostname has changed

How to fix "DNSHostNotFound: Failed to look up service "_mongodb._tcp.cluster0.mongodb.net""

1Verify the MongoDB Atlas cluster exists and is active

Log into your MongoDB Atlas account and confirm:
- The cluster is running (not paused or terminated)
- The cluster hostname matches your connection string
- Copy the connection string again from Atlas to ensure accuracy

In Atlas Dashboard:
1. Navigate to your cluster
2. Click "Connect"
3. Choose "Connect your application"
4. Copy the fresh connection string and compare with yours

2Switch to Google Public DNS or Cloudflare DNS

Change your system DNS to a public DNS server that supports SRV records.

On Linux:

bash
# Edit resolv.conf
sudo nano /etc/resolv.conf

# Add Google DNS
nameserver 8.8.8.8
nameserver 8.8.4.4

# Or Cloudflare DNS
nameserver 1.1.1.1
nameserver 1.0.0.1

On macOS:

bash
# Open System Preferences > Network
# Select your connection > Advanced > DNS
# Add 8.8.8.8 and 8.8.4.4

On Windows:

powershell
# Open Network Connections
# Right-click adapter > Properties
# Select IPv4 > Properties
# Use: 8.8.8.8 and 8.8.4.4

For Docker containers:

json
// In docker-compose.yml
services:
  app:
    dns:
      - 8.8.8.8
      - 8.8.4.4
3Use standard connection string instead of SRV format

Replace mongodb+srv:// with mongodb:// and specify hosts explicitly.

Original SRV format:

bash
mongodb+srv://username:password@cluster0.mongodb.net/database

Standard format:

bash
mongodb://username:password@cluster0-shard-00-00.mongodb.net:27017,cluster0-shard-00-01.mongodb.net:27017,cluster0-shard-00-02.mongodb.net:27017/database?ssl=true&replicaSet=atlas-xxxxx-shard-0&authSource=admin&retryWrites=true&w=majority

Get the standard format from Atlas:
1. Click "Connect" on your cluster
2. Choose "Connect your application"
3. Select "2.2.12 or later" driver version (shows standard format)
4. Click "I am not using the SRV connection format"

Note: You'll need to manually update if Atlas adds/removes nodes.

4Update MongoDB driver to latest version

Ensure you're using a MongoDB driver version that properly supports SRV connections.

Node.js:

bash
npm install mongodb@latest
# or
npm install mongoose@latest

Python:

bash
pip install --upgrade pymongo

Java:

xml
<!-- Update pom.xml -->
<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver-sync</artifactId>
    <version>4.11.1</version>
</dependency>

Minimum versions for SRV support:
- Node.js: mongodb 3.1.0+, mongoose 5.2.0+
- Python: pymongo 3.6.0+
- Java: 3.6.0+
- C#: 2.5.0+

5Test DNS SRV resolution manually

Verify your system can resolve SRV records:

Using dig (Linux/macOS):

bash
dig +short SRV _mongodb._tcp.cluster0.mongodb.net

Expected output shows host and port:

bash
0 0 27017 cluster0-shard-00-00.mongodb.net.
0 0 27017 cluster0-shard-00-01.mongodb.net.
0 0 27017 cluster0-shard-00-02.mongodb.net.

Using nslookup (Windows):

cmd
nslookup -type=SRV _mongodb._tcp.cluster0.mongodb.net

If no results appear, your DNS server doesn't support SRV lookups. Switch to a different DNS server (step 2) or use standard format (step 3).

6Configure DNS in containerized environments

For Docker and Kubernetes deployments:

Docker Compose:

yaml
version: '3.8'
services:
  app:
    image: myapp
    dns:
      - 8.8.8.8
      - 1.1.1.1
    dns_search:
      - .

Kubernetes Pod:

yaml
apiVersion: v1
kind: Pod
metadata:
  name: myapp
spec:
  dnsPolicy: "None"
  dnsConfig:
    nameservers:
      - 8.8.8.8
      - 1.1.1.1

Environment variable workaround (some drivers):

bash
export MONGODB_DNS_SERVER=8.8.8.8

Advanced notes

SRV vs Standard Connection Strings:
The mongodb+srv:// format is convenient because it automatically discovers all replica set members via DNS, making connection strings shorter and self-updating when Atlas scales your cluster. However, it requires DNS infrastructure that supports SRV (Service) and TXT (for connection options) record types. The standard mongodb:// format works everywhere but requires manual updates if your cluster topology changes.

Corporate and Restricted Networks:
Many corporate networks use DNS servers that filter record types for security reasons, blocking SRV queries. If you're behind a corporate firewall and cannot change DNS settings, the standard connection string is your best option. Contact your network administrator if you need SRV support enabled.

DNS Caching Issues:
After switching DNS servers, you may need to flush your DNS cache:
- Linux: sudo systemd-resolve --flush-caches or sudo service nscd restart
- macOS: sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
- Windows: ipconfig /flushdns

Kubernetes DNS Considerations:
Kubernetes uses CoreDNS or kube-dns, which may have limitations with external SRV lookups. Setting dnsPolicy: "None" with explicit nameservers bypasses cluster DNS for your pod. Alternatively, configure CoreDNS to forward SRV queries to external resolvers.

Driver-Specific Behavior:
Some drivers (particularly Java and .NET) may have environment-specific DNS resolution issues. Check your driver's documentation for DNS configuration options. The Node.js driver uses the system's DNS resolver, while others may have built-in resolvers that behave differently.

Atlas IP Whitelisting:
After resolving DNS issues, ensure your IP address is whitelisted in Atlas Network Access settings, or you'll encounter authentication errors instead.

Frequently asked questions

What does "DNSHostNotFound: Failed to look up service "_mongodb._tcp.cluster0.mon" mean?
This error occurs when MongoDB drivers attempt to use the mongodb+srv:// connection string format but cannot resolve the DNS SRV records required for cluster discovery. _tcp to automatically discover all replica set members in a cluster. When your system's DNS resolver cannot look up these special SRV records, the connection fails immediately.
How do I fix "DNSHostNotFound: Failed to look up service "_mongodb._tcp.cluster0.mon"?
This DNS lookup error occurs when your system cannot resolve MongoDB Atlas SRV records, typically due to DNS server limitations or network configuration issues preventing mongodb+srv:// connections.
What causes "DNSHostNotFound: Failed to look up service "_mongodb._tcp.cluster0.mon"?
ISP DNS server does not support SRV record lookups required by mongodb+srv:// protocol Corporate firewall or network policy blocking DNS SRV queries DNS resolver configuration in Docker or Kubernetes not supporting SRV lookups
Is the "DNSHostNotFound: Failed to look up service "_mongodb._tcp.cluster0.mon" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading