dns.setServers(servers)


设置IP地址服务器端口在进行DNS解析时可用, servers参数是一个rfc5952数组格式的地址。 如果端口是IANA默认端口(53),那么它可以被忽略。

比如:

dns.setServers([
  '4.4.4.4',
  '[2001:4860:4860::8888]',
  '4.4.4.4:1053',
  '[2001:4860:4860::8888]:1053'
]);

ip地址无效将会报错。

dns.setServers()方法不要在DNS查询过程中使用。

Sets the IP address and port of servers to be used when performing DNS resolution. The servers argument is an array of rfc5952 formatted addresses. If the port is the IANA default DNS port (53) it can be omitted.

dns.setServers([
  '4.4.4.4',
  '[2001:4860:4860::8888]',
  '4.4.4.4:1053',
  '[2001:4860:4860::8888]:1053'
]);

An error will be thrown if an invalid address is provided.

The dns.setServers() method must not be called while a DNS query is in progress.

The dns.setServers() method affects only dns.resolve(), [dns.resolve*()][] and dns.reverse() (and specifically not dns.lookup()).

Note that this method works much like resolve.conf. That is, if attempting to resolve with the first server provided results in a NOTFOUND error, the resolve() method will not attempt to resolve with subsequent servers provided. Fallback DNS servers will only be used if the earlier ones time out or result in some other error.