Repository navigation
dns.getServers() incorrectly returns 127.0.0.1 when OS DNS is configured to 8.8.8.8 #62347
Description
Activity
This was fixed in c-ares (c-ares/c-ares@8ba37af) but not yet released.
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.
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.jsonas well:
"terminal.integrated.env.windows": {
"NODE_OPTIONS": "--require C:\\Tools\\dns-fix.cjs"
}Hope this saves someone else some debugging time.
Version
Current Version: 24.14.0, Same Issue on Every version of nodejs
Platform
Subsystem
No response
What steps will reproduce the bug?
node -e "console.log(require('node:dns').getServers())"
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 /allconfirms the system is using8.8.8.8and no local DNS proxy (like Acrylic or Acrylic DNS) is running on port 53.Additional information
netsh winsock reset,ipconfig /flushdns, andnetsh int ip reset.nslookup google.comcorrectly identifies the server as 8.8.8.8, but Node.js remains stuck on the loopback address.