解决阿里云ECS服务器不能解析外部DNS的问题

首选方案:彻底修复系统 DNS(永久生效)
1. 修改 systemd-resolved 配置写入公共上游 DNS

cat > /etc/systemd/resolved.conf <<EOF
[Resolve]
DNS=223.5.5.5 114.114.114.114
FallbackDNS=8.8.8.8
DNSSEC=no
MulticastDNS=no
LLMNR=no
Cache=yes
EOF

 

2. 重启 DNS 服务

systemctl restart systemd-resolved
systemctl status systemd-resolved

 

3. 验证本地DNS解析

nslookup swr.cn-north-4.myhuaweicloud.com

 

备选方案:直接干掉 systemd-resolved 软链接,静态锁定 resolv.conf(最稳)

Ubuntu 默认 /etc/resolv.conf 是指向 /run/systemd/resolve/stub-resolv.conf 的软链接,会自动覆盖:

# 删除软链接
rm -f /etc/resolv.conf
# 写入静态DNS
cat > /etc/resolv.conf << EOF
nameserver 223.5.5.5
nameserver 114.114.114.114
EOF
# 锁定文件,系统无法自动覆盖
chattr +i /etc/resolv.conf

 

测试连通华为仓库 443 端口(解析通不代表网络通)

# 直接curl访问仓库v2接口验证HTTPS连通
curl -v --connect-timeout 10 https://swr.cn-north-4.myhuaweicloud.com/v2/

 

验证本地DNS解析

nslookup swr.cn-north-4.myhuaweicloud.com

 

posted @ 2026-07-30 11:10  民工黑猫  阅读(9)  评论(0)    收藏  举报