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.
getent passwd app01Incorrect. passwd searches user accounts.
getent services app01Incorrect. services searches service names and ports.
getent networks app01Incorrect. 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
getent
A command that resolves a system database through the configured NSS sources.
hosts database
The NSS database containing host names and address mappings.
passwd database
The NSS database containing user-account records, not host mappings.