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.
Incorrect. It checks files before DNS.
dns: hosts filesIncorrect. The database name must be hosts.
Incorrect. The database name must be hosts.
hosts=dns,filesIncorrect. nsswitch.conf does not use equals and comma syntax.
Incorrect. nsswitch.conf does not use equals and comma syntax.
hosts: dns filesCorrect. It places DNS before files.
Correct. 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
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.