【亲测有效】Ubuntu18.04sudoaptupdate⽆法解析域名的解决⽅案
问题描述如下:
拿起了封尘已久的ThinkPad,输⼊ sudo apt update 的时候,发现这个命令变得不好使了,具体出现的问题如下图所⽰:
#( 09/08/19@ 2:44下午 )( python@Sakura ):~/下载/shadowsocksr@manyuser✔
sudo apt update
忽略:1 dl.google/linux/chrome/deb stable InRelease
命中:2 dl.google/linux/chrome/deb stable Release
0% [正在连接 cn.archive.ubuntu] [正在连接 cz.0% [正在连接 c0% [错误:4 ppa.launchpad/obsproject/obs-studio/ubuntu bionic InRelease
⽆法解析域名“ppa.launchpad”
错误:5 cz.archive.ubuntu/ubuntu bionic InRelease
⽆法解析域名“cz.archive.ubuntu”
错误:6 packages.microsoft/ubuntu/18.04/prod bionic InRelease
⽆法解析域名“packages.microsoft”
错误:7 download.sublimetext apt/stable/ InRelease
⽆法解析域名“download.sublimetext”
错误:8 mirrors.ustc.edu/docker-ce/linux/ubuntu bionic InRelease
⽆法解析域名“mirrors.ustc.edu”
错误:9 archive.ubuntukylin:10006/ubuntukylin xenial InRelease
⽆法解析域名“archive.ubuntukylin”
错误:10 ppa.launchpad/ondrej/php/ubuntu bionic InRelease
⽆法解析域名“ppa.launchpad”
错误:11 cn.archive.ubuntu/ubuntu bionic InRelease
⽆法解析域名“cn.archive.ubuntu”
错误:12 packages.microsoft/repos/vscode stable InRelease
⽆法解析域名“packages.microsoft”
错误:13 ppa.launchpad/openjdk-r/ppa/ubuntu bionic InRelease
⽆法解析域名“ppa.launchpad”
错误:14 cn.archive.ubuntu/ubuntu bionic-updates InRelease
⽆法解析域名“cn.archive.ubuntu”
错误:15 ppa.launchpad/openshot.developers/ppa/ubuntu bionic InRelease
⽆法解析域名“ppa.launchpad”
错误:16 cn.archive.ubuntu/ubuntu bionic-security InRelease
⽆法解析域名“cn.archive.ubuntu”
错误:17 ppa.launchpad/ubuntu-toolchain-r/test/ubuntu bionic InRelease
⽆法解析域名“ppa.launchpad”
错误:18 cn.archive.ubuntu/ubuntu bionic-proposed InRelease
⽆法解析域名“cn.archive.ubuntu”
错误:19 ppa.launchpad/webupd8team/java/ubuntu bionic InRelease
⽆法解析域名“ppa.launchpad”
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
有 382 个软件包可以升级。请执⾏ ‘apt list --upgradable’ 来查看它们。
W: ⽆法下载 cn.archive.ubuntu/ubuntu/dists/bionic/InRelease  ⽆法解析域名“cn.archive.ubuntu”
W: ⽆法下载 cn.archive.ubuntu/ubuntu/dists/bionic-updates/InRelease  ⽆法解析域名“cn.archive.ubuntu”
W: ⽆法下载 cn.archive.ubuntu/ubuntu/dists/bionic-security/InRelease  ⽆法解析域名“cn.archive.ubuntu”
W: ⽆法下载 cn.archive.ubuntu/ubuntu/dists/bionic-proposed/InRelease  ⽆法解析域名“cn.archive.ubuntu”
W: ⽆法下载 cz.archive.ubuntu/ubuntu/dists/bionic/InRelease  ⽆法解析域名“cz.archive.ubuntu”
W: ⽆法下载 mirrors.ustc.edu/docker-ce/linux/ubuntu/dists/bionic/InRelease  ⽆法解析域名“mirrors.ustc.edu”
W: ⽆法下载 packages.microsoft/ubuntu/18.04/prod/dists/bionic/InRelease  ⽆法解析域名“packages.microsoft”
W: ⽆法下载 ppa.launchpad/obsproject/obs-studio/ubuntu/dists/bionic/InRelease  ⽆法解析域名“ppa.launchpad”
W: ⽆法下载 ppa.launchpad/ondrej/php/ubuntu/dists/bionic/InRelease  ⽆法解析域名“ppa.launchpad”
W: ⽆法下载 ppa.launchpad/openjdk-r/ppa/ubuntu/dists/bionic/InRelease  ⽆法解析域名“ppa.launchpad”
W: ⽆法下载 ppa.launchpad/openshot.developers/ppa/ubuntu/dists/bionic/InRelease  ⽆法解析域名“ppa.launchpad”
W: ⽆法下载 archive.ubuntukylin:10006/ubuntukylin/dists/xenial/InRelease  ⽆法解析域名“archive.ubuntukylin”
W: ⽆法下载 download.sublimetext/apt/stable/InRelease  ⽆法解析域名“download.sublimetext”
W: ⽆法下载 ppa.launchpad/ubuntu-toolchain-r/test/ubuntu/dists/bionic/InRelease  ⽆法解析域名“ppa.launchpad”
W: ⽆法下载 packages.microsoft/repos/vscode/dists/stable/InRelease  ⽆法解析域名“packages.microsoft”
W: ⽆法下载 ppa.launchpad/webupd8team/java/ubuntu/dists/bionic/InRelease  ⽆法解析域名“ppa.launchpad”
W: 部分索引⽂件下载失败。如果忽略它们,那将转⽽使⽤旧的索引⽂件。
我们可以看到,⼤概我们⽆法对像"cn.archive.ubuntu"、"packages.microsoft"之类的⽹站进⾏域名解析。出现这⼀问题主要是因为DNS解析有误,或者是DNS未配置。我们可以查看⼀下DNS Server:
cat /f
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a f 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 /f. To manage f(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 /f.
nameserver 127.0.0.53
options edns0
search DHCP HOST
只有⼀个DNS Server的地址 127.0.0.53,我们可以采取如下⽅法给其配置DNS Server。
解决⽅案:
ubuntu网络配置⽅案⼀:重启会失效
我们只需要加⼊DNS服务器地址,让其能够⾃动去解析即可。不过有个问题就是重启以后可能会失效,需要重新对其进⾏配置。
1. sudo vim /f # 添加如下内容
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/f.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 /f
# f(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 dl.google/linux/chrome/deb stable InRelease
命中:2 dl.google/linux/chrome/deb stable Release
获取:3 archive.ubuntukylin:10006/ubuntukylin xenial InRelease [18.1 kB]
获取:4 packages.microsoft/repos/vscode stable InRelease [3,181 B]
命中:6 ppa.launchpad/obsproject/obs-studio/ubuntu bionic InRelease
命中:7 packages.microsoft/ubuntu/18.04/prod bionic InRelease
获取:8 packages.microsoft/repos/vscode stable/main amd64 Packages [139 kB]
命中:9 cz.archive.ubuntu/ubuntu bionic InRelease
命中:10 cn.archive.ubuntu/ubuntu bionic InRelease
命中:11 ppa.launchpad/ondrej/php/ubuntu bionic InRelease
命中:12 download.sublimetext apt/stable/ InRelease
获取:13 cn.archive.ubuntu/ubuntu bionic-updates InRelease [88.7 kB]
命中:14 ppa.launchpad/openjdk-r/ppa/ubuntu bionic InRelease
命中:15 ppa.launchpad/openshot.developers/ppa/ubuntu bionic InRelease
命中:16 ppa.launchpad/ubuntu-toolchain-r/test/ubuntu bionic InRelease
命中:17 ppa.launchpad/webupd8team/java/ubuntu bionic InRelease
获取:18 cn.archive.ubuntu/ubuntu bionic-security InRelease [88.7 kB]
获取:19 cn.archive.ubuntu/ubuntu bionic-proposed InRelease [242 kB]
命中:20 mirrors.ustc.edu/docker-ce/linux/ubuntu bionic InRelease
获取:21 cn.archive.ubuntu/ubuntu bionic-updates/main amd64 DEP-11 Metadata [285 kB]
获取:22 cn.archive.ubuntu/ubuntu bionic-updates/main DEP-11 48x48 Icons [70.9 kB]
获取:23 cn.archive.ubuntu/ubuntu bionic-updates/main DEP-11 64x64 Icons [140 kB]
获取:24 cn.archive.ubuntu/ubuntu bionic-updates/multiverse amd64 DEP-11 Metadata [2,464 B]
获取:25 cn.archive.ubuntu/ubuntu bionic-updates/universe amd64 DEP-11 Metadata [253 kB]
获取:26 cn.archive.ubuntu/ubuntu bionic-updates/universe DEP-11 48x48 Icons [197 kB]
获取:27 cn.archive.ubuntu/ubuntu bionic-updates/universe DEP-11 64x64 Icons [447 kB]
获取:28 cn.archive.ubuntu/ubuntu bionic-security/main amd64 DEP-11 Metadata [22.7 kB]
获取:29 cn.archive.ubuntu/ubuntu bionic-security/main DEP-11 48x48 Icons [10.4 kB]
获取:30 cn.archive.ubuntu/ubuntu bionic-security/main DEP-11 64x64 Icons [31.7 kB]
获取:31 cn.archive.ubuntu/ubuntu bionic-security/multiverse amd64 DEP-11 Metadata [2,464 B]
获取:32 cn.archive.ubuntu/ubuntu bionic-security/universe amd64 DEP-11 Metadata [42.1 kB]
获取:33 cn.archive.ubuntu/ubuntu bionic-security/universe DEP-11 48x48 Icons [16.4 kB]
获取:34 cn.archive.ubuntu/ubuntu bionic-security/universe DEP-11 64x64 Icons [111 kB]
获取:35 cn.archive.ubuntu/ubuntu bionic-proposed/main amd64 DEP-11 Metadata [7,160 B]
已下载 2,220 kB,耗时 35秒 (63.8 kB/s)
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
有 383 个软件包可以升级。请执⾏ ‘apt list --upgradable’ 来查看它们。
这样就OK了。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。