/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
Machine-checked — no person has signed for it. This question was read against the source cited below by an automated pass, which found no contradiction. That is a weaker claim than it sounds: the same kind of process wrote the question, so it can confirm its own mistake.
Treat it as a good draft rather than as settled fact, and read the source below before you rely on it. It is not used in mock exams here — only questions a person has signed for are.
How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.
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 short set from objective 109 and space the ones you get wrong.
More questions on this objective
- A subnet is defined as 192.168.10.0/26. How many addresses in it can actually be assigned to hosts? machine-checked
- A host is configured with the address 172.20.35.77/20. What is the network address of its subnet? machine-checked
- In IPv6, which address is the loopback address, equivalent in role to 127.0.0.1 in IPv4? machine-checked
- Which is the correct fully compressed form of the IPv6 address 2001:0db8:0000:0000:0000:ff00:0042:8329? machine-checked
- Which pairing of a service with its default port number is correct? machine-checked
- DNS normally uses UDP port 53. In which situation does a DNS client or server fall back to TCP on port 53? machine-checked