Search code examples
node.jsdnsskydns

Node.JS not querying local DNS


I have just installed locally SkyDNS and I am not resolve the IP address from a Node's dns lookup. My resolv.conf has only one entry:

nameserver 127.0.0.1

result from dig:

$ dig service.skydns.local

; <<>> DiG 9.9.5-3ubuntu0.8-Ubuntu <<>> service.skydns.local
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25842
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;service.skydns.local.      IN  A

;; ANSWER SECTION:
service.skydns.local.   3600    IN  A   10.0.1.125

;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Mar 16 10:41:21 BRT 2016
;; MSG SIZE  rcvd: 54

When I try to resolve using Node's dns lookup:

var dns = require('dns');
dns.lookup('service.skydns.local', function(err, res, fam){console.log(err, res, fam);})

{ [Error: getaddrinfo ENOTFOUND service.skydns.local]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'service.skydns.local' } undefined undefined

Using resolve4 instead of lookup it works, but why won't lookup resolve this address from the local dns?


Solution

  • Changing the priority of dns at /etc/nsswitch.conf it works:

    hosts: dns files