Change name resolution so DNS is consulted first and /etc/hosts second.
Choose the hosts line in /etc/nsswitch.conf.
Which line is appropriate?
nsswitch sources are evaluated left to right. hosts: dns files consults DNS before the local hosts file.
Detailed explanation
hosts: files dnsIncorrect. It checks files before DNS.
dns: hosts filesIncorrect. The database name must be hosts.
hosts=dns,filesIncorrect. nsswitch.conf does not use equals and comma syntax.
hosts: dns filesCorrect. It places DNS before files.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s
' 'hosts: dns files' | awk -F: '{print $2}'Expected result
dns filesKey points
- Sources are tried left to right
- dns means resolver lookup
- files means /etc/hosts
Notes
- Environment: POSIX awk / 一時標準入力のみ
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
/etc/nsswitch.conf
The file that defines lookup sources and their order for system databases.
hosts database
The NSS database used for host-name and address resolution.
Source order
The left-to-right order in which configured lookup sources are tried.