Concepts / Names and DNS

Names and DNS

Hosts file

Also called /etc/hosts, nsswitch, getent

A local list of names and addresses, consulted before DNS on most systems.

The hosts file is read before DNS
The hosts file is read before DNS

A program looks in /etc/hosts first and asks DNS only when the file has no match. dig skips the file, so it can disagree with what programs get.

The hosts file (/etc/hosts) is a local list of names and their addresses that a machine reads before it asks DNS. The line hosts: files dns in /etc/nsswitch.conf sets that order. Programs follow it; dig does not, because it asks DNS directly. getent hosts name shows the address programs really get.

See it on real machines

Read next

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start learning