修改 /etc/systemd/resolved.conf, 写入自定义的 DNS 地址,多个地址使用空格分隔:

vi /etc/systemd/resolved.conf

[Resolve]
#cloudflare
DNS=1.1.1.1 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001
#阿里/腾讯
DNS=223.5.5.5 119.29.29.29 2400:3200::1 2402:4e00::

创建软连接覆盖系统的 resolv.conf,让系统使用 systemd-resolved 生成的配置:

ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

重启 systemd-resolved 服务,使配置生效:

service systemd-resolved restart

测试一下是否生效了:

nslookup github.com

输出结果:

Server:		1.1.1.1
Address:	1.1.1.1#53

Non-authoritative answer:
Name:	github.com
Address: 140.82.112.4

systemd-resolve --status 可以查询当前设置的状态:

Global
       LLMNR setting: yes
MulticastDNS setting: yes
  DNSOverTLS setting: no
      DNSSEC setting: allow-downgrade
    DNSSEC supported: yes
         DNS Servers: 1.1.1.1
                      1.0.0.1
                      2606:4700:4700::1111
                      2606:4700:4700::1001
          DNSSEC NTA: ...
          ...

开机自动启动 systemd-resolved

service systemd-resolved restart 是临时启动服务,重启后就失效了。

需要把 systemd-resolved 服务设置为开机启动才能永久生效:

systemctl enable systemd-resolved
Categories: 未分类

0 Comments

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注