Ubuntu 16.04:Temporary failure resolving 'security.ubuntu.com'

本文介绍了在Ubuntu系统中遇到的软件源更新失败问题及解决方案。通过修改DNS服务器地址为8.8.8.8并重新运行apt-get update命令,成功解决了因DNS解析问题导致的软件源更新失败。

今天早上对软件源进行更新的时候,发现出现了如下的错误:

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

我的解决方法为:

echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null
sudo apt-get update

然后就一切正常了,我的输出为:

idc@idc-Precision-Tower-7910:~/Downloads/DeepMIML$ sudo apt-get update
Hit:1 http://cn.archive.ubuntu.com/ubuntu xenial InRelease                     
Hit:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates InRelease             
Hit:3 http://cn.archive.ubuntu.com/ubuntu xenial-backports InRelease           
Hit:4 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu xenial InRelease    
Hit:5 http://ppa.launchpad.net/xorg-edgers/ppa/ubuntu xenial InRelease         
Ign:6 http://dl.google.com/linux/chrome/deb stable InRelease                   
Hit:7 http://dl.google.com/linux/chrome/deb stable Release                     
Get:9 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]     
Ign:10 http://linux.teamviewer.com/deb stable InRelease                        
Ign:11 http://linux.teamviewer.com/deb preview InRelease                       
Hit:12 http://linux.teamviewer.com/deb stable Release    
Get:9 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Hit:14 http://linux.teamviewer.com/deb preview Release   
Get:16 http://security.ubuntu.com/ubuntu xenial-security/main amd64 DEP-11 Metadata [62.3 kB]
Get:17 http://security.ubuntu.com/ubuntu xenial-security/main DEP-11 64x64 Icons [62.1 kB]
Get:18 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 DEP-11 Metadata [51.3 kB]
Get:19 http://security.ubuntu.com/ubuntu xenial-security/universe DEP-11 64x64 Icons [80.2 kB]
Fetched 303 kB in 2min 58s (1,703 B/s)                                         
Reading package lists... Done

参考文献

