Centos7 yum 报错“Could not resolve host: mirrorlist.centos.org; Unknown error“

[root@localhost ~]# yum install net-tools
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"


 One of the configured repositories failed (Unknown),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64

yum install xxx报错!

解决方式

[root@localhost ~]# 
sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo
 
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
更新yum镜像
[root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
清除缓存,重新运行
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache

[root@localhost ~]# yum install -y net-tools


Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package net-tools.x86_64 0:2.0-0.25.20131004git.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================
 Package               Arch               Version                               Repository        Size
=======================================================================================================
Installing:
 net-tools             x86_64             2.0-0.25.20131004git.el7              base             306 k

Transaction Summary
=======================================================================================================
Install  1 Package
...

### Yum 配置中无法解析 `mirrorlist.centos.org` 的解决方案 当遇到错误提示 `Could not resolve host: mirrorlist.centos.org; Unknown error` 时,通常是因为系统尝试连接到 CentOS 官方镜像列表服务器失败。这可能是由于网络限制或官方资源不可用引起的。以下是具体的解决方法: #### 替换为国内可用的镜像源 由于国内网络可能无法正常访问 `mirrorlist.centos.org`,建议将其替换为国内可访问的镜像源地址。可以通过下载并覆盖默认的 `CentOS-Base.repo` 文件来实现。 执行以下命令之一以更新仓库配置文件: ```bash wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo ``` 或者使用 `curl` 命令完成相同操作: ```bash curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo ``` 上述命令会将阿里云提供的 CentOS 7 镜像源写入系统的 YUM 配置文件中[^4]。 #### 清理旧缓存并重建新缓存 在更改了 YUM 源之后,需要清理原有的缓存数据,并重新生成新的缓存以便于后续的操作能够顺利进行。运行如下两条指令即可完成此过程: ```bash yum clean all yum makecache ``` 通过这些步骤可以清除之前的错误记录以及加载最新的软件包索引信息[^3]。 #### 确认网络连通性 如果仍然存在类似的主机名解析问题,则还需要确认本机是否有正常的互联网接入能力。比如测试能否成功 ping 到外部站点如百度网站(`www.baidu.com`)。另外也可以考虑重启网络服务来修复潜在的小型故障: ```bash systemctl restart network ``` 以上措施综合起来应该能有效地处理因无法解析特定域名而导致的各种 yum 工具使用的障碍情况。 ### 注意事项 对于不同版本号或者其他发行版衍生出来的 Linux 发行版来说,具体路径名称可能会有所差异,请按照实际情况调整对应部分的内容设置。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值