Linux Domain Name System (DNS) client configuration files /etc/hosts, /etc/nsswitch.conf and /etc/resolv.conf

There are three main client configuration files associated with DNS: /etc/hosts, /etc/nsswitch.conf and /etc/resolv.conf. When your computer looks for another computer on a TCP/IP network such as the Internet, it typically looks in two places: /etc/hosts and any DNS servers that you've set up for your network.


The /etc/hosts file keeps a local name database. This file helps in local name resolution if your local DNS server is not functioning. Network adinistrators should manually populate entries in this file. A sample /etc/hosts file is copied below.

[root@RHEL01 ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail. localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6 RHEL01 RHEL05 RHEL06 RHEL07 RHEL08 RHEL09


The order of name resolution process is determined by a single line in /etc/nsswitch.conf:

hosts: files,dns

In this case, the name resolution process will begin with checking /etc/hosts file, and if the name cannot be resolved, the name resolution will happen with the DNS server.


The /etc/resolv.conf file contains directives with the IP addresses of nameservers available to a host. A sample /etc/resolv.conf file is copied below.

[root@RHEL01 ~]# cat /etc/resolv.conf

Related Tutorials