systemd-resolved+VPN:忽略第二个 DNS 服务器(L2TP)

systemd-resolved+VPN:忽略第二个 DNS 服务器(L2TP)

我正在通过网络管理器-l2tp 使用预共享密钥和用户+密码连接到公司 VPN。我会自动获取正确的 DNS 服务器 IP,从而正确解析公司 URL。

但是,公共互联网尚未解决(我测试过www.google.com一直),但这取决于角度:我无法让 systemd-resolved 同时从 2 个 DNS 服务器(1.1.1.1 和公司 DNS)进行解析。严格来说,要么是要么,我尝试了很多不同的配置......

问题:如何配置 systemd-resolved 以同时使用企业 VPN 的 DNS 和常规 DNS 服务器?

我不在乎它是基于域的“条件转发”还是在第一个 DNS 失败后使用第二个 DNS。这两种方法我都无法工作。我的猜测是这与 l2tp 有关,但我找不到任何适用于我的情况的解决方案。

我在 Pop OS 上使用:NetworkManager 1.30.0、systemd-resolved (systemd 247.3) 和 openresolv(而不是旧的 resolvconf)。两项服务均已启动并正在运行。

resolv.conf -> /run/systemd/resolve/stub-resolv.conf

# This file is managed by man:systemd-resolved(8). Do not edit.
[...]

nameserver 127.0.0.53
options edns0 trust-ad
search fritz.box

/etc/systemd/resolved.conf

[Resolve]
FallbackDNS=1.1.1.1 corp.ip.add.ress

resolvectl status连接VPN后的输出

Global
           Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
    resolv.conf mode: stub
Fallback DNS Servers: 1.1.1.1 corp.ip.add.ress

Link 2 (enp6s0)
    Current Scopes: DNS
         Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.168.178.1
       DNS Servers: 192.168.178.1
        DNS Domain: fritz.box

Link 3 (ip_vti0)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

Link 23 (ppp0)
    Current Scopes: DNS
         Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: corp.ip.add.ress
       DNS Servers: 1.1.1.1 corp.ip.add.ress

我尝试了很多不同的方法,但是您在上面看到的内容是提出可靠的最终解决方案的一个很好的起点。

答案1

您可以通过以下配置实现拆分 DNS(条件转发)(假设ppp0是您的 VPN 接口,enp6s0 是您的常规 LAN):

resolvectl dns ppp0 corp.ip.add.ress
resolvectl domain ppp0 ~corp.domain.name
resolvectl default-route ppp0 false
resolvectl default-route enp6s0 true

这将为所有查询使用默认 DNS,域名以 结尾的查询除外corp.domain.name。对于这些查询,它将使用corp.ip.add.ress.另请注意,必须更正默认路由,因为连接到 VPN 可能会导致更新默认路由。

相关内容