修改 /etc/systemd/resolved.conf
, 写入自定义的 DNS 地址,多个地址使用空格分隔:
[Resolve]
DNS=1.1.1.1 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001
创建软连接覆盖系统的 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