Resolve app.example.test according to the hosts database configuration in /etc/nsswitch.conf.
Use the configured files and DNS order rather than querying DNS directly.
Which command is appropriate?
getent hosts NAME searches the NSS hosts database and follows the service order configured in nsswitch.conf.
Detailed explanation
getent hosts app.example.testCorrect. It searches the NSS hosts database.
Correct. It searches the NSS hosts database.
dig app.example.test AIncorrect. dig sends a DNS query directly and does not follow local files order.
Incorrect. dig sends a DNS query directly and does not follow local files order.
grep app.example.test /etc/resolv.confIncorrect. It only searches a resolver configuration file and does not resolve the name.
Incorrect. It only searches a resolver configuration file and does not resolve the name.
hostname app.example.testIncorrect. hostname manages the local hostname rather than querying the NSS database.
Incorrect. hostname manages the local hostname rather than querying the NSS database.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s
' 'getent hosts NAME -> NSS hosts database lookup'Expected result
getent hosts NAME -> NSS hosts database lookupKey points
- getent uses NSS
- Use the hosts database
- Different path from dig
Notes
- Environment: getent動作対応表(名前解決なし)
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.