Resolve names by checking /etc/hosts first and DNS second.
Choose the hosts line in /etc/nsswitch.conf.
Which line is appropriate?
nsswitch.conf lists sources from left to right. hosts: files dns checks /etc/hosts before DNS.
Detailed explanation
hosts: dns filesIncorrect. It checks DNS before local files.
Incorrect. It checks DNS before local files.
hosts = files,dnsIncorrect. nsswitch.conf does not use this equals-and-comma form.
Incorrect. nsswitch.conf does not use this equals-and-comma form.
nameserver: files dnsIncorrect. The database name should be hosts, not nameserver.
Incorrect. The database name should be hosts, not nameserver.
hosts: files dnsCorrect. files is tried before dns.
Correct. files is tried before dns.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s
' 'hosts: files dns' | awk -F: '{print $1 ":" $2}'Expected result
hosts: files dnsKey points
- hosts is the name-resolution database
- files means /etc/hosts
- Sources are tried left to right
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.