我的网络如下所示:
┌────────────┐ ┌────────────┐ ┌────────────┐
│Notebook │ │ FW/DNS │ │ISP ROUTER │
│ arch linux ├─────►│mapping: ├───►│192.168.2.1 │
│ │ │speedport.ip│ │speedport.ip│
│ │ │192.168.2.1 │ │ │
└────────────┘ └────────────┘ └────────────┘
FW(防火墙)为我的网络(笔记本)执行 DNS。因此“speedport.ip”无法正常解析。但是,我在 FW 上进行了映射:
speedport.ip->192.168.2.1
我可以使用以下方法在笔记本上进行验证:
# dig speedport.ip
; <<>> DiG 9.18.15 <<>> speedport.ip
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17333
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;speedport.ip. IN A
;; ANSWER SECTION:
speedport.ip. 3600 IN A 192.168.2.1
;; Query time: 0 msec
;; SERVER: 192.168.3.2#53(192.168.3.2) (UDP)
;; WHEN: Fri Oct 27 07:53:46 UTC 2023
;; MSG SIZE rcvd: 57
我还使用 tcpdump 验证了 dns 包已发送:
# tcpdump udp port 53
listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
08:03:43.974915 IP notebook.mydomain.xyz.46555 > fw.mydomain.xyz.domain: 26+ [1au] A? speedport.ip. (53)
08:03:43.975175 IP fw.mydomain.xyz.domain > notebook.mydomain.xyz.46555: 26* 1/0/1 A 192.168.2.1 (57)
问题是,当我执行以下操作时:
[root@notebook]# curl http://speedport.ip
curl: (6) Could not resolve host: speedport.ip
[root@notebook]# ping speedport.ip
ping: speedport.ip: Name or service not known
也没有发送任何 dns 查询(不会显示在 tcpdump 中)。所以我的问题是:
为什么没有发送 DNS 查询?
顺便说一句,我可以将此条目添加到笔记本的 /etc/hosts 文件中。然后它就可以正常工作了。
编辑:
[root@notebook]# cat /etc/nsswitch.conf
# Name Service Switch configuration file.
# See nsswitch.conf(5) for details.
passwd: files systemd
group: files [SUCCESS=merge] systemd
shadow: files systemd
gshadow: files systemd
publickey: files
hosts: mymachines resolve [!UNAVAIL=return] files myhostname dns
networks: files
protocols: files
services: files
ethers: files
rpc: files
netgroup: files
[root@notebook]# cat /etc/resolv.conf
search mydomain.xyz
nameserver 192.168.3.2
编辑2:
[root@notebook]# resolvectl
Global
Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: foreign
Current DNS Server: 192.168.3.2
DNS Servers: 192.168.3.2
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
DNS Domain: mydomain.xyz
Link 2 (eth0)
Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.168.3.2
DNS Servers: 192.168.3.2