Why is DNS important?
DNS is like a phone book for the Internet. If you know a person’s name but don’t know their telephone number, you can simply look it up in a phone book. DNS provides this same service to the Internet.
When you visit http://facebook.com in a browser, your computer uses DNS to retrieve the website’s IP address of 22.214.171.124. Without DNS, you would only be able to visit our website (or any website) by visiting its IP address directly, such as http://126.96.36.199.
rupin@L687:~$ ping facebook.com PING facebook.com (188.8.131.52) 56(84) bytes of data. 64 bytes from edge-star-mini-shv-01-iad3.facebook.com (184.108.40.206): icmp_seq=1 ttl=42 time=347 ms
When a linux computer looks for another computer IP it looks for the information in two files : /etc/hosts and /etc/resolv.conf. The order in which the files are consulted is configured on /etc/nsswitch.conf:
$ cat /etc/nsswitch.conf
Search first on files (/etc/hosts) and then on dns (/etc/resolv.conf).
This file is a simple database that relates a numeric IP with a hostname. It can be edited as a normal file with ‘vi’ command in order to add more information.
# cat /etc/hosts 127.0.0.1 localhost.localdomain localhost 192.168.1.1 rupin.server.com server
The first line maps the 127.0.0.1 IP to the hostnames localhost, short hostname, and localhost.localdomain, FQHN hostname. The second line maps the 192.168.1.1 IP to server and rupin.server.com hostname.
In order to configure a linux computer as a DNS client the file /etc/resolv.conf must be used.
# cat /etc/resolv.conf search info.net nameserver 192.168.1.1
In this case all DNS queries launched from the computer will be addressed to the nameserver on 192.168.1.1. If a short hostname is provided it will be complemented automatically with ‘info.net’ domain.
Note: By default if a DNS query is done and can be answered from /etc/hosts the nameserver configured on /etc/resolv.conf is not consulted. Only the information obtained from /etc/hosts is taken as valid.