Node.JS没有查询本地DNS

时间:2016-03-16 14:08:59

标签: node.js dns skydns

我刚安装了本地SkyDNS,我没有从Node的dns查找解析IP地址。我的resolv.conf只有一个条目:

nameserver 127.0.0.1

来自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

当我尝试使用Node的dns查找解析时:

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

使用resolve4而不是查找它有效,但为什么不查找从本地dns解析此地址?

1 个答案:

答案 0 :(得分:0)

在/etc/nsswitch.conf中更改dns的优先级它可以工作:

hosts: dns files