Rootop 服务器运维与web架构

ubuntu24 dns配置-systemd-resolved

系统版本:Ubuntu 24.04

# 查看传统dns配置文件
root@rd:~# cat /etc/resolv.conf | grep -Ev "^#|^$"
nameserver 127.0.0.53
options edns0 trust-ad
search .

上面3个参数的解释
将 DNS 请求发送给本地 systemd-resolved 的 stub 代理
开启 DNS 扩展(EDNS0)并信任上游的 DNSSEC 验证状态
空值,表示不追加任何搜索域

# 同时此文件是一个软链接
root@rd:~# ll /etc/resolv.conf 
lrwxrwxrwx 1 root root 39 Apr 23  2024 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf

# 查看本地是否监听53
root@rd:~# netstat -tnlp | grep -w 53
tcp        0      0 127.0.0.54:53           0.0.0.0:*               LISTEN      857/systemd-resolve 
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      857/systemd-resolve 

可以看到是由 systemd-resolve 进程控制,实际为 systemd-resolved 服务

# 修改服务配置文件 /etc/systemd/resolved.conf
找到 [Resolve] 区块,修改如下:
[Resolve]
DNS=8.8.8.8 1.1.1.1
FallbackDNS=9.9.9.9
DNSStubListener=yes

上面3个参数的解释:
主DNS服务器列表,优先使用这些服务器解析域名。多个地址之间用空格隔开,按顺序尝试。
当主DNS不可用或响应失败时使用的备用DNS。
启用或禁用本地DNS stub监听器,它通常监听在 127.0.0.53:53


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

验证 DNS 是否更新:
resolvectl status
resolvectl flush-caches 


也可以修改 /etc/netplan/*.yaml 下配置文件,最终也会是由systemd-resolved接管新的配置。


DHCP 获取的 DNS 也会被 systemd-resolved 接收。
#########################
root@rd:~# resolvectl status
Global
         Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: stub

Link 2 (ens33)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 8.8.8.8
       DNS Servers: 8.8.4.4

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/5578.html

作者:Venus

服务器运维与性能优化

评论已关闭。