【亲测有效】Ubuntu18.04 sudo apt update无法解析域名的解决方案
<h3 id="问题描述如下">问题描述如下:</h3><p>拿起了封尘已久的ThinkPad,输入 sudo apt update 的时候,发现这个命令变得不好使了,具体出现的问题如下图所示:</p>
<pre><code class="language-shell">#( 09/08/19@ 2:44下午 )( python@Sakura ):~/下载/***@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: 部分索引文件下载失败。如果忽略它们,那将转而使用旧的索引文件。
</code></pre>
<p>我们可以看到,大概我们无法对像"cn.archive.ubuntu.com"、"packages.microsoft.com"之类的网站进行域名解析。出现这一问题主要是因为DNS解析有误,或者是DNS未配置。我们可以查看一下DNS Server:</p>
<pre><code>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
</code></pre>
<p>只有一个DNS Server的地址 127.0.0.53,我们可以采取如下方法给其配置DNS Server。</p>
<h3 id="解决方案">解决方案:</h3>
<p>方案一:重启会失效</p>
<p>我们只需要加入DNS服务器地址,让其能够自动去解析即可。不过有个问题就是重启以后可能会失效,需要重新对其进行配置。</p>
<pre><code class="language-shell">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
</code></pre>
<p>我们再输入 sudo apt update 进行更新即可。</p>
<p>方案二:永久有效</p>
<pre><code class="language-shell">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
</code></pre>
<p>在这里,我还要提一点相关内容。虽然我按照方案二并没有达到想要的这种结果(理论上应该是没问题的),可能是因为我这边配置全局代理,让它默认自动走本地代理路线,所以DNS Server解析的地址为127.0.0.1,不过至少已经可以使用了,如果方案二行不通的同学,你可以采用方案一,稍微麻烦一点,每次都要进行修改罢了。</p>
<p>最终的结果如下:</p>
<pre><code class="language-shell">#( 09/08/19@ 2:58下午 )( python@Sakura ):~/下载/***@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
获取:4 http://packages.microsoft.com/repos/vscode stable InRelease
命中: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
命中: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
命中: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
获取:19 http://cn.archive.ubuntu.com/ubuntu bionic-proposed InRelease
命中: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
获取:22 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main DEP-11 48x48 Icons
获取:23 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main DEP-11 64x64 Icons
获取:24 http://cn.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 DEP-11 Metadata
获取:25 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 DEP-11 Metadata
获取:26 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe DEP-11 48x48 Icons
获取:27 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe DEP-11 64x64 Icons
获取:28 http://cn.archive.ubuntu.com/ubuntu bionic-security/main amd64 DEP-11 Metadata
获取:29 http://cn.archive.ubuntu.com/ubuntu bionic-security/main DEP-11 48x48 Icons
获取:30 http://cn.archive.ubuntu.com/ubuntu bionic-security/main DEP-11 64x64 Icons
获取:31 http://cn.archive.ubuntu.com/ubuntu bionic-security/multiverse amd64 DEP-11 Metadata
获取:32 http://cn.archive.ubuntu.com/ubuntu bionic-security/universe amd64 DEP-11 Metadata
获取:33 http://cn.archive.ubuntu.com/ubuntu bionic-security/universe DEP-11 48x48 Icons
获取:34 http://cn.archive.ubuntu.com/ubuntu bionic-security/universe DEP-11 64x64 Icons
获取:35 http://cn.archive.ubuntu.com/ubuntu bionic-proposed/main amd64 DEP-11 Metadata
已下载 2,220 kB,耗时 35秒 (63.8 kB/s)
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
有 383 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。
</code></pre>
<p>这样就OK了。</p>
</div>
<div id="MySignature" role="contentinfo">
<p id="PSignature" style="padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 60px; background: url("https://www.cnblogs.com/images/cnblogs_com/ECJTUACM-873284962/1318325/o_o_122329534672560.png") #e5f1f4 no-repeat 1% 50%; font-family: 微软雅黑; font-size: 12px; border: #e0e0e0 1px dashed"> <br>
作 者:<strong><span style="font-size: 12px; color: red">Angel_Kitty</span></strong>
<br>
出 处:https://www.cnblogs.com/ECJTUACM-873284962/
<br>
关于作者:阿里云ACE,目前主要研究方向是Web安全漏洞以及反序列化。如有问题或建议,请多多赐教!
<br>
版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。
<br>
特此声明:所有评论和私信都会在第一时间回复。也欢迎园子的大大们指正错误,共同进步。或者直接私信我
<br>
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角<strong><span style="color: #ff0000; font-size: 18pt">【推荐】</span></strong>一下。您的鼓励是作者坚持原创和持续写作的最大动力!
<br>
</p>
<div id="mySponsorBox" style="padding: 30px; background: #ececec">
<p style="color: #4bd3d3; font-weight: bold; text-align: center">欢迎大家关注我的微信公众号IT老实人(IThonest),如果您觉得文章对您有很大的帮助,您可以考虑赏博主一杯咖啡以资鼓励,您的肯定将是我最大的动力。thx. </p>
<div style="border: silver 1px dashed; padding: 10px; height: 420">
<div style="float: left; width: 100%">
<img style="margin-left: auto; margin-right: auto; display: block" src="https://images.cnblogs.com/cnblogs_com/ECJTUACM-873284962/1318325/o_donate.png" width="100%">
</div>
</div>
</div>
<div id="mySponsorBox" style="padding: 30px; background: #ececec">
<p style="color: #4bd3d3; font-weight: bold; text-align: center">我的公众号是IT老实人(IThonest),一个有故事的公众号,欢迎大家来这里讨论,共同进步,不断学习才能不断进步。扫下面的二维码或者收藏下面的二维码关注吧(长按下面的二维码图片、并选择识别图中的二维码),个人QQ和微信的二维码也已给出,扫描下面👇的二维码一起来讨论吧!!!</p>
<div style="border: silver 1px dashed; padding: 10px; height: 420">
<div style="float: left; width: 100%">
<img style="margin-left: auto; margin-right: auto; display: block" src="https://images.cnblogs.com/cnblogs_com/ECJTUACM-873284962/1318325/o_chat.png" width="100%">
</div>
</div>
</div>
<div id="mySponsorBox" style="padding: 30px; background: #ececec">
<p style="color: #4bd3d3; font-weight: bold; text-align: center">欢迎大家关注我的Github,一些文章的备份和平常做的一些项目会存放在这里。</p>
<div class="github-card" data-github="AngelKitty" data-width="400" data-height="150" data-theme="default"></div>
</div><br><br>
来源:https://www.cnblogs.com/ECJTUACM-873284962/p/11487273.html
頁:
[1]