【Ubuntu】sudo apt-get update 无法解析域名(亲测有效)

本文涉及的产品
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
云解析 DNS,旗舰版 1个月
全局流量管理 GTM,标准版 1个月
简介: 在Ubuntu 18.04系统中,用户在执行sudo apt-get update时遇到“无法解析域名‘ip’”的错误。经分析,问题源于之前设置的网络代理配置未完全清除。解决方案是找到并重命名/etc/apt/apt.conf.d下的proxy.conf文件,使其不再生效。操作后,sudo apt-get update命令恢复正常,问题得到完美解决。

一、问题描述

在 ubuntu18.04系统终端运行指令sudo apt-get update

  报错:无法解析域名“ip”

==具体信息如下:==
image.png


二、原因分析

  出现这个问题之前,我尝试使用网络代理proxy下载一些外网的资源,按照 CSDN 教程创建了一些网络代理环境,但是还是没有成功,然后清除这些配置,但是可能没有清除干净,导致我的apt所使用的域名仍然是之前设置的一个海外的 $ip$。


比较奇怪的是,我的网络是没有问题的

网页可以正常打开

  • ping baidu.com正常
  • ping 8.8.8.8也正常

唯独sudo apt-get update报错
  无法解析域名“ip”

  CSDN上的解决方案基本都试过了

1、添加DNS服务器

sudo gedit /etc/resolv.conf

添加内容

nameserver 114.114.114.114
nameserver 8.8.8.8
无效

2、换源

sudo gedit /etc/apt/sources.list
也无效

三、解决方案

1、查找源配置文件路径

最终解决:
查看这个路径/etc/apt/apt.conf.d下有一个这个文件proxy.conf

cat /etc/apt/apt.conf.d/proxy.conf

==显示内容==
Acquire {HTTP::proxy "http://ip:88"; HTTPS::proxy "http://ip:88";}

  是这里在设置代理网址的时候填入了ip,导致在输入sudo apt-get update时报错无法解析域名“ip"

2、删除生效的源配置文件

  那么现在要做的就是删除掉这个文件,或者是==不让它生效==。

可以使用如下命令:

mv  /etc/apt/apt.conf.d/proxy.conf  /etc/apt/apt.conf.d/proxy.conf.bak

  使用mv指令,在新的文件路径后面加上.bak就相当于把这个文件重命名为bak类型的备份文件了,这样它就不生效了。


3、完美解决

再次尝试命令:

sudo apt-get update

得到结果:

qingliu@QingLiu-Lenovo:~$ sudo apt-get update [sudo] qingliu 的密码: 忽略:1 http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu bionic InRelease
获取:2 http://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu bionic InRelease
[4,680 B] 命中:3 http://mirrors.aliyun.com/ubuntu
bionic InRelease 命中:4
http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu bionic Release
命中:5 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease
命中:6 http://packages.microsoft.com/repos/code stable InRelease
命中:7 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease
命中:9 http://ppa.launchpad.net/apandada1/brightness-controller/ubuntu
bionic InRelease 命中:10
https://apollo-pkg-beta.cdn.bcebos.com/apollo/core bionic InRelease
命中:11 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic InRelease
命中:12 http://security.ubuntu.com/ubuntu bionic-security InRelease
命中:13 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu bionic
InRelease 命中:14
http://ppa.launchpad.net/oibaf/graphics-drivers/ubuntu bionic
InRelease 命中:15
http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic
InRelease 命中:16
https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64
InRelease 命中:17
https://nvidia.github.io/nvidia-container-runtime/stable/ubuntu18.04/amd64
InRelease 命中:18
https://nvidia.github.io/nvidia-docker/ubuntu18.04/amd64 InRelease
已下载 4,680 B,耗时 3秒 (1,385 B/s) 正在读取软件包列表... 完成

  OK,解决!

目录
相关文章
|
2月前
|
Ubuntu Java 应用服务中间件
如何通过 Apt-Get 在 Ubuntu 14.04 上安装 Apache Tomcat 7
如何通过 Apt-Get 在 Ubuntu 14.04 上安装 Apache Tomcat 7
86 0
|
3月前
|
Ubuntu Linux 文件存储
如何使用 Linux 构建自己的 NAS 系统?
【7月更文挑战第28天】
503 6
如何使用 Linux 构建自己的 NAS 系统?
|
2月前
|
Ubuntu 网络安全 数据安全/隐私保护
Ubuntu 普通用户修改sudoers导致无法使用sudo的解决办法
Ubuntu 普通用户修改sudoers导致无法使用sudo的解决办法
54 2
|
2月前
|
Web App开发 缓存 Ubuntu
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
168 11
|
3月前
|
存储 缓存 Ubuntu
Ubuntu apt-get 命令大全
【7月更文挑战第12天】
123 6
Ubuntu apt-get 命令大全
|
10天前
|
并行计算 Ubuntu Linux
Ubuntu学习笔记(五):18.04安装多版本CUDA
这篇博客文章介绍了在Ubuntu 18.04系统上如何安装和切换不同版本的CUDA,以及如何安装不同版本的cuDNN。
57 2
|
Ubuntu 数据安全/隐私保护
【Ubuntu使用技巧】ubuntu sudo不需要输入密码
作者:gnuhpc 出处:http://www.cnblogs.com/gnuhpc/ 网上流传最广关于这个的操作的中文博文写的很邪乎,例如这一篇,http://mrtips.blogbus.
556 0
|
10天前
|
并行计算 PyTorch TensorFlow
Ubuntu安装笔记(一):安装显卡驱动、cuda/cudnn、Anaconda、Pytorch、Tensorflow、Opencv、Visdom、FFMPEG、卸载一些不必要的预装软件
这篇文章是关于如何在Ubuntu操作系统上安装显卡驱动、CUDA、CUDNN、Anaconda、PyTorch、TensorFlow、OpenCV、FFMPEG以及卸载不必要的预装软件的详细指南。
766 3
|
4天前
|
Ubuntu Linux 测试技术
Linux系统之Ubuntu安装cockpit管理工具
【10月更文挑战第13天】Linux系统之Ubuntu安装cockpit管理工具
25 4
Linux系统之Ubuntu安装cockpit管理工具

相关产品

  • 云解析DNS