使用DNS over TLS

运维 系统运维
现代计算机用来在互联网种查找资源的 域名系统(DNS) 是在 35 年前设计的,没有考虑用户隐私。它会面临安全风险和攻击,例如 DNS 劫持。它还能让 ISP 拦截查询。

使用DNS over TLS

现代计算机用来在互联网种查找资源的 域名系统(DNS) 是在 35 年前设计的,没有考虑用户隐私。它会面临安全风险和攻击,例如 DNS 劫持。它还能让 ISP 拦截查询。

幸运的是,现在有 DNS over TLS 和 DNSSEC 两种技术。DNS over TLS 和 DNSSEC 允许创建从计算机到它配置的 DNS 服务器之间的安全且加密的端到端隧道。在 Fedora 上,部署这些技术的步骤很容易,并且所有必要的工具也很容易获得。

本指南将演示如何使用 systemd-resolved 在 Fedora 上配置 DNS over TLS。有关 systemd-resolved 服务的更多信息,请参见文档

步骤 1:设置 systemd-resolved

类似于下面所示修改 /etc/systemd/resolved.conf。确保启用 DNS over TLS 并配置要使用的 DNS 服务器的 IP 地址。

  1. $ cat /etc/systemd/resolved.conf
  2. [Resolve]
  3. DNS=1.1.1.1 9.9.9.9
  4. DNSOverTLS=yes
  5. DNSSEC=yes
  6. FallbackDNS=8.8.8.8 1.0.0.1 8.8.4.4
  7. #Domains=~.
  8. #LLMNR=yes
  9. #MulticastDNS=yes
  10. #Cache=yes
  11. #DNSStubListener=yes
  12. #ReadEtcHosts=yes

关于选项的简要说明:

  • DNS:以空格分隔的 IPv4 和 IPv6 地址列表,用作系统 DNS 服务器。
  • FallbackDNS:以空格分隔的 IPv4 和 IPv6 地址列表,用作后备 DNS 服务器。
  • Domains:在解析单标签主机名时,这些域名用于搜索后缀。 ~. 代表对于所有域名,优先使用 DNS= 定义的系统 DNS 服务器。
  • DNSOverTLS:如果启用,那么将加密与服务器的所有连接。请注意,此模式要求 DNS 服务器支持 DNS-over-TLS,并具有其 IP 的有效证书。

注意:上面示例中列出的 DNS 服务器是我个人的选择。你要确定要使用的 DNS 服务器。要注意你要向谁请求 IP。

步骤 2:告诉 NetworkManager 将信息推给 systemd-resolved

在 /etc/NetworkManager/conf.d 中创建一个名为 10-dns-systemd-resolved.conf 的文件。

  1. $ cat /etc/NetworkManager/conf.d/10-dns-systemd-resolved.conf
  2. [main]
  3. dns=systemd-resolved

上面的设置(dns=systemd-resolved)让 NetworkManager 将从 DHCP 获得的 DNS 信息推送到 systemd-resolved 服务。这将覆盖步骤 1 中配置的 DNS 设置。这在受信任的网络中没问题,但是也可以设置为 dns=none 从而使用 /etc/systemd/resolved.conf 中配置的 DNS 服务器。

步骤 3: 启动和重启服务

若要使上述步骤中的配置生效,请启动并启用 systemd-resolved 服务。然后重启 NetworkManager 服务。

注意:在 NetworkManager 重启时,连接会中断几秒钟。

  1. $ sudo systemctl start systemd-resolved
  2. $ sudo systemctl enable systemd-resolved
  3. $ sudo systemctl restart NetworkManager

注意:目前,systemd-resolved 服务默认处于禁用状态,是可选使用的。[有计划][33]在 Fedora 33 中默认启用systemd-resolved。

步骤 4:检查是否一切正常

现在,你应该在使用 DNS over TLS。检查 DNS 解析状态来确认这一点:

  1. $ resolvectl status
  2. MulticastDNS setting: yes
  3. DNSOverTLS setting: yes
  4. DNSSEC setting: yes
  5. DNSSEC supported: yes
  6. Current DNS Server: 1.1.1.1
  7. DNS Servers: 1.1.1.1
  8. 9.9.9.9
  9. Fallback DNS Servers: 8.8.8.8
  10. 1.0.0.1
  11. 8.8.4.4

/etc/resolv.conf 应该指向 127.0.0.53

  1. $ cat /etc/resolv.conf
  2. # Generated by NetworkManager
  3. search lan
  4. nameserver 127.0.0.53

若要查看 systemd-resolved 发送和接收安全查询的地址和端口,请运行:

  1. $ sudo ss -lntp | grep '\(State\|:53 \)'
  2. State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
  3. LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=10410,fd=18))

若要进行安全查询,请运行:

  1. $ resolvectl query fedoraproject.org
  2. fedoraproject.org: 8.43.85.67 -- link: wlp58s0
  3. 8.43.85.73 -- link: wlp58s0
  4.  
  5. [..]
  6.  
  7. -- Information acquired via protocol DNS in 36.3ms.
  8. -- Data is authenticated: yes

额外步骤 5:使用 Wireshark 验证配置

首先,安装并运行 Wireshark

  1. $ sudo dnf install wireshark
  2. $ sudo wireshark

它会询问你在哪个设备上捕获数据包。在我这里,因为我使用无线接口,我用的是 wlp58s0。在 Wireshark 中设置筛选器,tcp.port == 853(853 是 DNS over TLS 协议端口)。在捕获 DNS 查询之前,你需要刷新本地 DNS 缓存:

  1. $ sudo resolvectl flush-caches

现在运行:

  1. $ nslookup fedoramagazine.org

你应该会看到你的计算机和配置的 DNS 服务器之间的 TLS 加密交换:

 

 


 

 

责任编辑:庞桂玉 来源: Linux中国
相关推荐

2017-10-26 09:08:00

Android 8.1

2020-01-02 10:51:09

DNSHTTPS安全性

2022-07-15 16:29:16

微软Windows 11

2019-07-31 10:36:38

FirefoxDNS-over-HT浏览器

2011-03-08 14:14:31

Proftpd

2021-06-30 14:05:08

DNSWindows 11HTTPS

2021-03-22 10:01:06

Edge浏览器问题修复

2021-06-21 11:25:54

GoTLS语言

2023-06-06 14:55:29

Firefox浏览器

2010-10-25 13:33:10

Oracle over

2021-07-09 14:52:58

MozillaFirefoxDNS-over-HT

2011-04-08 15:50:54

Oracleover函数

2021-03-21 19:53:06

微软Edge浏览器

2009-09-22 12:20:12

ibmdwLotus

2021-06-30 18:11:56

Windows 11操作系统微软

2020-08-05 08:31:51

SSL TLSNode.js

2021-03-25 14:41:05

TLS1.0IETF浏览器

2018-06-28 09:06:27

DNS技术CDN

2019-04-02 09:01:47

CoreDNSDNS污染

2016-10-31 10:25:24

点赞
收藏

51CTO技术栈公众号