跳转到内容
搜索 AlmaLinux 文档

    浏览当前文档目录

    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。

    $ ss -lunp | grep ':53 '
    UNCONN 0 0 127.0.0.54:53 ... systemd-resolve
    UNCONN 0 0 127.0.0.53%lo:53 ... systemd-resolve
    UNCONN 0 0 192.168.2.241:53 ... dnsmasq
    • 127.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.test
    web.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 ens18
    Link 2 (ens18)
    Current Scopes: DNS
    Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
    Current 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 验证

    装了 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 验证。
    Terminal window
    resolvectl status ens18 | sed -n '1,10p'
    ss -lunp | grep ':53 '
    resolvectl query web.lab.test
    sudo resolvectl flush-caches
    resolvectl statistics | head -6

    检查:

    1. 三个监听地址与进程对应关系;
    2. DNS Domain 是否带 ~;
    3. 查询结果是否标注 -- link: ens18;
    4. flush-caches 后 statistics 的 cache 计数归零。

    常见问题

    resolved 和 dnsmasq 必须二选一吗?

    不必。它们可以共存:resolved 管本机解析入口,dnsmasq 管局域网提供服务,只要绑不同地址。

    DNSSEC 怎么打开?

    在 resolved 配置里设 DNSSEC=yes(或 allow-downgrade),再用 resolvectl query 看结果里的验证状态。

    为什么 /etc/resolv.conf 是符号链接?

    resolved 接管了它;这是预期状态,手工改会被下次启动覆盖。