With glibc, name resolution goes getaddrinfo()
â nsswitch.conf (for Name Service Switch, which is not Network Security Services) â /etc/hosts
or DNS. If DNS: â libresolv â host.conf
â /etc/hosts
or real DNS.
With musl, name resolution goes getaddrinfo()
â /etc/hosts
or DNS. name_from_hosts()
reads /etc/hosts
directly, and name_from_dns_search()
calls name_from_dns()
for each search domain with resolver configuration read from /etc/resolv.conf
.
Both glibc and musl defaults to returning all valid addresses for a host that appears in the /etc/hosts
file, instead of only the first. muslâs behavior is not configurable and has a fixed limit of at most 48 results. glibcâs behavior can be configured with the multi
keyword in the /etc/host.conf
file, and can be overridden by the RESOLV_MULTI
environment variable.
gethostbyname()
gethostbyname()
is obsolete, does not support IPv6 and only returns one IP address even if there are multiple entries.
Applications
Some applications do name resolution on their own, some always pick the first address returned from getaddrinfo()
. The behavior is very application-specific and you should always test it before making conclusion.