AlmaLinux 10:一台机器上三个 53 端口监听,谁在回答谁
AlmaLinux 10.2 Server 组虚拟机,systemd-resolved-257-23.el10_2.1.alma.1 + dnsmasq-2.90。
场景:本机既是局域网 DNS(dnsmasq 监听 192.168.2.241:53),又装了 systemd-resolved 作为系统解析入口。截图:public/evidence/resolved/alma-coexist.png。
三个监听,互不冲突
Section titled “三个监听,互不冲突”$ ss -lunp | grep ':53 'UNCONN 0 0 127.0.0.54:53 ... systemd-resolveUNCONN 0 0 127.0.0.53%lo:53 ... systemd-resolveUNCONN 0 0 192.168.2.241:53 ... dnsmasq127.0.0.53:resolved 的 stub,本机程序通过它解析;127.0.0.54:resolved 的 DNS-over-TLS/代理监听(默认开启);192.168.2.241:53:dnsmasq 对局域网提供服务。
三者绑定不同地址,因此能同时存在。真正会冲突的是「两个进程都想绑 0.0.0.0:53」——这通常发生在 bind-interfaces 没配的时候。
让 resolved 把某个域指回本机 dnsmasq
Section titled “让 resolved 把某个域指回本机 dnsmasq”$ resolvectl dns ens18 192.168.2.241$ resolvectl domain ens18 '~lab.test'$ resolvectl query web.lab.testweb.lab.test: 192.168.2.241 -- link: ens18注意上游写的是 192.168.2.241 而不是 127.0.0.1:dnsmasq 只绑在这个地址上,指 127.0.0.1 会得到 Connection refused(我们第一次就踩了这个坑)。
读 resolvectl status
Section titled “读 resolvectl status”$ resolvectl status ens18Link 2 (ens18) Current Scopes: DNS Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupportedCurrent DNS Server: 192.168.2.241 DNS Servers: 192.168.2.241 DNS Domain: ~lab.test判读要点:
| 字段 | 含义 |
|---|---|
Current Scopes: DNS | 该链路参与了 DNS 选路 |
Current DNS Server | 实际会被使用的服务器 |
DNS Domain: ~lab.test | 带 ~ 即 routing domain |
DNSSEC=no/unsupported | 当前未启用 DNSSEC 验证 |
/etc/resolv.conf 的真实身份
Section titled “/etc/resolv.conf 的真实身份”装了 resolved 后,/etc/resolv.conf 通常变成指向 /run/systemd/resolve/stub-resolv.conf 的符号链接。这意味着:
- 手工编辑它不会改变 resolved 的行为,重启即被覆盖;
- 想改解析路径,应该改 resolved 的链路配置(
resolvectl或nmcli); - 想绕过 resolved,要么停用它,要么让程序直连外部服务器。
- 把上游写成
127.0.0.1:本机 53 被 stub 占着,dnsmasq 不在那个地址上; - 以为 stub 就是「真正的 DNS」:它只是本机代理,答案仍来自上游;
- 两份配置打架:
nmcli与resolvectl都改 DNS 时,以连接激活时的 NM 配置为准; dig @127.0.0.53失败就以为坏了:stub 不响应任意查询格式,用resolvectl query验证。
练习:把链路配置看清楚
Section titled “练习:把链路配置看清楚”resolvectl status ens18 | sed -n '1,10p'ss -lunp | grep ':53 'resolvectl query web.lab.testsudo resolvectl flush-cachesresolvectl statistics | head -6检查:
- 三个监听地址与进程对应关系;
DNS Domain是否带~;- 查询结果是否标注
-- link: ens18; flush-caches后statistics的 cache 计数归零。
常见问题
resolved 和 dnsmasq 必须二选一吗?
不必。它们可以共存:resolved 管本机解析入口,dnsmasq 管局域网提供服务,只要绑不同地址。
DNSSEC 怎么打开?
在 resolved 配置里设 DNSSEC=yes(或 allow-downgrade),再用 resolvectl query 看结果里的验证状态。
为什么 /etc/resolv.conf 是符号链接?
resolved 接管了它;这是预期状态,手工改会被下次启动覆盖。
- resolved 基础:/systemd-resolved/
- dnsmasq:/dnsmasq-lab/
- 网络基础:/network-basics/