Description of problem: Since upgrading to glibc-2.5-65.el5_7.3 we noticed that gethostbyname() can now return duplicate addresses - if the name appears in /etc/hosts multiple times. Machines running with glibc-2.5-58.el5_6.4 do not show this behaviour. I've not tested glibc-2.5-81 yet but the announcement https://rhn.redhat.com/errata/RHBA-2012-0260.html does not mention anything obviously related. Note in the test setup we have nsswitch set to look in /etc/hosts first and host.conf has multi set to on, but so do the systems with the previous glibc which do no show the new behaviour. Running with/without nscd doesn't affect this other than that it caches the results. Version-Release number of selected component (if applicable): glibc-2.5-65.el5_7.3 How reproducible: 100% Steps to Reproduce: Here is my test procedure. I wrote a trivial test script ~/scripts/gethostbyname.pl : #! /usr/bin/perl # use Socket; foreach $i (@ARGV) { ($name,$aliases,$addrtype,$length,@addrs)=gethostbyname($i); printf "%-25s %s\n", $name, $i; foreach $ad (@addrs) { print " ".inet_ntoa($ad)."\n"; } } On a machine running the newer glibc: # grep multi /etc/host.conf multi on # grep '^host' /etc/nsswitch.conf hosts: files dns # service nscd stop Stopping nscd: [ OK ] # grep beast /etc/hosts # ~jp107/scripts/gethostbyname.pl beast beast # echo "10.6.6.6 beast" >> /etc/hosts # grep beast /etc/hosts| wc -l 1 # ~jp107/scripts/gethostbyname.pl beast beast beast 10.6.6.6 # echo "10.6.6.6 beast" >> /etc/hosts # grep beast /etc/hosts| wc -l 2 # ~jp107/scripts/gethostbyname.pl beast beast beast 10.6.6.6 10.6.6.6 # echo "10.6.6.6 beast" >> /etc/hosts # grep beast /etc/hosts| wc -l 3 # ~jp107/scripts/gethostbyname.pl beast beast beast 10.6.6.6 10.6.6.6 10.6.6.6 # ... Actual results: duplicate (idential) addresses returned Expected results: each unique address returned only once. Additional info: The 'old' glibc behaviour is what we also get on Solaris. It is possible that gethostbyname() was always intended to return the address multiple times, and the previous behaviour was a (very longstanding) bug. We originally noticed this because a script we use to generate /etc/host sticks some names in twice. Apache got confused if a "listen name:port" where gethostbyname(name) returns the same address multiple times - it tries to bind to the same address/port multiple times which fails (and the apache error message doesn't make it clear what is going wrong, but that isn't glibc's fault)... We have corrected our script to avoid those duplicates, but the change of behaviour in glibc might affect others.
I believe that the 'new' behaviour is also present in the latest glibc in EL6.2, but I have not tested that myself. Sorry I forgot to mention that we are actually running on Scientific Linux 5.7 but it is hard to see that this won't also affect RHEL customers since the glibc would be built from the same srpms.
I've been unable to recreate your desired behavior, even after installing a fresh version of Red Hat Enterprise Linux 5.6 with glibc-2.5-58.el5_6.4 which reportedly has the desired behaviour. The returning multiple entries, including duplicates has been the intended behaviour when /etc/host.conf specifies "multi on" since 2000 (glibc-2.1.91). This pre-dates Red Hat Enterprise Linux 3.0. There have been a couple bugs where glibc was not producing the intended behaviour; one occurred when using nscd, the other using the getaddrinfo routine from glibc. Both were fixed in glibc-2.5-65. Given the behaviour you're seeing in the intended behaviour when /etc/host.conf specifies multi on, I'm closing this as NOTABUG. If you have further questions, feel free to add them to this bug report. I'll get notified if you add any comments.