跳转至内容

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。其配置应当相似,甚至完全相同。

© . This site is unofficial and not affiliated with Arch Linux.

Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.