Skip to content
Latchkey

getent Command Reference: Databases, Usage & CI Examples

getent queries the system NSS databases like hosts, passwd, and group.

getent reads the Name Service Switch databases the system itself uses, so its host lookups honor /etc/hosts and nsswitch.conf, not just DNS. That makes it the most accurate resolver check in a container.

Common flags and usage

  • getent hosts <name>: resolve via NSS (/etc/hosts then DNS)
  • getent ahosts <name>: all address families
  • getent passwd [user]: user database entries
  • getent group [group]: group database entries
  • getent services <name>: service/port entries

Example

shell
getent hosts db.internal || echo "name does not resolve via NSS"

In CI

getent hosts reflects how the application will actually resolve a name, including /etc/hosts overrides and container DNS, where dig queries DNS only. Use it to verify a service alias inside a Docker network resolves before connecting.

Key takeaways

  • getent queries NSS databases, not just DNS.
  • getent hosts mirrors how the app actually resolves a name.
  • It honors /etc/hosts and container DNS overrides.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →