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.
hosts = files,dnsIncorrect. nsswitch.conf does not use this equals-and-comma form.
nameserver: files dnsIncorrect. The database name should be hosts, not nameserver.
hosts: files dnsCorrect. 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
Network interface
A host attachment whose link state and addresses can be managed.
Connection profile
Saved settings used to activate a persistent network connection.
Routing table
Rules that select the next hop for each destination network.