Skip to content

Node.js dns.getServers() returns 127.0.0.1 on Windows 11 while Windows DNS is configured correctly, causing dns.resolveSrv() and MongoDB Atlas (mongodb+srv://) to fail #64428

Description

@kharat-dev

Version

v24.18.0 , v22.22.0 Issue reproduced on both versions.

Platform

Windows 11 24H2 (Build 10.0.26200) x64

Subsystem

No response

What steps will reproduce the bug?

  1. Install Node.js (tested with v22.22.0 and v24.18.0) on Windows 11 (Build 10.0.26200).

  2. Save the following as repro.js:

const dns = require("node:dns");

console.log("Node:", process.version);
console.log("Servers:", dns.getServers());

dns.lookup("google.com", (err, address) => {
  console.log("lookup:", err, address);
});

dns.resolve4("google.com", (err, addresses) => {
  console.log("resolve4:", err, addresses);
});

dns.resolveSrv("_mongodb._tcp.cluster0.mongodb.net", (err, records) => {
  console.log("resolveSrv:", err, records);
});
  1. Run:
node repro.js
  1. Observe the output.

Output

Node: v22.22.0
Servers: [ '127.0.0.1' ]

resolve4:
Error: queryA ECONNREFUSED google.com

resolveSrv:
Error: querySrv ECONNREFUSED _mongodb._tcp.cluster0.mongodb.net

lookup:
null 2404:6800:4013:804::64

How often does it reproduce? Is there a required condition?

The issue reproduces 100% of the time on my machine.

Conditions:

  • Windows 11 (Build 10.0.26200)
  • Reproduced with Node.js v22.22.0 and v24.18.0
  • Occurs regardless of whether I am connected via Wi-Fi or a mobile hotspot.
  • No proxy is configured.
  • Windows DNS resolution works correctly (nslookup and Resolve-DnsName both succeed).
  • dns.getServers() consistently returns ['127.0.0.1'].
  • dns.lookup() succeeds.
  • dns.resolve4() and dns.resolveSrv() fail with ECONNREFUSED.
  • Calling dns.setServers(["8.8.8.8", "1.1.1.1"]) before performing DNS resolution makes the issue disappear.

What is the expected behavior? Why is that the expected behavior?

dns.getServers() should return the DNS servers configured by the operating system rather than 127.0.0.1, since Windows is configured to use DHCP-assigned DNS servers.

On my system:

  • ipconfig /all reports:

    • IPv4 DNS: 10.219.174.109
    • IPv6 DNS: 2409:40c2:8427:7b61::c7
  • nslookup works correctly.

  • Resolve-DnsName works correctly.

  • dns.lookup() works correctly.

Therefore I expect:

  • dns.getServers() to report the DNS servers configured by Windows.
  • dns.resolve4() and dns.resolveSrv() to successfully resolve DNS records without requiring an explicit call to dns.setServers().

Instead, dns.getServers() reports ['127.0.0.1'], causing dns.resolve4() and dns.resolveSrv() to fail with ECONNREFUSED.

What do you see instead?

Instead of using the DNS servers configured by Windows, dns.getServers() returns:

[ '127.0.0.1' ]

As a result:

  • dns.lookup() succeeds because it uses the operating system's resolver.
  • dns.resolve4() fails with ECONNREFUSED.
  • dns.resolveSrv() fails with ECONNREFUSED.

Output:

Node: v22.22.0

Servers:
[ '127.0.0.1' ]

resolve4:
Error: queryA ECONNREFUSED google.com
    code: 'ECONNREFUSED'
    syscall: 'queryA'

resolveSrv:
Error: querySrv ECONNREFUSED _mongodb._tcp.cluster0.mongodb.net
    code: 'ECONNREFUSED'
    syscall: 'querySrv'

lookup:
null 2404:6800:4013:804::64

Additionally, calling:

const dns = require("node:dns");
dns.setServers(["8.8.8.8", "1.1.1.1"]);

before the DNS queries immediately resolves the issue:

  • dns.resolve4() succeeds.
  • dns.resolveSrv() succeeds.
  • MongoDB Atlas connections using mongodb+srv:// work correctly.

Additional information

The issue disappears if I explicitly configure DNS servers before performing DNS resolution:

const dns = require("node:dns");

dns.setServers(["8.8.8.8", "1.1.1.1"]);

After calling dns.setServers():

  • dns.resolve4() succeeds.
  • dns.resolveSrv() succeeds.
  • MongoDB Atlas connections using mongodb+srv:// work normally.

This suggests that the failure is related to the default DNS server configuration returned by dns.getServers(), which reports 127.0.0.1 on my system.

Activity

  1. Renegade334 commented on Jul 11, 2026

    @Renegade334
    Member

    Duplicate of #62347. The fix should land in the next releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions