Verbatim output from my terminal:

$ getent hosts example.org
2001:500:88:200::10 example.org
$ getent ahosts example.org     STREAM 43-10.any.icann.org     DGRAM     RAW    

I thought they were both (at the very least ahosts) supposed to print both IPv4 and IPv6 addresses. Why are these printing different address types?

$ uname -srvmpio
Linux 3.2.0-31-generic #50-Ubuntu SMP Fri Sep 7 16:17:36 UTC 2012 i686 i686 i386 GNU/Linux

Edit: Looks like it might be related to this bug report.


1 Answer 1


Both getent hosts and getent ahosts can potentially print both IPv4 and IPv6 addresses, but they decide which address(es) to print differently (that's the point of having two different commands).

hosts calls gethostbyname2 (the IPv6-supporting variant of gethostbyname). The behavior is hard-coded: look up an IPv6 address, and if none exists, look up an IPv4 address.

ahosts calls getaddrinfo. This function enumerates all protocols for a given name, so it can return both IPv4 and IPv6 addresses in the same call. What it returns is determined by the settings in /etc/gai.conf. Because many applications are still struggling to cope with IPv6, most distributions prefer IPv4 by default and only use IPv6 by explicit request.

Some useful reading on ahosts and gai.conf around Stack Exchange:

  • My system also has ahostsv4 and ahostsv6, as revealed in the man page. Commented Jun 4, 2023 at 1:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .