【Centos7】无法解析镜像源地址-解决方案

文章目录
  • 使用 curl 替代 wget
  • 5. 执行更新
  • 一、查看是否能连接到外网

    我们通过ping命令,来查看是否与外网连同

    OK,啊,连同外网没问题

    • 如果无法解析域名,可能是 DNS 配置问题
    • 如果无法访问 IP 地址,可能是 防火墙或网络代理问题

    解决方法:

    • 临时更换 DNS(例如使用 DnsPod DNS):echo "nameserver 119.29.29.29" > /etc/resolv.conf
    • 或者永久修改 DNS 配置(编辑 /etc/resolv.conf

    二、修改 YUM 镜像源为国内镜像

    由于 CentOS 官方镜像源可能访问不稳定,建议更换为国内镜像(如阿里云、清华源)。

    步骤:

    1. 备份原始配置文件mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
    1. 下载阿里云镜像配置(以 CentOS 7 为例):wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

    出现 -bash: wget: 未找到命令 的错误,说明当前系统中 未安装 wget 工具。以下是解决方法:

    使用 curl 替代 wget

    因为软件源有问题导致无法安装 wget,可以直接使用 curl 下载文件(无需安装额外工具):

    sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

    3. 验证文件是否下载成功

    下载完成后,检查文件内容:cat /etc/yum.repos.d/CentOS-Base.repo

    确保内容包含阿里云镜像地址

    4. 清理并重建 YUM 缓存

    sudo yum clean all

    sudo yum makecache

    5. 执行更新

    最后运行:sudo yum update

    冷行

    我还没有学会写个人说明!

    相关推荐

    暂无评论

    发表评论

    您的电子邮件地址不会被公开,必填项已用*标注。

    这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理