1. 首页 > Linux教程 > 正文

Linux教程FG210-DNS解析故障排查

内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。

本文档详细介绍DNS解析故障的排查方法

风哥提示:

,包括DNS配置检查、解析测试、故障诊断等内容。

Part01-DNS基础检查

1.1 检查DNS配置

# 查看DNS配置文件
$ cat /etc/resolv.conf
# Generated by NetworkManager
search fgedu.net.cn
nameserver 192.168.1.1
nameserver 8.8.8.8

# 查看NetworkManager DNS配置
$ nmcli dev show | grep DNS
IP4.DNS[1]: 更多学习教程公众号风哥教程itpux_com 192.168.1.1
IP4.DNS[2]: 8.更多视频教程www.fgedu.net.cn8.8.8

# 查看hosts文件
$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.100 server.fgedu.net.cn server

# 检查nsswitch配置
$ grep hosts /etc/nsswitch.conf
hosts: files dns myhostname

Part02-DNS解析测试

2.1 使用dig命令测试

# 安装bind-utils
$ sudo dnf install -y bind-utils

# 基本DNS查询
$ dig www.google.com

; <<>> DiG 9.16.23 <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12345 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;www.google.com. IN A ;; ANSWER SECTION: www.google.com. 300 IN A 142.250.185.68 ;; Query time: 15 msec ;; SERVER: 192.168.1.1#53(192.168.1.1) ;; WHEN: Thu Apr 03 19:30:00 CST 2026 ;; MSG SIZE rcvd: 59 # 指定DNS服务器查询 $ dig @8.8.8.8 www.google.com ; <<>> DiG 9.16.23 <<>> @8.8.8.8 www.google.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12346 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 512 ;; QUESTION SECTION: ;wfrom PG视频:www.itpux.comww.google.com. IN A ;; ANSWER SECTION: www.google.com. 300 IN A 142.250.185.68 ;; Query time: 10 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) ;; WHEN: Thu Apr 03 19:30:30 CST 2026 ;; MSG SIZE rcvd: 59 # 查询MX记录 $ dig google.com MX ; <<>> DiG 9.16.23 <<>> google.com MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12347 ;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;google.com. IN MX ;; ANSWER SECTION: google.com. 600 IN MX 10 smtp.google.com. ;; Query time: 20 msec ;; SERVER: 192.168.1.1#53(192.168.1.1) ;; WHEN: Thu Apr 03 19:31:00 CST 2026 ;; MSG SIZE rcvd: 78 # 反向DNS查询 $ dig -x 8.8.8.8 ; <<>> DiG 9.16.23 <<>> -x 8.8.8.8
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12348 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;8.8.8.8.in-addr.arpa. IN PTR ;; ANSWER SECTION: 8.8.8.8.in-addr.arpa. 21600 IN PTR dns.google. ;; Query time: 25 msec ;; SERVER: 192.168.1.1#53(192.168.1.1) ;; WHEN: Thu Apr 03 19:31:30 CST 2026 ;; MSG SIZE rcvd: 83

Part03-nslookup和host命令

3.1 使用nslookup测试

# 基本查询
$ nslookup www.google.com
Server: 192.168.1.1
Address: 192.168.1.1#53

Non-authoritative answer:
Name: www.google.com
Address: 142.250.185.68

# 指定DNS服务器
$ nslookup www.google.com 8.8.8.8
Server: 8.8.8.8
Address: 8.8.8.8#53

Non-authoritative answer:
Name: www.google.com
Address: 142.250.185.68

# 交互模式
$ nslookup
> server 8.8.8.8
Default server: 8.8.8.8
Address: 8.8.8.8#53
> www.google.com
Server: 8.学习交流加群风哥微信: itpux-com8.8.8
Address: 8.8.8.8#53

Non-authoritative answer:
Name: www.google.com
Address: 142.250.185.68
> exit

# 使用host命令
$ host www.google.com
www.google.com has address 142.250.185.68

$ host google.com
google.com has address 142.250.185.78
google.com mail is handled by 10 smtp.google.com.

# 反向查询
$ host 8.8.8.8
8.8.8.8.in-addr.arpa domain name pointer dns.google.

Part04-DNS故障诊断

4.1 常见DNS故障排查

# 1. 检查DNS服务器连通性
$ ping -c 3 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.521 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.489 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.512 ms

— 192.168.1.1 ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2049ms

# 2. 检查DNS端口
$ nc -zv 192.168.1.1 53
Ncat: Version 7.92 ( https://nmap.org/ncat )
Ncat: Connected to 192.168.1.1:53.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.

# 3. 检查DNS响应时间
$ dig www.google.com | grep “Query time”
;; Query time: 15 msec

# 4. 检查DNS缓存
$ sudo systemd-resolve –statistics
DNSSEC supported by current zones: no
Transactions
Current Transactions: 0
Total Transactions: 12345
Transactions per second: 0.1
Cache
Current Cache Size: 100
Cache Hits: 10000
Cache Misses: 2345
Cache hit ratio: 81.0%

# 5. 清除DNS缓存
$ sudo systemd-resolve –flush-caches

# 6. 检查DNS解析顺序
$ getent hosts www.google.com
142.250.185.68 www.google.com

# 7. 测试DNS解析
$ host -v www.google.com
Trying “www.google.com”
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12349 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;www.google.com. IN A ;; ANSWER SECTION: www.google.com. 300 IN A 142.250.185.68 Received 59 bytes from 192.168.1.1#53 in 15 ms

Part05-DNS配置修复

5.1 修复DNS配置

# 使用nmcli修改DNS
$ sudo nmcli connection modify eth0 ipv4.dns “8.8.8.8 8.8.4.4”

# 重新激活连接
$ sudo nmcli connection up eth0
Connection successfully activated

# 验证DNS配置
$ cat /etc/resolv.conf
# Generated by NetworkManager
search fgedu.net.cn
nameserver 8.8.8.8
nameserver 8.8.4.4

# 手动修改resolv.conf(临时)
$ sudo tee /etc/resolv.conf << EOF nameserver 8.8.8.8 nameserver 8.8.4.4 search fgedu.net.cn EOF # 禁用NetworkManager管理DNS $ sudo nmcli connection modify eth0 ipv4.ignore-auto-dns yes # 配置本地DNS缓存 $ sudo dnf install -y dnsmasq $ sudo tee /etc/dnsmasq.conf << EOF server=8.8.8.8 server=8.8.4.4 cache-size=1000 listen-address=127.0.0.1 EOF $ sudo systemctl enable --now dnsmasq $ sudo tee /etc/resolv.conf << EOF nameserver 127.0.0.1 search fgedu.net.cn EOF # 测试DNS解析 $ dig www.google.com @127.0.0.1 ; <<>> DiG 9.16.23 <<>> www.google.com @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12350 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;www.google.com. IN A ;; ANSWER SECTION: www.google.com. 300 IN A 142.250.185.68 ;; Query time: 1 msec ;; SERVER: 127.0.0.1#53(127.0.0.1) ;; WHEN: Thu Apr 03 19:35:00 CST 2026 ;; MSG SIZE rcvd: 59

风哥针对排查建议:
1. 检查DNS服务器配置是否正确
2. 测试DNS服务器连通性
3. 使用多种工具验证解析结果
4. 检查DNS缓存和解析顺序
5. 配置备用DNS服务器提高可用性

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息