我的 DNS 自行更改,但无法通过 /etc/resolv.conf 观察到其更改

我的 DNS 自行更改,但无法通过 /etc/resolv.conf 观察到其更改

我制作了一个脚本来打印 /etc/resolv.conf 和 ping 结果www.reddit.com每一秒。我使用了 Cloudflare 的 DNS (1.1.1.1),因为 reddit 在我的国家/地区被屏蔽,但可以使用 DNS 绕过。似乎在登录我的桌面大约 10 秒后,我的 DNS 返回到我的默认网关 (192.168.1.1)。我该如何保持我的 DNS 为 1.1.1.1?

我的脚本:

#! /bin/bash

while true
do
    cat /etc/resolv.conf
    ping -c 1 www.reddit.com | grep "ping statistics" | sed "s/--- /$(date) /" | sed "s/ ping statistics ---//"
    sleep 1
done

重启并登录后立即运行结果:

# Generated by NetworkManager
nameserver 1.1.1.1
nameserver 1.0.0.1
Sat Aug 19 11:19:49 AM WIB 2023 reddit.map.fastly.net
# Generated by NetworkManager
nameserver 1.1.1.1
nameserver 1.0.0.1
Sat Aug 19 11:19:58 AM WIB 2023 reddit.map.fastly.net
# Generated by NetworkManager
nameserver 1.1.1.1
nameserver 1.0.0.1
Sat Aug 19 11:20:07 AM WIB 2023 reddit.map.fastly.net
# Generated by NetworkManager
nameserver 1.1.1.1
nameserver 1.0.0.1
Sat Aug 19 11:20:16 AM WIB 2023 trustpositif.kominfo.go.id
# Generated by NetworkManager
nameserver 1.1.1.1
nameserver 1.0.0.1
Sat Aug 19 11:20:17 AM WIB 2023 trustpositif.kominfo.go.id
# Generated by NetworkManager
nameserver 1.1.1.1
nameserver 1.0.0.1
Sat Aug 19 11:20:18 AM WIB 2023 trustpositif.kominfo.go.id

更多信息:

❯ nslookup www.reddit.com 1.1.1.1
Server:     1.1.1.1
Address:    1.1.1.1#53

Non-authoritative answer:
www.reddit.com  canonical name = reddit.map.fastly.net.
Name:   reddit.map.fastly.net
Address: 151.101.129.140
Name:   reddit.map.fastly.net
Address: 151.101.1.140
Name:   reddit.map.fastly.net
Address: 151.101.65.140
Name:   reddit.map.fastly.net
Address: 151.101.193.140

❯ nslookup www.reddit.com 192.168.1.1
Server:     192.168.1.1
Address:    192.168.1.1#53

Non-authoritative answer:
www.reddit.com  canonical name = trustpositif.kominfo.go.id.
Name:   trustpositif.kominfo.go.id
Address: 27.54.116.70

❯ grep hosts /etc/nsswitch.conf
hosts: mymachines resolve [!UNAVAIL=return] files myhostname dns

❯ resolvectl
Global
           Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
    resolv.conf mode: foreign
  Current DNS Server: 1.0.0.1
         DNS Servers: 1.1.1.1 1.0.0.1
Fallback DNS Servers: 1.1.1.1#cloudflare-dns.com 9.9.9.9#dns.quad9.net 8.8.8.8#dns.google 2606:4700:4700::1111#cloudflare-dns.com 2620:fe::9#dns.quad9.net
                      2001:4860:4860::8888#dns.google

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

Link 4 (wlan0)
    Current Scopes: DNS LLMNR/IPv4 mDNS/IPv4
         Protocols: +DefaultRoute +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.168.1.1
       DNS Servers: 192.168.1.1

答案1

您的系统正在使用systemd-resolved其主要 DNS 解析器(关键字位于resolve之前),因此只有在未运行时才会使用。dnsnsswitch.conf/etc/resolv.confsystemd-resolved

运行resolvectl以查看您的真实 DNS 设置。

/etc/resolv.conf在您的系统上实际上已过时。

相关内容