解决Could not resolve host: mirrorlist.centos.org; Unknown error

首先需要确定问题原因,是否是自己的网络问题。能ping通 任意互联网网站 就是镜像文件配置的问题了。

一、网络的问题
ping www.baidu.com
ping 不通的需要配置网络

关于VMware的虚拟网络编辑器配置,网络使用的是NAT模式,Linux的IP配置要与NAT模式配置在同一网段中。

 

Linux配置的网关也是与NAT中的配置一致,参考自己配置的情况进行修改

通过 ifconfig 查看Linux的网络配置

ifconfig


如果不是ens33,就将末尾修改成对应的文件名

vim /etc/sysconfig/network-scripts/ifcfg-ens33
在文件末尾添上

 

也可以如下,效果一样。(根据自己配置二选一,在末尾添加)

IPADDR="192.xx.xx.xx"
GATEWAY="192.xx.xx.x"
NETMASK="255.255.255.0"
DNS1="8.8.8.8"
DNS2="114.114.114.114"
IPV6_PRIVACY="no"
配置好后,需要重置一下网络

systemctl restart network
如果还是ping不通,虚拟机使用的NAT模式,进入 控制面板\网络和 Internet\网络连接,将

VMnet8的IPV4设置为自动获取IP和DNS

 

以上 ping www.baidu.com 基本没啥问题。

二、镜像资源问题
先查看一下自己的DNS,如下配置即可

vim /etc/resolv.conf

 

1、配置镜像文件
1).备份自己的原来的镜像配置文件
本操作是防止误操作,可以进行还原。

用 mv 指令备份好自己的原来的CentOS-Base.repo 文件,这个(CentOS-Base.repo.backup)名字可以不一致,自己知道备份的文件名就行

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
如果误操作了,仅需将备份文件名改回 CentOS-Base.repo

2).确认自己的Centos的版本
下列方法任选一种

cat /etc/centos-release


hostnamectl


3).下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
选择自己对应的版本。直接复制运行其中一条指令即可

CentOS 7

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者

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

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
Centos6

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
或者

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
3). 运行生成缓存
yum makecache
结果如下,就成功了。
好了就下载东西测试一下 yum install -y unzip zip

 

4. 如果还未成功可以查看下面
出现 Couldn't resolve host 'mirrors.cloud.aliyuncs.com' 信息,不影响使用。可自行修改相关配置

sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/Cent
2、直接访问阿里的案例镜像资源网站(有操作流程)
centos镜像_centos下载地址_centos安装教程-阿里巴巴开源镜像站 (aliyun.com)

posted on 2024-09-25 17:02  卖小女孩的小男孩  阅读(77)  评论(0)    收藏  举报