问题Could not resolve host: mirrorlist.centos.org; Unknown error【已解决】

在配置Linux下的Nginx服务器前安装gcc时出现该问题。

经过长时间的search,该问题产生的原因主要有以下几个方面:

1. 虚拟机的网络问题。

2. 镜像网站的配置问题。

3. DNS服务器的设置问题。

一、网络问题解决方案

(一)使用NAT模式

该模式下网络一般不会有太大问题,需要注意的是该模式下需要启用DHCP模式。

用以下命令检查网络模式。

配置如下图所示。

cat /etc/sysconfig/network-scripts/ifcfg-ens33

(二)使用主机模式

主机模式配置参考下文:

https://blog.csdn.net/weixin_68727920/article/details/141303586

配置好后重启网络。

三选一

sudo systemctl restart network

sudo nmcli networking on

sudo systemctl restart NetworkManager

二、镜像配置解决方案

(一)按需备份自己原来的镜像配置

此步骤目的在于防止误操作导致镜像毁坏。

mv /etc/yum.repos.d/CentOS-Base.repo /your/path/to/backup-name.repo.backup

(二)确认CentOS版本

法一:

cat /etc/centos-release

法二:

hostnamectl

(三)下载新的 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

(四)手动更新缓存

sudo yum clean all
sudo yum makecache

三、DNS服务器配置解决方案

(一)检查/etc/resolv.conf文件中的 DNS 服务器配置:

cat /etc/resolv.conf

应该看到类似以下内容:

nameserver 8.8.8.8
nameserver 8.8.4.4

如果没有,或 DNS 服务器不正确,可以手动添加 DNS 服务器。使用文本编辑器(如 vim 或 nano)编辑该文件,添加以上两个nameserver。

vim /etc/resolv.conf

参考两位大佬的文章:

【软件工具】CentOS 虚拟机出现 `Could not resolve host: mirrorlist.centos.org` 错误-CSDN博客

解决Could not resolve host: mirrorlist.centos.org; Unknown error_could not resolve host: mirrorlist.centos.org; unk-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值