Debian 系统出现域名解析失败,一般不是单一原因,可以按下面顺序排查。我按最常见 → 较少见给你一个完整排查流程。
ping -c 3 8.8.8.8
✅ 能通 → 网络没问题,问题在 DNS
❌ 不通 → 网络本身有问题(路由 / 网关 / 防火墙)
cat /etc/resolv.conf
正常应看到类似:
nameserver 8.8.8.8
nameserver 114.114.114.114
❌ 如果看到:
127.0.0.1127.0.0.53说明 systemd-resolved / resolvconf 在管理 DNS
nmcli dev show | grep DNS
修改 DNS:
nmcli connection modify eth0 ipv4.dns "8.8.8.8 114.114.114.114"
nmcli connection up eth0
/etc/network/interfaces(服务器常见)编辑:
nano /etc/network/interfaces
示例:
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 114.114.114.114
重启网络:
systemctl restart networking
systemctl status systemd-resolved
查看 DNS:
resolvectl status
手动设置 DNS(示例):
resolvectl dns eth0 8.8.8.8
dig www.baidu.com
nslookup www.google.com
如果返回 IP,说明 DNS 已恢复。
iptables -L -n
DNS 使用 UDP 53,如果被 DROP 会解析失败。
/etc/resolv.conf 是软链接ls -l /etc/resolv.conf
常见情况:
/etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
✅ 正常
但如果 systemd-resolved 没启动就会失败。
解决:
systemctl enable systemd-resolved
systemctl start systemd-resolved
| 现象 | 原因 |
|---|---|
| 能 ping IP 不能 ping 域名 | DNS |
| resolv.conf 总被覆盖 | NetworkManager / systemd |
| 容器里解析失败 | 宿主机 DNS |
| 重启就失效 | DNS 写入错误位置 |
| 国内服务器慢 | 用了国外 DNS |
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 114.114.114.114" >> /etc/resolv.conf
⚠️ 如果是桌面版 Debian,可能重启后又恢复,需要配合 NM 或 systemd 设置。
如果你愿意,可以贴出下面信息,我可以精准定位:
cat /etc/os-release
cat /etc/resolv.conf
ip a
ip route
systemctl status systemd-resolved
是 物理机 / 虚拟机 / Docker / WSL / 云服务器 哪一种?