写在前面:
🌟 欢迎光临 清流君 的博客小天地,这里是我分享技术与心得的温馨角落。📝


🎭 人生如戏,我们并非能选择舞台和剧本,但我们可以选择如何演绎 🌟
感谢您的支持与关注,让我们一起在知识的海洋中砥砺前行~~~

文章目录

  • 一、问题描述
  • 二、原因分析
  • 1、添加DNS服务器
  • 2、换源
  • 三、解决方案
  • 1、查找源配置文件路径
  • 2、删除生效的源配置文件
  • 3、完美解决


一、问题描述

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

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

具体信息如下:

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


二、原因分析

  出现这个问题之前,我尝试使用网络代理proxy下载一些外网的资源,按照 CSDN 教程创建了一些网络代理环境,但是还是没有成功,然后清除这些配置,但是可能没有清除干净,导致我的apt所使用的域名仍然是之前设置的一个海外的 【Ubuntu】sudo apt-get update 无法解析域名(亲测有效)_服务器_02

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

网页可以正常打开

  • 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,解决!


后记:

🌟 感谢您耐心阅读这篇关于 sudo apt-get update 无法解析域名 的技术博客。 📚

🎯 如果您觉得这篇博客对您有所帮助,请不要吝啬您的点赞和评论 📢

🌟您的支持是我继续创作的动力。同时,别忘了收藏本篇博客,以便日后随时查阅。🚀

🚗 让我们一起期待更多的技术分享,共同探索移动机器人的无限可能!💡

🎭感谢您的支持与关注,让我们一起在知识的海洋中砥砺前行 🚀