我在无头服务器上运行 Ubuntu 22.04.1,并尝试更改服务器使用的 DNS。我像这样设置 netplan .yaml 文件以使用 Cloudflare 的服务器:
network:
version: 2
renderer: networkd
ethernets:
enp0s31f6:
addresses:
- xxx.xxx.xxx.xxx/32
- xxxx.xxxx.xxx::2/64
routes:
- to: default
via: xxx.xxx.xxx.xxx
metric: 100
on-link: true
- to: ::/0
via: fe80::1
nameservers:
addresses:
- 1.1.1.1
- 2606:4700:4700::1111
- 1.0.0.1
- 2606:4700:4700::1001
经过一段时间后sudo netplan apply
,一切似乎都顺利。只是nslookup somewebsite.com
显示使用的 DNS 是 8.8.8.8。
我认为,我追溯了这个问题的根源到 /etc/resolv.conf 文件,它不是一个符号链接,它看起来像这样:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual #nameservers.
#nameserver 127.0.0.53
nameserver 8.8.8.8
该文件不仅表示不可编辑,而且实际上也无法编辑。而且我确信,如果我编辑它,它将被 Google 名称服务器覆盖(我猜是被 resolvconf 覆盖)。
现在我检查的所有东西都正确无误,除了实际使用的 DNS 顽固地停留在 8.8.8.8。
例如,sudo networkctl status enp0s31f6
返回以下内容:
● 2: enp0s31f6
Link File: /usr/lib/systemd/network/99-default.link
Network File: /run/systemd/network/10-netplan-enp0s31f6.network
Type: ether
State: routable (configured)
Online state: online
Path: pci-0000:00:1f.6
Driver: e1000e
Vendor: Intel Corporation
Model: Ethernet Connection (2) I219-LM
HW Address: xx:xx:xx:xx:xx:xx (Fujitsu Technology Solutions GmbH)
MTU: 1500 (min: 68, max: 9000)
QDisc: pfifo_fast
IPv6 Address Generation Mode: eui64
Queue Length (Tx/Rx): 1/1
Auto negotiation: yes
Speed: 1Gbps
Duplex: full
Port: tp
Address: xxx.xxx.xxx.xxx
xxxx:xxx:xx:xxxx::2
xxxx::xxxx:xxx:xxxx:xxxx
Gateway: xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx
fe80::1
DNS: 1.1.1.1
1.0.0.1
2606:4700:4700::1111
2606:4700:4700::1001
Activation Policy: up
Required For Online: yes
DHCP6 Client DUID: DUID-EN/Vendor:0000ab11edfd2edd2491a9410000
并sudo resolvctl status
给出:
Global
Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: foreign
Current DNS Server: 1.1.1.1
DNS Servers: 1.1.1.1
Fallback DNS Servers: 1.0.0.1
Link 2 (enp0s31f6)
Current Scopes: DNS
Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 1.1.1.1
DNS Servers: 1.1.1.1 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001
Link 8 (wg0)
Current Scopes: none
Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
因此,我看到的所有内容都告诉我 1.1.1.1 是我服务器的主 DNS。除了nslookup askubuntu.com
它总是顽固地返回以下内容:
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: askubuntu.com
Address: 151.101.65.69
Name: askubuntu.com
Address: 151.101.193.69
Name: askubuntu.com
Address: 151.101.129.69
Name: askubuntu.com
Address: 151.101.1.69
sudo tcpdump -n -vv -i enp0s31f6 -W 1200 | grep google.com
我通过在一个窗口中运行而在另一个窗口中运行时验证了 8.8.8.8 确实正在被使用nslookup google.com
。
我怎样才能让我的服务器停止使用 8.8.8.8 并开始使用我一直尝试运行的 DNS?