Bug 1015851 - gethostbyname failed to retrieve IPv6 address in /etc/hosts
gethostbyname failed to retrieve IPv6 address in /etc/hosts
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: glibc (Show other bugs)
All Linux
unspecified Severity high
: rc
: ---
Assigned To: glibc team
Depends On:
  Show dependency treegraph
Reported: 2013-10-06 03:45 EDT by wzis
Modified: 2017-11-08 05:43 EST (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2017-11-08 05:43:28 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

External Trackers
Tracker ID Priority Status Summary Last Updated
Sourceware 19582 None None None 2016-02-08 07:17 EST

  None (edit)
Description wzis 2013-10-06 03:45:26 EDT
Description of problem: the IPv6 address put in /etc/hosts with a special and unique name for it doesn't get returned by gethostbyname using that name.

Version-Release number of selected component (if applicable):

How reproducible:
Just put an IPv6 address in /etc/hosts, and give it a name. Then in a C program call gethostbyname("thename"); even when the /etc/nsswitch.conf has "files dns" for hosts, but the return result is not the IPv6 address in the /etc/hosts for that name. You may need to select a name that your DNS server can resolve.

Steps to Reproduce:

Actual results:
the returned address is from DNS, not the one in /etc/hosts.

Expected results:
the returned address should be from /etc/hosts when "files dns" is used for hosts in nsswitch.conf.

Additional info:
Comment 2 wzis 2013-10-06 05:05:07 EDT
only after add "options inet6", now it works.
Comment 3 wzis 2013-10-06 05:07:05 EDT
But then the IPv4 address in /etc/hosts fail to work.
Comment 4 RHEL Product and Program Management 2013-10-13 21:46:27 EDT
This request was not resolved in time for the current release.
Red Hat invites you to ask your support representative to
propose this request, if still desired, for consideration in
the next release of Red Hat Enterprise Linux.
Comment 5 Carlos O'Donell 2013-10-15 14:28:22 EDT
Moving to rhel-6.6 for scoping.
Comment 11 Florian Weimer 2016-02-04 10:25:38 EST
(In reply to wzis from comment #0)
> Description of problem: the IPv6 address put in /etc/hosts with a special
> and unique name for it doesn't get returned by gethostbyname using that name.

gethostbyname only returns IPv4 addresses, by design.  Please provide more details what you are doing.
Comment 12 wzis 2016-02-04 17:06:07 EST
"gethostbyname only returns IPv4 addresses"? then why after adding "options inet6" to resolve.conf, it can return IPv6 address? Also the man page says
"The gethostbyname() function returns a structure of type hostent for the given host name. Here name is either a hostname, or an IPv4 address in standard dot notation (as for inet_addr(3)), or an IPv6 address in colon (and possibly dot) notation."
The gethostbyname does handle IPv6 address. So why without using the options, it can't return the IPv6 addr specified in the /etc/hosts?
Comment 15 Florian Weimer 2017-11-08 05:43:28 EST
I cannot reproduce this issue with glibc-2.12-1.209.el6.x86_64.  With “options inet6”, gethostbyname returns IPv6 addresses mapped IPv4, as expected.

Note that “options inet6” has been deprecated in upstream glibc.

Note You need to log in before you can comment on or make changes to this bug.