Skip to content

dns.getServers() incorrectly returns 127.0.0.1 when OS DNS is configured to 8.8.8.8 #62347

Description

@CycloneAddons

Version

Current Version: 24.14.0, Same Issue on Every version of nodejs

Platform

Windows, x64

Subsystem

No response

What steps will reproduce the bug?

  1. Set system DNS to a public resolver (e.g., 8.8.8.8) on Windows.
  2. Verify 'ipconfig /all' shows 8.8.8.8 as the only DNS server.
  3. Run the following command in a clean terminal:
    node -e "console.log(require('node:dns').getServers())"
  4. Observe that it returns ['127.0.0.1'] despite system settings.

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

Always (100% of the time) on this specific machine after a PC reset, even after clearing virtual network adapters and setting the Interface Metric for Wi-Fi/Ethernet to 1.

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

The 'dns.getServers()' method should return the DNS servers configured in the OS network stack (8.8.8.8). It should not default to the loopback address (127.0.0.1) when a valid external DNS is active and prioritized.

What do you see instead?

The output of node -e "console.log(require('node:dns').getServers())" is ['127.0.0.1'].

This occurs even though ipconfig /all confirms the system is using 8.8.8.8 and no local DNS proxy (like Acrylic or Acrylic DNS) is running on port 53.

Additional information

  • I have already tried netsh winsock reset, ipconfig /flushdns, and netsh int ip reset.
  • I manually set the Interface Metric for the active Wi-Fi adapter to 1 to ensure priority.
  • I uninstalled all virtual network adapters (WSL2/Docker/VPN bridges).
  • nslookup google.com correctly identifies the server as 8.8.8.8, but Node.js remains stuck on the loopback address.
  • This behavior started immediately after a Windows PC reset.

Activity

Renegade334 commented on Mar 24, 2026

@Renegade334
Member

This was fixed in c-ares (c-ares/c-ares@8ba37af) but not yet released.

added
caresIssues and PRs related to the c-ares dependency or the cares_wrap binding.
on Mar 24, 2026

JUNED-AHMED-CHOUDHARY commented on Jun 5, 2026

@JUNED-AHMED-CHOUDHARY

I can confirm this issue on Windows 11.

Environment:

Windows 11 24H2
Node.js v24.16.0
Also reproduced on v22.22.3

The global resolver reports:

require('dns').getServers()
['127.0.0.1']

and:

require('dns').resolve4('google.com', console.log)

fails with:

Error: queryA ECONNREFUSED google.com

However, a manually configured resolver works:

const dns = require('dns');

const r = new dns.Resolver();
r.setServers(['8.8.8.8']);

r.resolve4('google.com', console.log);

which successfully resolves the hostname.

dns.lookup() and nslookup also work correctly on the same machine.

Thanks for identifying the c-ares fix. I can confirm the behavior is still present in Node.js v24.16.0 and the latest version that is v23.6.0.

This issue is causing connecting to mongodb srv url using mongoose, if this is solved then I think relase of this bug fix would be great help.

deepak-cardoza commented on Jun 24, 2026

@deepak-cardoza

Confirming I hit this exact symptom on a Windows 11 laptop — tested on both Node 24.x and Node 20.x, same behavior on both:

node -e "console.log(require('dns').getServers())"
// -> [ '127.0.0.1' ]

This was happening despite ipconfig /all and nslookup -type=SRV both showing the correct DNS servers (8.8.8.8 / 1.1.1.1), and mongodb+srv:// connections failing with querySrv ECONNREFUSED.

What fixed it was forcing the resolver explicitly via a preload script instead of relying on Node picking up the system DNS on its own:

// dns-fix.cjs
require('dns').setServers(['8.8.8.8', '1.1.1.1']);
[System.Environment]::SetEnvironmentVariable("NODE_OPTIONS", "--require C:\Tools\dns-fix.cjs", "Machine")

Two gotchas that cost extra time, in case they help someone else:

  • The machine-wide env var change didn't take effect until a full PC restart — a fresh terminal window alone wasn't always enough.
  • If you run from VS Code's integrated terminal, it can keep using a stale cached environment independently of the system-wide change. Needed this in VS Code's settings.json as well:
"terminal.integrated.env.windows": {
  "NODE_OPTIONS": "--require C:\\Tools\\dns-fix.cjs"
}

Hope this saves someone else some debugging time.

added
windowsIssues and PRs related to the Windows platform.
on Jun 24, 2026
added a commit that references this issue on Jul 8, 2026
added a commit that references this issue on Jul 30, 2026
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

    caresIssues and PRs related to the c-ares dependency or the cares_wrap binding.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions