本文介绍了如何在Node.js中设置DNS服务器解析查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Node.js解析查询中设置Google DNS服务器 8.8.8.8
.
I'm trying to set Google DNS server 8.8.8.8
in Node.js resolve query.
这样做的正确方法是什么?在命令行中,通常我们可以执行以下操作:
What is the correct way to do so? In command line usually we can do the following:
$ nslookup stackoverflow.com 8.8.8.8
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: stackoverflow.com
Address: 151.101.1.69
Address: 151.101.65.69
Address: 151.101.129.69
Address: 151.101.193.69
但是不清楚如何在Node.js中实现相同的方法
But its not quite clear how to make same approach in Node.js
require('dns').resolve('stackoverflow.com', function (err, addresses) {
console.log(err, addresses);
});
// => null [ '151.101.1.69', '151.101.65.69', '151.101.129.69', '151.101.193.69' ]
推荐答案
从nodejs文档: https://nodejs.org/api/dns.html#dns_dns_setservers_servers
From nodejs doc: https://nodejs.org/api/dns.html#dns_dns_setservers_servers
dns.setServers([
'4.4.4.4',
'[2001:4860:4860::8888]',
]);
这篇关于如何在Node.js中设置DNS服务器解析查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!