/etc/nsswitch.conf contains the line `hosts: dns files`, and /etc/hosts maps db.example.com to 10.0.0.5 while public DNS returns 203.0.113.9 for the same name. What does an application using the standard resolver library get?
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 10.0.0.5, because /etc/hosts always takes priority over DNS
Wrong. /etc/hosts wins only when `files` appears before `dns` on the hosts line, which is the common default but is exactly what has been changed here.
Not correct Both addresses, since the resolver merges every source listed
Wrong. The sources are tried in order and the first one that answers ends the lookup; results are not merged.
Correct 203.0.113.9, because the sources are tried left to right and DNS answers first
Correct. nsswitch.conf lists lookup sources in priority order. With `dns files`, DNS is consulted first and its successful answer ends the search, so the /etc/hosts entry is never reached.
Not correct A lookup failure, because listing dns before files is an invalid configuration
Wrong. Any order of valid sources is legal; the file merely expresses a preference. `dns files` is unusual but perfectly functional.
Why
/etc/nsswitch.conf selects which databases back each kind of lookup and in what order, for example `hosts: files dns myhostname`. Order is the whole point: the first source that returns a result wins, unless an action such as `[NOTFOUND=continue]` overrides that. This is why tools that go straight to DNS, such as dig and host, can disagree with what an application actually resolves, while getent hosts follows nsswitch exactly.
Where this comes from
- Cited
- LPI exam objective 109.2
- What it says
- Understand how /etc/nsswitch.conf orders hostname resolution sources.
Practise this
Reading one question is not practice. The trainer will draw a set from objective 109 and space the ones you get wrong.