跳转至内容

Stubby

来自 ArchWiki

Stubby 是一个应用程序,充当本地 DNS 隐私存根解析器(使用 DNS-over-TLS)。Stubby 加密从客户端计算机(台式机或笔记本电脑)发送到 DNS 隐私解析器的 DNS 查询,从而提高最终用户的隐私性。

安装

安装 stubby 包。

配置

要配置 stubby,请执行以下步骤

选择解析器

安装后,Stubby 具有一些默认解析器。它们可以在 /etc/stubby/stubby.yml 中找到并编辑。您可以使用默认设置,取消注释预先编写的解析器之一,或从此列表中查找其他解析器。

有效解析器配置示例

/etc/stubby/stubby.yml
upstream_recursive_servers:

## Cloudflare servers
 - address_data: 1.1.1.1
   tls_auth_name: "cloudflare-dns.com"
 - address_data: 1.0.0.1
   tls_auth_name: "cloudflare-dns.com"
 - address_data: 2606:4700:4700::1111
   tls_auth_name: "cloudflare-dns.com"
 - address_data: 2606:4700:4700::1001
   tls_auth_name: "cloudflare-dns.com"
注意 此示例使用了 Cloudflare 的公共 DNS 解析器。请将其替换为您信任的 DNS 解析器。请参阅 Domain name resolution#Third-party DNS services

当您收到警告日志抱怨 tls_pubkey_pinset 错误时,表示 tls_pubkey_pinset 值可能不正确,并且 tls_pubkey_pinsetvalue 可以使用以下方法生成:

$ openssl s_client -connect address_data:tls_port </dev/null 2>/dev/null | openssl x509 -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64
注意 有关配置 Stubby 的更多信息,请参阅 Configuring Stubby

启用 DNSSEC 验证

通过取消注释 /etc/stubby/stubby.yml 中的以下行来启用 DNSSEC 验证:

/etc/stubby/stubby.yml
...
dnssec: GETDNS_EXTENSION_TRUE
...

修改 resolv.conf

选择了解析器后,修改 resolv.conf 文件,并将当前的解析器地址集替换为 localhost 的地址。

/etc/resolv.conf
nameserver ::1
nameserver 127.0.0.1
options trust-ad

其他程序可能会覆盖此设置;有关详细信息,请参阅 resolv.conf#Overwriting of /etc/resolv.conf

启动 systemd 服务

最后,启动/启用 stubby.service

技巧与提示

本地 DNS 缓存配置

Stubby 没有内置的 DNS 缓存,因此每个查询都会被传输和解析,这可能会减慢连接速度。设置 DNS 缓存需要安装和配置单独的 DNS 缓存器。

更改端口

为了将请求转发到本地 DNS 缓存,Stubby 应该监听一个与默认值 53 不同的端口,因为 DNS 缓存本身需要监听 53 并在另一个端口查询 Stubby。本节使用端口号 54 作为示例。

如下编辑 listen_addresses 的值:

/etc/stubby/stubby.yml
listen_addresses:
  - 127.0.0.1@54
  -  0::1@54
dnsmasq

将 dnsmasq 配置为 本地 DNS 缓存。与 Stubby 一起工作的基本配置如下:

/etc/dnsmasq.conf
no-resolv
proxy-dnssec
server=::1#54
server=127.0.0.1#54
listen-address=::1,127.0.0.1

重启 dnsmasq.service 以应用更改。

其他 DNS 缓存器

有关更多 DNS 缓存器,请参阅 DNSCrypt#Local DNS cache configuration。如果配置不相同,则应该相似。