yum "Couldn't resolve host 'mirrorlist.centos.org'" for CentOS 6

I ran into an issue recently where I could ping URL's just fine, but when I ran the "yum update" command yum could not resolve anything. I would get error messages like the following:

[root@viviotech ~]# yum -y update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os error was
14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
Error: Cannot find a valid baseurl for repo: base

DNS and BindAfter a bit of digging, and absolutely no help from my friend Google, I asked one of the Vivio technicians about it and he said he'd seen it on other servers - specifically servers with VirtualMin.

Take a look at the resolve.conf file:

nameserver 127.0.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4

See how VirtualMin adds the 127.0.0.1 address first? Apparently YUM will ONLY check the very first entry in the /etc/resolve.conf file when it looks for the server to resolve IP Addresses. In this case, the local DNS resolver was not configured to use forwarders, so the YUM process would ask the local DNS server where to find "mirrorlist.centos.org", and when the local resolver didn't know, YUM would simply report an error instead of looking at the other resolvers in the /etc/resolve.conf list. This is why I could ping URL's just fine, but YUM could not find them.

The solution to this was to simply place the 127.0.0.1 entry at the botton of the /etc/resolv.conf file, like so:

nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 127.0.0.1

After that, eveything worked great.

IMPORTANT: The above examples of the /etc/resolv.conf file use the IP Addresses of the Google Public DNS

Comments

3
Robert

Thank you! I did a minimal Centos 6.3 install that left the resolv.conf file blank and I was scratching my head over this one. Cheers!

4
Maz

Indeed that was the problem. Such a stupid error.

5
bev

thanks a lot, perfecto!!

6
D H

THANKS!!!!! After looking and looking...

7
sagar

how can i sovle following problem i am working with CentOs [root@sagar ~]# yum install upgrade Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=i386&repo=os error was 14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'" Error: Cannot find a valid baseurl for repo: base

8
Chris Blackwell

I don't think moving 127.0.0.1 to the end of resolv.conf is really the best solution, this would mean that all dns queries have to be made externally which is very ineffiecient. The likely cause of your problem was that the local dns server (bind if you're using virtualmin) isn't allowing recursive lookups, which it should do from localnets but not remote you should check /etc/named.conf, mine contains options { /* just showing relevant portions */ allow-query { any; }; recursion yes; allow-recursion { localnets; 127.0.0.1; }; } now you can keep 127.0.0.1 at the top of resolv.conf by allowing bind to do recursive dns lookups for queries but only from the local machine.

9
Jordan

@ sagar I would checkto see if you had a network connection at all before trying to diagnose it. @ Chris I concede that moving 127.0.0.1 isn't always the best solution, but it will work jut fine for the majority of situations. Thank you for the alternate solution!

10
Ronan Loftus

Thank you. This worked perfectly for me on fedora 17 and now it seems all errors are gone, greatly appreciated!

11
Me Too

I also had this problem with a fresh install of CentOS 6.3 Not too happy - had to work out the problem and the text left in resolv.conf was not too helpful. # Generated by NetworkManager # No nameservers found; try putting DNS servers into your # ifcfg files in /etc/sysconfig/network-scripts like so: # #DNS1=XXX.XXX.XXX.XXX #DNS2=XXX.XXX.XXX.XXX #DOMAIN=localhost.localdomain

12
jim

I had the same problem, however, my resolve.conf had been automatically generated and included a search and a domain line before the nameserver lines. Moving these to the bottom of the file sorted things.

13
Josef

Thank you very much.

14
ken

Thanks...this is certainly one of Centos' dumbest features :-P

15
sadlyblue

Thanks... It worked. After some google searching, you had the solution.

16
Abdurrahim

i am trying to run command yum install glibc.i686 i have added above lines in resolv.conf than i get error "The requested URL returned error: 403" pls give some solution

17
Rome

I always disable "NetworkManager" on a server.

18
jaylord

this one really help me a lot. thanks

20
beybi

thanks...!

Write your comment

(it will not be displayed)

Leave this field empty: