Check how the current NSS configuration resolves alias app01 from /etc/hosts.
Do not grep the file directly.
Which command is appropriate?
getent hosts NAME queries the hosts database through the configured NSS sources and order, making it closer to actual name-resolution behavior than grep.
Detailed explanation
getent hosts app01Correct. It asks NSS to resolve app01 through the hosts database.
Correct. It asks NSS to resolve app01 through the hosts database.
getent passwd app01Incorrect. passwd searches user accounts.
Incorrect. passwd searches user accounts.
getent services app01Incorrect. services searches service names and ports.
Incorrect. services searches service names and ports.
getent networks app01Incorrect. networks searches network-name data.
Incorrect. networks searches network-name data.
Try it yourself
An example you can run in a temporary verification environment.
getent hosts localhostExpected result
localhostに対応するIPv4またはIPv6アドレスと名前Key points
- hosts database
- Reflects NSS ordering
- Closer to actual resolution
Notes
- Environment: glibc 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.