LINUX:错误“Could not resolve host: mirrors.aliyun.com; Unknown error“

前提

前提:使用SSH连接虚拟机

           操作系统镜像版本:CentOS-7-x86_64-Minimal-2207-02

           配置文件变更为:(地址:centos-vault镜像_centos-vault下载地址_centos-vault安装教程-阿里巴巴开源镜像站 (aliyun.com)

#Linux  Centos 7.9.2009
minorver=7.9.2009
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
         -e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo

       

错误

该错误产生的原因:DNS 服务器配置

                                 系统无法解析域名
[root@localhost ~]# yum -y install wget
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
https://mirrors.aliyun.com/centos-vault/7.9.2009/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.aliyun.com; Unknown error"
Trying other mirror.


 One of the configured repositories failed (CentOS-7 - Base),
 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=base ...

     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 base
        or
            subscription-manager repos --disable=base

     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=base.skip_if_unavailable=true

failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.
https://mirrors.aliyun.com/centos-vault/7.9.2009/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.aliyun.com; Unknown error"

 

解决方法

下面是一些常见的中国公共 DNS 服务器:

- 阿里公共 DNS:
  - 223.5.5.5
  - 223.6.6.6

- 百度公共 DNS:
  - 180.76.76.76

- 114 DNS:
  - 114.114.114.114
  - 114.114.115.115

编辑 `/etc/resolv.conf` 文件来使用这些 DNS 服务器。

1. 打开 `/etc/resolv.conf` 文件:

vi /etc/resolv.conf

2. 添加以下内容:

nameserver 223.5.5.5
nameserver 223.6.6.6
nameserver 180.76.76.76
nameserver 114.114.114.114
nameserver 114.114.115.115

3. 保存并退出文件。

4. 检查 DNS 配置是否生效:

nslookup baidu.com

如果能够正常解析域名,说明 DNS 配置已经生效。

5. 如果你希望这些设置永久生效,可以考虑锁定 `/etc/resolv.conf` 文件防止被 DHCP 客户端覆盖:

chattr +i /etc/resolv.conf

请注意,锁定文件可能会影响到系统的其他网络配置操作。如果需要修改 DNS 配置,可以先解锁:

chattr -i /etc/resolv.conf

尝试以上步骤后,你的系统应该能够正常解析域名并连接到软件源。

### 解决 'Could not resolve host: mirror.math.princeton.edu; Unknown error' 当遇到 `Could not resolve host` 的错误提示时,这通常意味着客户端无法将指定的域名转换为IP地址。此问题可能由多种原因引起,包括但不限于DNS配置不当、网络连接不稳定或是目标服务器本身存在问题。 #### DNS 配置检查 为了验证本地系统的DNS设置是否正常工作,可以尝试更改DNS服务器到公共DNS服务提供商,比如Google提供的8.8.8.8或Cloudflare提供的1.1.1.1[^1]: ```bash # 对于Linux系统,在/etc/resolv.conf文件中添加如下行: nameserver 8.8.8.8 nameserver 8.8.4.4 ``` 对于Windows用户,则可以通过控制面板中的网络和共享中心调整适配器设置下的首选项来修改DNS服务器地址。 #### 测试其他镜像源 如果特定镜像站点出现问题,考虑切换至另一个可用的软件包仓库。许多开源项目都提供了多个全球分布式的下载链接供选择。例如更换yum源或者apt-get源等命令所指向的位置[^2]。 #### 使用工具诊断网络状况 利用ping命令测试与该网站之间的连通性;通过nslookup查询具体的DNS记录是否存在异常情况;借助traceroute查看路由路径上是否有节点发生故障。这些操作有助于进一步定位具体的原因所在[^3]: ```bash ping mirror.math.princeton.edu nslookup mirror.math.princeton.edu traceroute mirror.math.princeton.edu ``` 以上方法可以帮助排查并最终解决问题。值得注意的是,有时候即使采取了上述措施之后仍然会收到相同的报错信息,这时可能是由于远程主机暂时性的不可访问造成的,建议稍后再试一次。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值