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

执行 yum 命令时报:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock32 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. Disable the repository, 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>

4. 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

配置下网络即可。

  • 查看网卡配置文件:

    1
    2
    $ cd /etc/sysconfig/network-scripts
    $ ls
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    ifcfg-ens32      ifdown-post      ifup-eth     ifup-sit
    ifcfg-ens32.bak ifdown-ppp ifup-ib ifup-Team
    ifcfg-lo ifdown-routes ifup-ippp ifup-TeamPort
    ifdown ifdown-sit ifup-ipv6 ifup-tunnel
    ifdown-bnep ifdown-Team ifup-isdn ifup-wireless
    ifdown-eth ifdown-TeamPort ifup-plip init.ipv6-global
    ifdown-ib ifdown-tunnel ifup-plusb network-functions
    ifdown-ippp ifup ifup-post network-functions-ipv6
    ifdown-ipv6 ifup-aliases ifup-ppp
    ifdown-isdn ifup-bnep ifup-routes

    第一个 ifcfg-ens32 就是网卡配置文件,不同机器略有不同:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    TYPE=Ethernet
    BOOTPROTO=static
    IPADDR=192.168.1.74
    GATEWAY=192.168.1.1
    NETMASK=255.255.255.0
    DNS1=8.8.8.8
    DEFROUTE=yes
    PEERDNS=yes
    PEERROUTES=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_PEERDNS=yes
    IPV6_PEERROUTES=yes
    IPV6_FAILURE_FATAL=no
    IPV6_ADDR_GEN_MODE=stable-privacy
    NAME=ens32
    UUID=fbe7146b-693d-4047-b73c-fd685a76337b
    DEVICE=ens32
    ONBOOT=yes
  • 备份

    1
    $ sudo cp /etc/sysconfig/network-scripts/ifcfg-ens32 /etc/sysconfig/network-scripts/ifcfg-ens32.bak
  • 编辑 ifcfg-ens32 文件:

    • 针对动态配置,需要设置:

      1
      2
      3
      4
      5
          BOOTPROTO=dhcp
      ONBOOT=yes
      ``

      - 针对静态配置,需要设置:

      BOOTPROTO=static
      ONBOOT=yes

      1
      同时静态配置还要设置固定 IP,网关,DNS:

      IPADDR=192.168.1.74
      GATEWAY=192.168.1.1
      NETMASK=255.255.255.0
      DNS1=8.8.8.8

      1
      2

      - 重启网络服务并更新资源

      $ sudo systemctl restart network
      $ sudo yum update

转载自 CentOS报错: Could not resolve host: mirrorlist.centos.org; Unknown error

分享到:
Disqus 加载中...

如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理