[1].apt-get update fails to fetch files, “Temporary failure resolving …” error.https://askubuntu.com/questions/91543/apt-get-update-fails-to-fetch-files-temporary-failure-resolving-error
wuyilun@ubuntu:~/Desktop$ sudo apt-get update [sudo] password for wuyilun: Err:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease Temporary failure resolving 'mirrors.tuna.tsinghua.edu.cn' Err:2 http://security.ubuntu.com/ubuntu focal-security InRelease Temporary failure resolving 'security.ubuntu.com' Err:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease Temporary failure resolving 'mirrors.tuna.tsinghua.edu.cn' Err:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease Temporary failure resolving 'mirrors.tuna.tsinghua.edu.cn' Err:5 http://us.archive.ubuntu.com/ubuntu focal InRelease Temporary failure resolving 'us.archive.ubuntu.com' Err:6 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease Temporary failure resolving 'us.archive.ubuntu.com' Err:7 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease Temporary failure resolving 'us.archive.ubuntu.com' Reading package lists... Done W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/focal/InRelease Temporary failure resolving 'us.archive.ubuntu.com' W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease Temporary failure resolving 'us.archive.ubuntu.com' W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease Temporary failure resolving 'us.archive.ubuntu.com' W: Failed to fetch https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal/InRelease Temporary failure resolving 'mirrors.tuna.tsinghua.edu.cn' W: Failed to fetch https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal-updates/InRelease Temporary failure resolving 'mirrors.tuna.tsinghua.edu.cn' W: Failed to fetch https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal-backports/InRelease Temporary failure resolving 'mirrors.tuna.tsinghua.edu.cn' W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease Temporary failure resolving 'security.ubuntu.com' W: Some index files failed to download. They have been ignored, or old ones used instead. wuyilun@ubuntu:~/Desktop$ ping www.baidu.com ping: www.baidu.com: Temporary failure in name resolution
最新发布
08-29
<think>我们面对的问题是Ubuntu系统中出现域名解析临时失败(Temporary failure in name resolution)以及apt-get update时出现类似错误。这通常与DNS配置或网络连接问题有关。根据引用内容,我们可以从以下几个方面解决: ### 1. **检查网络连接** - 首先确认网络是否可达。使用`ping 8.8.8.8`(Google DNS)测试网络连通性。如果连IP地址都ping不通,说明网络连接有问题(如网卡未启用、路由问题等)。此时需要检查网络接口配置。 ### 2. **配置静态IP和DNS(如果使用静态IP)** - 编辑网络配置文件`/etc/network/interfaces`(适用于较旧版本的Ubuntu,如16.04): ```bash sudo vim /etc/network/interfaces ``` 确保配置了正确的IP地址、子网掩码和网关,例如: ```plaintext auto eth0 iface eth0 inet static address 172.16.15.97 netmask 255.255.248.0 gateway 172.16.15.253 ``` 保存后重启网络服务: ```bash sudo /etc/init.d/networking restart ``` - **注意**:在Ubuntu 18.04及更高版本中,网络配置改用`netplan`,配置文件位于`/etc/netplan/`目录下,扩展名为`.yaml`。 ### 3. **配置DNS解析** - 编辑`/etc/resolv.conf`文件,添加可靠的DNS服务器地址(如Google DNS 8.8.8.8或国内DNS 114.114.114.114): ```bash sudo vim /etc/resolv.conf ``` 添加以下内容: ```plaintext nameserver 8.8.8.8 nameserver 114.114.114.114 ``` 保存后,尝试`ping www.baidu.com`测试解析是否正常。 - **注意**:在较新版本的Ubuntu中,`/etc/resolv.conf`可能是符号链接,由`systemd-resolved`管理。此时,应修改`/etc/systemd/resolved.conf`文件,设置DNS并重启服务: ```bash sudo vim /etc/systemd/resolved.conf ``` 取消注释并修改以下行: ```plaintext DNS=8.8.8.8 114.114.114.114 ``` 然后重启服务: ```bash sudo systemctl restart systemd-resolved ``` ### 4. **临时添加默认网关(如果需要)** - 如果网络不可达,可能需要手动添加默认网关(确保网关地址正确): ```bash sudo route add default gw 172.16.15.253 ``` ### 5. **解决apt-get update的DNS解析失败** - 如果上述步骤已解决DNS解析问题,那么`apt-get update`应该也能正常工作。如果问题仅在Docker容器内出现(如引用[2]所述),则需修改Docker的DNS配置: - 创建或编辑`/etc/docker/daemon.json`: ```json { "dns": ["8.8.8.8", "114.114.114.114"] } ``` - 重启Docker: ```bash sudo systemctl restart docker ``` ### 6. **更新软件源列表** - 如果DNS解析正常,但`apt-get update`仍失败,可能是软件源服务器问题。尝试更换软件源: - 备份原源列表: ```bash sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak ``` - 编辑源列表,替换为国内镜像源(如阿里云、清华源): ```bash sudo vim /etc/apt/sources.list ``` 例如,使用阿里云Ubuntu 20.04源: ```plaintext deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse ``` - 更新软件包列表: ```bash sudo apt-get update ``` ### 7. **清除apt缓存** - 如果出现索引文件下载失败(如引用[4]),可尝试清除apt缓存并重试: ```bash sudo apt-get clean sudo apt-get update ``` ### 8. **检查防火墙设置** - 确保防火墙没有阻止DNS查询(UDP端口53)或HTTP连接(apt-get update使用HTTP/HTTPS)。可暂时关闭防火墙测试: ```bash sudo ufw disable ``` ### 总结步骤 1. 检查网络连通性(ping IP地址)。 2. 配置正确的IP和网关(静态或DHCP)。 3. 配置可靠的DNS服务器(如8.8.8.8)。 4. 更新软件源并清除缓存。 5. 如问题在Docker容器内,配置Docker的DNS。 按照以上步骤操作,通常可以解决域名解析临时失败的问题。 §§相关问题§§ 1. Ubuntu系统中如何查看当前生效的DNS服务器地址? 2. 如何为Ubuntu系统配置DHCP自动获取IP地址? 3.Ubuntu中,如何测试DNS解析速度? 4. 如何查看Ubuntu系统网络接口的详细状态?</think>针对Ubuntu系统中出现的域名解析临时失败(`Temporary failure in name resolution`)以及`apt-get update`相关错误,以下是系统化的解决方案: --- ### 一、核心解决步骤 1. **配置DNS服务器** 编辑DNS配置文件(需管理员权限): ```bash sudo vim /etc/resolv.conf ``` 添加可靠的公共DNS服务器(如Google DNS或国内DNS): ```plaintext nameserver 8.8.8.8 # Google DNS nameserver 114.114.114.114 # 国内通用DNS nameserver 223.5.5.5 # 阿里DNS ``` > 注意:该文件可能被系统覆盖,需设置只读权限:`sudo chattr +i /etc/resolv.conf`[^1][^2] 2. **修复网络连接问题** - **检查默认网关**: ```bash ip route show | grep default ``` 若无输出,手动添加网关(替换为实际网关IP): ```bash sudo ip route add default via 192.168.1.1 ``` - **重启网络服务**: ```bash sudo systemctl restart systemd-resolved # DNS服务 sudo systemctl restart NetworkManager # 网络管理服务 ``` 3. **修复apt-get的DNS问题** - 全局配置DNS(影响所有应用): ```bash sudo vim /etc/systemd/resolved.conf ``` 取消注释并修改: ```ini DNS=8.8.8.8 114.114.114.114 DNSStubListener=no ``` 重启服务: ```bash sudo systemctl restart systemd-resolved sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf ``` --- ### 二、进阶排查方法 1. **测试DNS解析** 使用`dig`或`nslookup`验证DNS是否生效: ```bash dig www.baidu.com +short # 应返回IP地址 nslookup security.ubuntu.com ``` 2. **检查防火墙限制** 确保DNS端口(UDP 53)未被阻止: ```bash sudo ufw status # 查看防火墙状态 sudo ufw allow out 53/udp # 允许DNS出站 ``` 3. **更新软件源缓存** 修复`apt-get update`错误: ```bash sudo rm -rf /var/lib/apt/lists/* # 清除旧缓存 sudo apt-get update --fix-missing # 强制修复 ``` --- ### 三、特殊场景处理 #### 1. **Docker容器内DNS失败**(引用[2]) 编辑Docker配置文件: ```bash sudo vim /etc/docker/daemon.json ``` 添加自定义DNS: ```json { "dns": ["8.8.8.8", "114.114.114.114"] } ``` 重启Docker: ```bash sudo systemctl restart docker ``` #### 2. **Ubuntu 18.04+版本差异** 新版使用`netplan`配置网络: ```bash sudo vim /etc/netplan/*.yaml ``` 示例配置: ```yaml network: version: 2 ethernets: eth0: dhcp4: no addresses: [192.168.1.100/24] gateway4: 192.168.1.1 nameservers: addresses: [8.8.8.8, 114.114.114.114] ``` 应用配置:`sudo netplan apply` --- ### 四、验证解决 ```bash ping www.baidu.com # 应返回IP和延迟 apt-get update # 应正常更新软件列表 apt-get install net-tools # 测试软件安装 ``` > **关键点**:90%的此类错误源于DNS配置错误或网络不可达。优先检查`/etc/resolv.conf`和网关设置[^1][^2][^3]。 ---
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

农民小飞侠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值