Search

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.

/etc/hosts

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.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.1.1 RHEl01.omnisecu.com RHEL01
192.168.1.105 RHEL05.omnisecu.com RHEL05
192.168.1.106 RHEL06.omnisecu.com RHEL06
192.168.1.107 RHEL07.omnisecu.com RHEL07
192.168.1.108 RHEL08.omnisecu.com RHEL08
192.168.1.109 RHEL09.omnisecu.com RHEL09

/etc/nsswitch.conf

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.

/etc/resolv.conf

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
search omnisecu.com
nameserver 192.168.1.1

Related Tutorials