dns.resolve only tries the first nameserver in /etc/resolv.conf??

343 views
Skip to first unread message

Yun Feng Ma

unread,
May 5, 2016, 9:44:54 AM5/5/16
to nodejs
Hi everyone!

The dns.resolve tries to send request to only the first nameserver in /etc/resolv.conf, and if the first nameserver fails to resolve the name, dns.resolve just returns and doesn't try to send request to the second nameserver.  Is this work-as-design?

Here is an example: the  /etc/resolv.conf is like below in Linux:
75.2.4.5
75.4.7.6

Run below codes:
dns.resolve('demo1.sample.com','A',function(err, addresses) {
        console.log(err);
        console.log(addresses);
});

The 'demo1.sample.com' is defined in the second nameserver (75.4.7.6), so the above codes always failed, because the dns.resolve doesn't try to call the second nameserver.

I found nodejs has flag to control this: https://github.com/nodejs/node/blob/master/deps/cares/src/ares_init.c#L255  seems like the default behaviour is only call the first nameserver, is there any way to make dns.resolve to call all nameservers in /etc/resolv.conf until succeed? 

Thanks a lot.

Ben Noordhuis

unread,
May 5, 2016, 9:43:50 PM5/5/16
to nod...@googlegroups.com
The second nameserver is only tried when the first one times out or
returns a malformed reply. If the first server replies with NXDOMAIN
(domain not found), the second one isn't contacted; that shouldn't be
necessary because DNS is a global registry after all.

Yun Feng Ma

unread,
May 6, 2016, 12:05:00 AM5/6/16
to nodejs
在此输入代码...



在 2016年5月6日星期五 UTC+8上午9:43:50,Ben Noordhuis写道:
Thanks, Ben, for the reply.

In our environment, the first nameserver is our internal DNS server, which is used to resolve some internal domain names; the second nameserver is the public nameserver (like google DNS server 8.8.8.8), so this code  dns.resolve('www.google.com','A',function(err, addresses) { }) will get failed, because the first nameserver returns NXDOMAIN for "www.google.com". Do you have any solution for this?

Thanks.

Matt

unread,
May 6, 2016, 1:43:07 PM5/6/16
to nod...@googlegroups.com
Yes, make your internal nameserver also be recursive/caching and remove the second line. How you do that depends on what software you're using for DNS.

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/fc2151fc-c0fe-4126-bdd8-e9bedf3815b0%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Alain Mouette

unread,
May 6, 2016, 1:43:20 PM5/6/16
to nod...@googlegroups.com

What you are trying to do is against the rules. It will not work with any standard implementation!

Read more about DNS

-----
Alain Mouette

--

Denard Springle

unread,
May 6, 2016, 1:43:24 PM5/6/16
to nodejs
Set the internal DNS to proxy to an external DNS - such that when a DNS record is requested that the internal DNS does not have, it fetches it from an external name server (and caches it for future use). 

-- Denny

Ben Noordhuis

unread,
May 6, 2016, 1:43:34 PM5/6/16
to nod...@googlegroups.com
Not a node.js-based solution but is there a reason you can't configure
your internal nameserver to forward requests for names it doesn't know
about to an upstream server?

If that isn't a option, you could try installing dnsmasq locally and
see if you can make it do what you want.
Reply all
Reply to author
Forward
0 new messages