Debian 系统里“域名解析变慢”是一个比较常见的问题,通常不是 Debian 本身慢,而是DNS 解析链路出了问题。下面按最常见原因 → 排查方法 → 解决方式给你梳理一下。
Debian 默认可能使用了:
/etc/resolv.conf 里写的公共 DNS 但不稳定表现
ping 域名 慢,但 ping IP 很快排查
time nslookup example.com
如果耗时 > 1s,就是 DNS 问题。
解决 修改 DNS(推荐):
sudo nano /etc/resolv.conf
nameserver 223.5.5.5
nameserver 8.8.8.8
⚠️ 如果是 DHCP,需要改网络配置或 NetworkManager。
Debian 使用 systemd-resolved 时,可能:
检查
resolvectl status
重启
sudo systemctl restart systemd-resolved
如果 hosts 行里有:
hosts: files mdns4_minimal [NOTFOUND=return] dns
在没有 mDNS 环境时,会先尝试 mDNS,导致明显延迟。
解决 改为:
hosts: files dns
Debian 默认启用 IPv6,但网络不支持时:
表现
apt update 很慢curl 域名慢解决 禁用 IPv6 DNS:
sudo nano /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
sudo sysctl -p
或在 resolv.conf:
options single-request
如果你是:
解决 换国内镜像:
sudo sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list
sudo apt update
# 1. 看 DNS 是否慢
time nslookup debian.org
# 2. 看解析顺序
cat /etc/nsswitch.conf | grep hosts
# 3. 看当前 DNS
resolvectl status
# 4. 看是否 IPv6 问题
ip a | grep inet6
Debian 域名变慢,99% 是 DNS 服务器慢 / IPv6 / mDNS / systemd-resolved 配置问题,不是系统本身慢。
如果你愿意,可以把下面信息发我,我可以直接帮你定位:
/etc/resolv.confresolvectl status我可以给你一套最合适的具体配置。