An entry for buildhost in /etc/hosts is being ignored by dig, which keeps returning NXDOMAIN. Which command resolves the name the same way an ordinary application would, so you can confirm the /etc/hosts entry is effective?

LPIC-1 Exam 102-500, objective 109. Networking fundamentals hard

Draft — not checked yet. This question was written from the published exam objectives and cites the clause it comes from, but nobody has yet read it against that clause and signed for it.

It is kept out of search results and out of mock exams until they have. Read the source below before you take the answer as settled.

The options

Not correct nslookup buildhost

Wrong. Like dig, nslookup is a DNS-protocol client. It sends a query to a name server and ignores /etc/hosts and the rest of NSS.

Not correct host buildhost

Wrong. host is also a pure DNS client from the BIND utilities; it will report the name as not found regardless of /etc/hosts.

Not correct dig +short buildhost

Wrong. +short only trims dig's output to the bare answer. It does not change where dig looks, which is still DNS only.

Correct getent hosts buildhost

Correct. getent queries the NSS databases exactly as the C library does, so it walks the hosts line of /etc/nsswitch.conf, including the files source that reads /etc/hosts.

Why

dig, host and nslookup speak DNS directly and deliberately skip /etc/hosts, NSS and any local caching resolver behaviour. getent hosts NAME goes through the same glibc path as ping, ssh and browsers do, which makes it the right tool for the question 'what will an application actually get?'. A disagreement between getent and dig is normally an /etc/hosts entry or an nsswitch ordering, not a DNS fault.

Where this comes from

Cited
LPI exam objective 109.2
What it says
Query hostname resolution with host, dig and getent.

Practise this

Reading one question is not practice. The trainer will draw a set from objective 109 and space the ones you get wrong.

Practise LPIC-1 Exam 102-500