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

21
Works

What worked for me is just using the Google public nameserver in your example, the 8.8.8.8 as the first line in resolv.conf This came AFTER I unsuccessfully tried my own router's nameserver at 192.168.0.1 and my local ISP's nameserver and one of my own server's nameserver ... which is very strange to me that only Google's public nameserver works for me. Of course, the other nameservers work with all other devices of my office and my home ... except CentOS 6.3 and 6.4 which I just installed this week. The other nameservers *do* work with my old CentOS 5.8 server for some reason and another CentOS server installation many months ago. I have experimented a bit, and the only thing which works well for me is Google's 8.8.8.8 nameserver as the first line. As I have spent hours on this problem, with multiple reinstalls of CentOS 6.3 and 6.4, both minimal and full DVD installation of "Web server", with the same failure experiences on this one DNS point, I am very appreciative of your help and wish to potentially save many others hours as well. For example, with my own LAN nameserver, I can ping ibiblio.org but if I immediately thereafter try to ftp ibiblio.org then ftp fails (" No address associated with hostname"), but I can ping again successfully. It's actually your mention of the Google public nameservers which were the solution which worked for me. It still leaves the issue of "WHY?" unanswered. Since many people have reported having the same problem, surely countless other people are having it as well. It wasn't fixed between CentOS 6.3 and CentOS 6.4 . Nor was it fixed by a yum update , as I just put mirror.centos.org into my hosts file with the IP I got from ping so I did get a yum update, but the yum update still didn't fix the problem. To reiterate, ping works OK with various resolv.conf settings but yum and ftp did not work on hostname lookups with the same settings. It's only on my latest 6.4 installation that I tried I put Google's public nameserver as the *first* line of resolv.conf , which worked. However, if Google's public nameserver was the second line then it failed. Regarding another user's solution by working on named, I do not have named installed and I suspects others do not, either. Installing named and properly configuring it is apparently unnecessary to solve this problem. Just try different nameservers until you find one which works for your CentOS, or use Google's.

22
jordan

Hi Works, the problem, as mentioned in the post, is that some programs only check the first resolver that's listed, and not the others that are listed. Once you made 8.8.8.8 the first entry, that was the entry that the programs that only check the first entry used. Other programs, like ping, check all resolvers until a resolution is made, and hence you can ping things just fine but they still don't resolve with programs that only check the first entry. Hope this helps!

24
buzz blustein

Brilliant solution Thanks, hope I can do something for you in the future

25
sajid

You Rock!!! You are genius!! Love you man....

26
kiran

I've the same problem and i looked into resolv.conf file.. the name server with 127.**.**.** is at the bottom in that file. but the issue is not resolved yet..

27
Josh

I had the same problem after a fresh install, I too checked resolv.conf and saw that it was empty. I also ran ifconfig and saw that I had no IP address so I checked /etc/sysconfig/network-scripts/ifcfg-eth0 and saw that ONBOOT=no once I changed it to yes I reboot and the problem was solved.

28
Manju

Helped me thank u

29
FreyrLin

Good, my system didn't reboot for quite a long time, but today after reboot the yum stop work. Your blog do helps a lot, problem is DNS configure clean up!

30
AK

Thanks, you saved me a lot of troubleshooting, in a real short time!

31
Sashi

Thank you,, it worked..

32
Edson

thanksss, I was with these problem , up installation in this moment in my pc

33
Stevenson

Thanks!! It saved me :)

Write your comment

(it will not be displayed)

Leave this field empty: