Checking Host Resolution Using getent
Luke Hebert
- 2 minutes read - 405 wordsWhen a service on your Linux box cannot reach a host by name, the first thing to check is whether the system can actually resolve that name. The getent command gives you a fast, low-noise way to see exactly what your resolver returns, without the extra output that tools like nslookup or dig tend to produce.
What getent Does
getent queries the Name Service Switch (NSS) databases defined in /etc/nsswitch.conf. That means it walks through every source your system is configured to use, in order: typically /etc/hosts, then DNS, then NIS or LDAP if present. The result you see is the same one your applications will get.
Basic Usage
Resolve a fully qualified domain name:
getent hosts example.comResolve a short (unqualified) name:
getent hosts webserverReverse-lookup an IP address:
getent hosts 192.168.1.10Each line of output shows the IP address followed by one or more hostnames, for example:
192.168.1.10 webserver.example.com webserverWhy Prefer getent Over nslookup or dig
- It respects your full
/etc/nsswitch.conforder, so a/etc/hostsentry will short-circuit DNS just like it does for your applications. - It returns a single, clean line instead of a multi-line query/response dump.
- It is available on virtually every Linux distribution without extra packages.
Troubleshooting Tips
- No output at all. The name does not resolve through any configured source. Check your DNS server settings in
/etc/resolv.confand confirm the domain exists. - Output shows an unexpected IP. A
/etc/hostsentry or a split-horizon DNS record is likely overriding the public answer. Compare withdig +short <name>to see what the authoritative DNS server returns. - Short name resolves but FQDN does not (or vice versa). Your
searchordomaindirectives in/etc/resolv.confmay be appending a suffix that does not exist. - Works as root but not as a regular user. Check file permissions on
/etc/hostsand/etc/resolv.conf; a restrictiveumaskor SELinux policy can block reads.
Quick Comparison
| Command | What it checks | Typical use |
|---|---|---|
getent hosts <name> | Full NSS chain | “Can my system resolve this?” |
dig <name> | Authoritative DNS only | “What does DNS actually say?” |
nslookup <name> | DNS (legacy) | Quick ad-hoc lookups |
host <name> | DNS (simple) | One-line DNS answer |
Wrapping Up
getent hosts is the fastest way to confirm that your Linux system can resolve a name the same way your applications will. Run it before you start digging into DNS server logs or firewall rules, and you will save yourself a lot of back-and-forth.