You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu Server 22.04执行sudo apt update时域名解析失败问题求助

Ubuntu Server 22.04执行sudo apt update时域名解析失败问题求助

最近我在电脑上安装了Ubuntu Server 22.04,但每次执行sudo apt update时,总会弹出以下报错信息:

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease Temporary failure resolving 'archive.ubuntu.com'

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease Temporary failure resolving 'archive.ubuntu.com'

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease Temporary failure resolving 'archive.ubuntu.com'

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease Temporary failure resolving 'security.ubuntu.com'

W: Some index files failed to download. They have been ignored, or old ones used instead.

我已经尝试更换了多个国内镜像源,包括官方主源,但问题依然存在。有没有大佬能给点解决建议?

[编辑补充]
我的/etc/apt/sources.list内容暂未贴出,若需要我可以补充相关信息。


解决方案建议

别发愁,这种"Temporary failure resolving"的问题基本都是DNS解析或者基础网络配置出了问题,我给你几个一步步排查的方向:

  • 先确认基础网络是否连通
    先试试直接ping公共IP,比如执行ping 8.8.8.8,如果能收到回复,说明你的服务器能连上外网,问题肯定出在DNS解析环节;如果ping不通,那得先检查网线连接、IP地址分配(比如用ip addr看看有没有正确获取到IP)这些基础配置。

  • 手动配置稳定的DNS服务器
    Ubuntu Server默认用DHCP分配的DNS有时候不太靠谱,咱们手动换成公共DNS试试:

    1. 打开systemd的DNS配置文件:sudo nano /etc/systemd/resolved.conf
    2. 找到DNS和FallbackDNS这两行,去掉前面的#注释,改成:
      DNS=8.8.8.8 1.1.1.1
      FallbackDNS=8.8.4.4 1.0.0.1
      
      这里用的是谷歌和Cloudflare的公共DNS,都很稳定。
    3. 保存退出后,重启DNS服务:sudo systemctl restart systemd-resolved
    4. 现在再跑一遍sudo apt update,看看能不能正常解析域名了。
  • 检查sources.list的源地址是否正确
    虽然你换过镜像,但还是要确认源地址有没有拼写错误。比如国内阿里云的Jammy(22.04)源格式应该是这样的,你可以对比一下自己的配置:

    deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
    

    如果你的文件里有错误的域名或者路径,也会导致连接失败,建议先备份原文件(sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak),再替换成正确的配置。

  • 清除APT缓存后重试
    有时候旧的缓存文件会搞事情,执行下面两条命令清掉缓存再更新:

    sudo apt clean
    sudo apt update
    

备注:内容来源于stack exchange,提问作者Barney.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 08:18:05