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
dig Command Reference: Flags, Usage & CI ExamplesReference for dig: +short, record types, @server, +trace, and a CI example that resolves a hostname to verify…
nslookup Command Reference: Usage & CI ExamplesReference for nslookup: querying A/MX/TXT records, specifying a server, the dig comparison, and a CI example…
uname Command Reference: Flags, Usage & CI ExamplesReference for uname: -a, -s, -m, -r, the OS/arch detection use, and a CI example that branches a script on op…