【亲测有效】Ubuntu18.04 sudo apt update无法解析域名的解决方案

简介: 【亲测有效】Ubuntu18.04 sudo apt update无法解析域名的解决方案

问题描述如下:

拿起了封尘已久的ThinkPad,输入 sudo apt update 的时候,发现这个命令变得不好使了,具体出现的问题如下图所示:

#( 09/08/19@ 2:44下午 )( python@Sakura ):~/下载/shadowsocksr@manyuser✔
   sudo apt update
忽略:1 http://dl.google.com/linux/chrome/deb stable InRelease                  
命中:2 http://dl.google.com/linux/chrome/deb stable Release                    
0% [正在连接 cn.archive.ubuntu.com] [正在连接 cz.archive.ubuntu.co0% [正在连接 c0% [错误:4 http://ppa.launchpad.net/obsproject/obs-studio/ubuntu bionic InRelease      
  无法解析域名“ppa.launchpad.net”
错误:5 http://cz.archive.ubuntu.com/ubuntu bionic InRelease                        
  无法解析域名“cz.archive.ubuntu.com”
错误:6 https://packages.microsoft.com/ubuntu/18.04/prod bionic InRelease           
  无法解析域名“packages.microsoft.com”
错误:7 https://download.sublimetext.com apt/stable/ InRelease                      
  无法解析域名“download.sublimetext.com”
错误:8 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu bionic InRelease         
  无法解析域名“mirrors.ustc.edu.cn”
错误:9 http://archive.ubuntukylin.com:10006/ubuntukylin xenial InRelease           
  无法解析域名“archive.ubuntukylin.com”
错误:10 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease                
  无法解析域名“ppa.launchpad.net”
错误:11 http://cn.archive.ubuntu.com/ubuntu bionic InRelease                 
  无法解析域名“cn.archive.ubuntu.com”
错误:12 http://packages.microsoft.com/repos/vscode stable InRelease          
  无法解析域名“packages.microsoft.com”
错误:13 http://ppa.launchpad.net/openjdk-r/ppa/ubuntu bionic InRelease
  无法解析域名“ppa.launchpad.net”
错误:14 http://cn.archive.ubuntu.com/ubuntu bionic-updates InRelease
  无法解析域名“cn.archive.ubuntu.com”
错误:15 http://ppa.launchpad.net/openshot.developers/ppa/ubuntu bionic InRelease
  无法解析域名“ppa.launchpad.net”
错误:16 http://cn.archive.ubuntu.com/ubuntu bionic-security InRelease
  无法解析域名“cn.archive.ubuntu.com”
错误:17 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic InRelease
  无法解析域名“ppa.launchpad.net”
错误:18 http://cn.archive.ubuntu.com/ubuntu bionic-proposed InRelease
  无法解析域名“cn.archive.ubuntu.com”
错误:19 http://ppa.launchpad.net/webupd8team/java/ubuntu bionic InRelease
  无法解析域名“ppa.launchpad.net”
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
有 382 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。
W: 无法下载 http://cn.archive.ubuntu.com/ubuntu/dists/bionic/InRelease  无法解析域名“cn.archive.ubuntu.com”
W: 无法下载 http://cn.archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease  无法解析域名“cn.archive.ubuntu.com”
W: 无法下载 http://cn.archive.ubuntu.com/ubuntu/dists/bionic-security/InRelease  无法解析域名“cn.archive.ubuntu.com”
W: 无法下载 http://cn.archive.ubuntu.com/ubuntu/dists/bionic-proposed/InRelease  无法解析域名“cn.archive.ubuntu.com”
W: 无法下载 http://cz.archive.ubuntu.com/ubuntu/dists/bionic/InRelease  无法解析域名“cz.archive.ubuntu.com”
W: 无法下载 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/dists/bionic/InRelease  无法解析域名“mirrors.ustc.edu.cn”
W: 无法下载 https://packages.microsoft.com/ubuntu/18.04/prod/dists/bionic/InRelease  无法解析域名“packages.microsoft.com”
W: 无法下载 http://ppa.launchpad.net/obsproject/obs-studio/ubuntu/dists/bionic/InRelease  无法解析域名“ppa.launchpad.net”
W: 无法下载 http://ppa.launchpad.net/ondrej/php/ubuntu/dists/bionic/InRelease  无法解析域名“ppa.launchpad.net”
W: 无法下载 http://ppa.launchpad.net/openjdk-r/ppa/ubuntu/dists/bionic/InRelease  无法解析域名“ppa.launchpad.net”
W: 无法下载 http://ppa.launchpad.net/openshot.developers/ppa/ubuntu/dists/bionic/InRelease  无法解析域名“ppa.launchpad.net”
W: 无法下载 http://archive.ubuntukylin.com:10006/ubuntukylin/dists/xenial/InRelease  无法解析域名“archive.ubuntukylin.com”
W: 无法下载 https://download.sublimetext.com/apt/stable/InRelease  无法解析域名“download.sublimetext.com”
W: 无法下载 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu/dists/bionic/InRelease  无法解析域名“ppa.launchpad.net”
W: 无法下载 http://packages.microsoft.com/repos/vscode/dists/stable/InRelease  无法解析域名“packages.microsoft.com”
W: 无法下载 http://ppa.launchpad.net/webupd8team/java/ubuntu/dists/bionic/InRelease  无法解析域名“ppa.launchpad.net”
W: 部分索引文件下载失败。如果忽略它们,那将转而使用旧的索引文件。

我们可以看到,大概我们无法对像"cn.archive.ubuntu.com"、"packages.microsoft.com"之类的网站进行域名解析。出现这一问题主要是因为DNS解析有误,或者是DNS未配置。我们可以查看一下DNS Server:

cat /etc/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 127.0.0.53
options edns0
search DHCP HOST

只有一个DNS Server的地址 127.0.0.53,我们可以采取如下方法给其配置DNS Server。

解决方案:

方案一:重启会失效

我们只需要加入DNS服务器地址,让其能够自动去解析即可。不过有个问题就是重启以后可能会失效,需要重新对其进行配置。

1. sudo vim /etc/resolv.conf # 添加如下内容
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 127.0.0.1
2. 输入Esc,:wq,保存并退出
3. sudo /etc/init.d/networking restart

我们再输入 sudo apt update 进行更新即可。

方案二:永久有效

1. sudo apt install resolvconf
2. sudo vim /etc/resolvconf/resolv.conf.d/base
在里面插入:
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 127.0.0.1
3. 输入Esc,:wq,保存并退出
4. sudo resolvconf -u
5. cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.4.4

在这里,我还要提一点相关内容。虽然我按照方案二并没有达到想要的这种结果(理论上应该是没问题的),可能是因为我这边配置全局代理,让它默认自动走本地代理路线,所以DNS Server解析的地址为127.0.0.1,不过至少已经可以使用了,如果方案二行不通的同学,你可以采用方案一,稍微麻烦一点,每次都要进行修改罢了。

最终的结果如下:

#( 09/08/19@ 2:58下午 )( python@Sakura ):~/下载/shadowsocksr@manyuser✔
   sudo apt update                    
忽略:1 http://dl.google.com/linux/chrome/deb stable InRelease
命中:2 http://dl.google.com/linux/chrome/deb stable Release                        
获取:3 http://archive.ubuntukylin.com:10006/ubuntukylin xenial InRelease [18.1 kB] 
获取:4 http://packages.microsoft.com/repos/vscode stable InRelease [3,181 B]       
命中:6 http://ppa.launchpad.net/obsproject/obs-studio/ubuntu bionic InRelease      
命中:7 https://packages.microsoft.com/ubuntu/18.04/prod bionic InRelease           
获取:8 http://packages.microsoft.com/repos/vscode stable/main amd64 Packages [139 kB]
命中:9 http://cz.archive.ubuntu.com/ubuntu bionic InRelease                        
命中:10 http://cn.archive.ubuntu.com/ubuntu bionic InRelease                       
命中:11 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease                
命中:12 https://download.sublimetext.com apt/stable/ InRelease                     
获取:13 http://cn.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]     
命中:14 http://ppa.launchpad.net/openjdk-r/ppa/ubuntu bionic InRelease             
命中:15 http://ppa.launchpad.net/openshot.developers/ppa/ubuntu bionic InRelease   
命中:16 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic InRelease   
命中:17 http://ppa.launchpad.net/webupd8team/java/ubuntu bionic InRelease          
获取:18 http://cn.archive.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]    
获取:19 http://cn.archive.ubuntu.com/ubuntu bionic-proposed InRelease [242 kB]     
命中:20 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu bionic InRelease        
获取:21 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 DEP-11 Metadata [285 kB]
获取:22 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main DEP-11 48x48 Icons [70.9 kB]
获取:23 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main DEP-11 64x64 Icons [140 kB]
获取:24 http://cn.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 DEP-11 Metadata [2,464 B]
获取:25 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 DEP-11 Metadata [253 kB]
获取:26 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe DEP-11 48x48 Icons [197 kB]
获取:27 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe DEP-11 64x64 Icons [447 kB]
获取:28 http://cn.archive.ubuntu.com/ubuntu bionic-security/main amd64 DEP-11 Metadata [22.7 kB]
获取:29 http://cn.archive.ubuntu.com/ubuntu bionic-security/main DEP-11 48x48 Icons [10.4 kB]
获取:30 http://cn.archive.ubuntu.com/ubuntu bionic-security/main DEP-11 64x64 Icons [31.7 kB]
获取:31 http://cn.archive.ubuntu.com/ubuntu bionic-security/multiverse amd64 DEP-11 Metadata [2,464 B]
获取:32 http://cn.archive.ubuntu.com/ubuntu bionic-security/universe amd64 DEP-11 Metadata [42.1 kB]
获取:33 http://cn.archive.ubuntu.com/ubuntu bionic-security/universe DEP-11 48x48 Icons [16.4 kB]
获取:34 http://cn.archive.ubuntu.com/ubuntu bionic-security/universe DEP-11 64x64 Icons [111 kB]
获取:35 http://cn.archive.ubuntu.com/ubuntu bionic-proposed/main amd64 DEP-11 Metadata [7,160 B]
已下载 2,220 kB,耗时 35秒 (63.8 kB/s)                                             
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
有 383 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。

这样就OK了。

目录
相关文章
|
4月前
|
Ubuntu 编译器 计算机视觉
Ubuntu 20.04环境下无法找到#include<opencv/cv.h>文件 - 解决方案。
希望这些信息能帮助你解决遇到的问题。
321 10
备案成功以后,也解析了为什么没办法通过域名收到网站呢
网站备案成功后仍无法通过域名访问,可能涉及解析设置错误、服务器配置问题或网络限制等原因。本文将详细分析常见原因并提供解决方案。
|
8月前
|
Ubuntu 机器人 开发者
Docker环境下的ROS Noetic:Ubuntu 20.04 系统下的解决方案
这就是在Docker环境下安装ROS Noetic在Ubuntu 20.04系统的一种简单方法,希望能对你有所帮助。
959 16
|
XML JSON API
ServiceStack:不仅仅是一个高性能Web API和微服务框架,更是一站式解决方案——深入解析其多协议支持及简便开发流程,带您体验前所未有的.NET开发效率革命
【10月更文挑战第9天】ServiceStack 是一个高性能的 Web API 和微服务框架,支持 JSON、XML、CSV 等多种数据格式。它简化了 .NET 应用的开发流程,提供了直观的 RESTful 服务构建方式。ServiceStack 支持高并发请求和复杂业务逻辑,安装简单,通过 NuGet 包管理器即可快速集成。示例代码展示了如何创建一个返回当前日期的简单服务,包括定义请求和响应 DTO、实现服务逻辑、配置路由和宿主。ServiceStack 还支持 WebSocket、SignalR 等实时通信协议,具备自动验证、自动过滤器等丰富功能,适合快速搭建高性能、可扩展的服务端应用。
885 3
|
9月前
|
Ubuntu 安全
Ubuntu中遇到"无法创建临时文件"/tmp/..."在普通或root用户运行apt-get update时的错误解决办法
这些步骤当然不能涵盖所有可能出现问题的场合,但是能覆盖大多数常见的情景。希望这些信息能帮到你解决"无法创建临时文件"/tmp/..."这样的问题。不过,请记住,因为修改系统文件和目录的权限,清理临时文件,或者运行磁盘检查,都可能对系统造成影响,所以执行这些操作前要先确认这是安全的,必要时最好先做好数据备份。
657 10
|
11月前
|
Ubuntu 安全 Linux
Linux错误排查:解决Ubuntu 20.4执行sudo apt-get update时出现的libnettle.so.6错误。
很有可能在你得到解决方案时,你也学到了不少Linux修复技巧。祝你处理计算机问题时顺利如麻!永远记得,各种问题总是像老鼠一样从意想不到的地方冒出来。但记住,不管它们跑到哪里,最终都逃不过你的捕鼠器。盖起你的计算机,拾起你的代码,大步向前!
364 28
|
11月前
|
Ubuntu 安全 Linux
Linux错误排查:解决Ubuntu 20.4执行sudo apt-get update时出现的libnettle.so.6错误。
很有可能在你得到解决方案时,你也学到了不少Linux修复技巧。祝你处理计算机问题时顺利如麻!永远记得,各种问题总是像老鼠一样从意想不到的地方冒出来。但记住,不管它们跑到哪里,最终都逃不过你的捕鼠器。盖起你的计算机,拾起你的代码,大步向前!
345 18
|
11月前
|
监控 Shell Linux
Android调试终极指南:ADB安装+多设备连接+ANR日志抓取全流程解析,覆盖环境变量配置/多设备调试/ANR日志分析全流程,附Win/Mac/Linux三平台解决方案
ADB(Android Debug Bridge)是安卓开发中的重要工具,用于连接电脑与安卓设备,实现文件传输、应用管理、日志抓取等功能。本文介绍了 ADB 的基本概念、安装配置及常用命令。包括:1) 基本命令如 `adb version` 和 `adb devices`;2) 权限操作如 `adb root` 和 `adb shell`;3) APK 操作如安装、卸载应用;4) 文件传输如 `adb push` 和 `adb pull`;5) 日志记录如 `adb logcat`;6) 系统信息获取如屏幕截图和录屏。通过这些功能,用户可高效调试和管理安卓设备。
|
11月前
|
算法 前端开发 定位技术
地铁站内导航系统解决方案:技术架构与核心功能设计解析
本文旨在分享一套地铁站内导航系统技术方案,通过蓝牙Beacon技术与AI算法的结合,解决传统导航定位不准确、路径规划不合理等问题,提升乘客出行体验,同时为地铁运营商提供数据支持与增值服务。 如需获取校地铁站内智能导航系统方案文档可前往文章最下方获取,如有项目合作及技术交流欢迎私信我们哦~
913 1
|
Serverless 对象存储 人工智能
智能文件解析:体验阿里云多模态信息提取解决方案
在当今数据驱动的时代,信息的获取和处理效率直接影响着企业决策的速度和质量。然而,面对日益多样化的文件格式(文本、图像、音频、视频),传统的处理方法显然已经无法满足需求。
490 4
智能文件解析:体验阿里云多模态信息提取解决方案

热门文章

最新文章