How to Solve Error Message Could not retrieve mirrorlist http://mirrorlist.centos.org when using yum to install package in Linux CentOS

Posted on

Introduction

This is an error appear where the focus for solving it become the solution of the problem. The problem appear as in the title of the article. There is a problem upon installing a package using ‘yum’ command. Actually the network connection from the server or the machine to the internet is perfectly fine. But the main problem actually relies on the policy of the network itself. Apparently, it does not allow any ‘yum’ connection from the machine or the server itself. Before moving on to the solution, the following is the actual appearance on the installation process execution :

[root@localhost ~]# yum -y install supervisor
Loaded plugins: fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=genclo 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= ...

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

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

Cannot find a valid baseurl for repo: base/7/x86_64
[rootlocalhost ~]#

Troubleshooting Attempt

  1. First of all, check the gateway of the machine or server. It is an attempt to check whether the connection line to the internet is available through out the gateway. Just check the gateway and then try to ‘ping’ the IP address of the gateway as follows :

    [root@localhost ~]# route
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    default         gateway        0.0.0.0         UG  0 0 0 eth0
    169.254.169.254 192.168.1.1    255.255.255.255 UGH 0 0 0 eth0
    192.168.1.0     0.0.0.0        255.255.255.0   U   0 0 0 eth0
    [root@localhost ~]# ping 192.168.1.1
    PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
    64 bytes from 192.168.1.1: icmp_seq=1 ttl=123 time=1.14 ms
    ^C
    --- 192.168.1.1 ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 1.146/1.146/1.146/0.000 ms
    [root@localhost ~]#
    
  2. Since the line connection to the gateway is active, just check the name server using ‘nslookup’, ‘dig’ or check the file of the name server configuration as follows :

    [root@localhost ~]# nslookup
    -bash: nslookup: command not found
    [root@localhost ~]# dig
    -bash: dig: command not found
    [root@localhost ~]# cat /etc/resolv.conf
    ; generated by /usr/sbin/dhclient-script
    search local
    nameserver 192.168.100.2
    [root@localhost ~]#

    After that, try to ping the name server as follows :

    [root@localhost ~]# ping 192.168.100.2
    PING 192.168.100.2 (192.168.100.2) 56(84) bytes of data.
    64 bytes from 192.168.100.2: icmp_seq=1 ttl=123 time=1.14 ms
    ^C
    --- 192.168.100.2 ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 1.146/1.146/1.146/0.000 ms
    [root@localhost ~]#
    
  3. Actually, this article has a connection with the previous article. That article is an article showing on how to install ‘supervisor’ tool using yum command. The article with the title of ‘How to Install supervisord in Linux CentOS 7’ exist in this link.

    Apparently, the line connection to the gateway even to the name server is normal. So, in this case one of the solution which is available as an option in this article is the proxy configuration. Specifically, the ‘yum’ configuration for defining proxy configuration. It is already exist in the article with the title of ‘How to Configure Proxy Connection using yum tool to install package in Linux CentOS’ in this link. So, add a proxy connection configuration to the ‘yum’ file configuration as follows :

    proxy=http://xxx.xxx.xxx.xxx:xxx

    Fortunately, it is the correct option to do and in this case it is a successful way to use the yum tool properly. It works well since it has been a success for installing one of the package available in another article. That package is supervisord as it exist in the previous article mentioned before.

Leave a Reply