随机化 DNS 名称服务器

随机化 DNS 名称服务器

是否可以在 Unix 系统上的 /etc/resolv.conf 中列出多个名称服务器,并在进行 DNS 查询时使用随机名称服务器(而不仅仅是第一个)来解析 DNS 查询?

答案1

对于 Linux 系统,我使用timeoutrotate选项/etc/resolv.conf...我通常将 DNS 超时降低到 1 秒。

timeout:n
    sets the amount of time the resolver will wait for a response from a remote name server
    before  retrying  the  query  via  a  different  name server.  Measured in seconds, the
    default is RES_TIMEOUT (currently 5, see  <resolv.h>).   The  maximum  value  for  this
    option is silently capped to 30.

rotate 
    sets RES_ROTATE in _res.options, which causes round robin selection of nameservers from
    among  those  listed.  This has the effect of spreading the query load among all listed
    servers, rather than having all clients try the first listed server first every time.

答案2

Linux 上的 DNS 解析有不同类型的随机化或伪随机化。

使用 libc 解析器和/etc/resolv.conf

“选项轮换”是一种客户端循环,因此可以视为一种穷人随机化。但是,libc 解析器最多支持 3 个不同的服务器。以下是/etc/resolv.conf使用 3 个流行且可靠的公共 DNS 服务器的示例。

options timeout:1
options rotate

# resolver1.level3.net
nameserver 209.244.0.3  

# resolver1.opendns.com
nameserver 208.67.222.222  

# google-public-dns-a.google.com
nameserver 8.8.8.8

未绑定

使用 unbound 时,还可以指定多个解析器(超过 3 个)。随机化记录如下:

当需要发送查询时,将选择最快的服务器(在所谓的 400 毫秒 RTT 带内随机选择)

https://www.unbound.net/documentation/info_timeout.html

/etc/resolv.conf

nameserver 127.0.0.1

/etc/unbound/unbound.conf

forward-zone:
    name: "."
    # google
    #forward-addr: 8.8.8.8 

    # fnd.org
    forward-addr: 80.67.169.12 

    # comodo
    forward-addr: 8.26.56.26

    # level 3
    forward-addr: 209.244.0.3

答案3

简短的回答:不是的。

较长的回答:虽然几乎所有 Unix 变体都使用文件 /etc/resolv.conf 进行全局名称解析配置,但实际上它们几乎都使用相同的解析器库来完成这项工作。您的特定 Unix 变体可能可以完成您想要的工作,但要找出答案,您必须阅读其自己的文档。此外,它根本不可移植。

相关内容