设置 unbound DNS 服务器
Unbound 是一个验证性、递归性和缓存 DNS 解析器,它支持 DNSSEC。
安装
安装 unbound 软件包
apk add unbound
设置
可以设置 unbound
作为服务运行,并使用以下命令启动
rc-update add unbound default service unbound start
配置
以下配置是一个缓存名称服务器的示例(在生产服务器中,建议调整 access-control 参数以限制对您网络的访问)。 forward-zone(s) 部分会将所有 DNS 查询转发到指定的服务器。 不要忘记将 'interface' 参数更改为您本地接口 IP 地址(或 0.0.0.0 以监听所有本地 IPv4 接口)。 以下是一个最小示例,其中许多选项被注释掉。
/etc/unbound/unbound.conf
server: verbosity: 1 ## Specify the interface address to listen on: interface: 10.0.0.1 ## To listen on all interfaces use: # interface: 0.0.0.0 do-ip4: yes do-ip6: yes do-udp: yes do-tcp: yes do-daemonize: yes access-control: 0.0.0.0/0 allow ## Other access control examples #access-control: 192.168.1.0/24 action ## 'action' should be replaced by any one of: #deny (drop message) #refuse (sends a DNS rcode REFUSED error message back) #allow (recursive ok) #allow_snoop (recursive and nonrecursive ok). ## Minimum lifetime of cache entries in seconds. Default is 0. #cache-min-ttl: 60 ## Maximum lifetime of cached entries. Default is 86400 seconds (1 day). #cache-max-ttl: 172800 ## enable to prevent answering id.server and hostname.bind queries. hide-identity: yes ## enable to prevent answering version.server and version.bind queries. hide-version: yes ## default is to use syslog, which will log to /var/log/messages. use-syslog: yes ## to log elsewhere, set 'use-syslog' to 'no' and set the log file location below: #logfile: /var/log/unbound python: remote-control: control-enable: no ## Stub zones are like forward-zones (see below) but must contain only the authority server (no recursive servers) #stub-zone: # name: "my.test.com" # stub-addr: 172.16.1.1 # stub-addr: 172.16.1.2 ## Note: for forward-zones, the destination servers must be able to handle recursion to other DNS servers ## Forward all *.example.com queries to the server at 192.168.1.1 #forward-zone: # name: "example.com" # forward-addr: 192.168.1.1 ## Forward all other queries to the Verizon DNS servers forward-zone: name: "." ## Level3 Verizon forward-addr: 4.2.2.1 forward-addr: 4.2.2.4
root-hints
您可以选择查询根 DNS 服务器,而不是将查询转发到公共 DNS 服务器。 要做到这一点,请注释掉配置中的转发条目(“forward-zone”部分)。 然后,使用 wget 获取最新的 root hints 文件
wget -S https://www.internic.net/domain/named.cache -O /etc/unbound/root.hints
最后,通过将以下行添加到 unbound 配置文件的 server 部分,将 unbound 指向 root hints 文件
root-hints: "/etc/unbound/root.hints"
重启 unbound 以确保更改生效。 您可能希望设置一个 cron 任务 以定期更新 root hints 文件。
0x20 位
使用 0x20 位 被认为是实验性的。 它利用 DNS 数据包中一个未使用的位,要求权威服务器以模仿查询中使用的大小写来响应。
例如,当使用此功能时,对 www.google.com 的查询可能在请求中显示为 www.google.com 或 Www.GoogLe.coM 或 WWW.GoOGlE.cOm 或任何其他大小写组合。 权威服务器应以相同的大小写响应。 这有助于防止 DNS 欺骗攻击。
在某些情况下,极少数旧的或配置错误的服务器可能会返回错误(不到 1% 的服务器会响应不正确)。 要启用此功能,只需将以下行添加到 /etc/unbound/unbound.conf 的 'server' 部分,然后重启服务器
use-caps-for-id: yes
设置自动启动,启动并测试守护进程
检查配置是否有错误
unbound-checkconf
如果没有报告错误,则设置为自动启动,然后启动 unbound
rc-update add unbound rc-service unbound start
测试。 例如
dig dl-cdn.alpinelinux.org @10.0.0.1
或
nslookup www.google.cz 10.0.0.1
或使用 drill
drill www.bbc.co.uk @10.0.0.1
附加信息
通过 Wikipedia 页面获取的 DNS、记录类型、区域、名称服务器 和 DNSsec 的一般信息