风险提示:虚拟货币不具有法定货币等同的法律地位,参与虚拟货币投资交易存在法律风险,继续浏览代表你同意以上所有声明,否则请立即关闭本站!

服务器上的 DNS 整体挂了,不只是 Git 域名。curl cip.cc 也解析不了,说明当前连公共 DNS 都用不上。

127.0.0.53 是 systemd-resolved 的本地代理,上游 DNS 没配好或不可用 时就会全部解析失败。


第一步:先看上游 DNS 状态

在服务器上执行:

resolvectl status
systemctl status systemd-resolved --no-pager
cat /etc/systemd/resolved.conf
ls /etc/netplan/ 2>/dev/null; ls /etc/network/interfaces.d/ 2>/dev/null

如果 resolvectl statusDNS Servers 为空,或只有无效地址,就是根因。


第二步:快速修复(推荐先试)

mkdir -p /etc/systemd/resolved.conf.d
cat > /etc/systemd/resolved.conf.d/dns.conf <<'EOF'
[Resolve]
DNS=223.5.5.5 8.8.8.8
FallbackDNS=1.1.1.1
Domains=~.
EOF

systemctl restart systemd-resolved
resolvectl flush-caches

# 验证
resolvectl query git.bz121.com
curl -I --connect-timeout 5 https://git.bz121.com
curl cip.cc

解析正常后再更新代码:

cd /opt/qihuo
git fetch origin
git reset --hard origin/main
pm2 restart qihuo

第三步:若仍失败,用静态 resolv.conf(临时)

systemctl stop systemd-resolved
rm -f /etc/resolv.conf
cat > /etc/resolv.conf <<'EOF'
nameserver 223.5.5.5
nameserver 8.8.8.8
EOF

ping -c 2 git.bz121.com
curl cip.cc
注意:停掉 systemd-resolved 是权宜之计,重启后可能被改回。长期应在云厂商控制台或 netplan 里配 DNS。

第四步:云服务器常见原因

如果是阿里云 / 腾讯云 / 其他 VPS:

  1. 控制台 VPC / 网络 里是否配置了 DNS(如 223.5.5.5 或内网 DNS)
  2. 安全组是否放行 UDP/TCP 53 出站
  3. 是否改过 /etc/resolv.conf 导致和 systemd 冲突

第五步:Git 仍不可用时的应急(仅 DNS 修不好时)

在你 本机(能 push 的那台)把代码打包传到服务器:

# 本机
cd c:\Users\dekun\Desktop\qihuo
git archive -o qihuo.tar.gz HEAD
scp qihuo.tar.gz root@你的服务器IP:/opt/qihuo/
# 服务器
cd /opt/qihuo
tar -xzf qihuo.tar.gz
pm2 restart qihuo

这种方式 不会更新 .git,只适合应急;DNS 修好后仍建议用 git fetch


resolvectl status 的输出贴出来,我可以帮你看该改 netplan 还是 systemd-resolved。

发表评论