Briefing

The tragedy of gethostbyname

hosting
by ariadne.space via kokada ·

Patch your apps to use a dedicated DNS resolver library like c‑ares or adns instead of gethostbyname/getaddrinfo.

What to do now

Patch your applications to use a dedicated DNS resolver library such as c‑ares or adns, and avoid relying on gethostbyname/getaddrinfo for production workloads.

Summary

Gethostbyname was introduced in 4.2BSD in 1983 and originally only read /etc/hosts, performing no DNS queries. In 1984 4.3BSD added DNS support via res_search, returning the first IP address and falling back to /etc/hosts if the query failed. The APIs were standardized in X/Open Networking Services Issue 4 (SUSv3) in 1995, and later re‑introduced in POSIX Issue 6 (2004) after being deprecated in XNS5. Musl’s DNS client was written with the assumption that applications would use a dedicated resolver; it now plans to add DNS‑over‑TCP support to address bulk‑data use cases. The Name Service Switch (NSS) allows hot‑plugging DNS modules, and systemd‑resolved can be forced via nss‑systemd, but disabling the dns module in /etc/nsswitch.conf removes DNS entirely from gethostbyname. Because gethostbyname/getaddrinfo are blocking and implementation‑defined, they are unreliable for production workloads that need fast, bulk DNS resolution. Developers should therefore use specialized libraries such as c‑ares, GNU adns, s6‑dns, or OpenBSD’s libasr to guarantee consistent behaviour. The article explains why relying on the libc resolver is a legacy design that can break on modern systems.

Key changes

  • gethostbyname originally only read /etc/hosts in 4.2BSD (1983).
  • 4.3BSD added DNS queries via res_search, returning first IP and falling back to /etc/hosts.
  • POSIX Issue 6 (2004) re‑introduced gethostbyname after XNS5 deprecation.
  • Musl’s DNS client assumes dedicated resolver; DNS‑over‑TCP extension is planned.
  • NSS enables hot‑plugging DNS modules; systemd‑resolved can be forced via nss‑systemd.
  • Disabling the dns module in /etc/nsswitch.conf removes DNS from gethostbyname.
  • gethostbyname/getaddrinfo are blocking and unreliable for bulk DNS resolution.
  • Recommended to use dedicated DNS libraries like c‑ares, adns, s6‑dns, or libasr.

Affects

internal

Customer impact

Analyzing matches…

Ask about this story

Impact on an agency? Which customers? Compare historically Risks of waiting