| Article Index |
|---|
| DNS resolution explained |
| Part 2 - Basic Dns Guide |
| All Pages |
DNS resolution is an important backbone to all name based network activities. Gain a good understand of DNS resolution on Unix by reading this article.
The article explains about Linux and Unix dns resolution, the config files involved and the common configurations and common problems / solutions reported by users.
The main related config files on most types of Linux and Unix are:
/etc/hosts file, /etc/resolv.conf file, /etc/nsswitch.conf file
Depending on the version and distribution more files maybe involved, but these files represent the corner stone of the configuration in terms of which files are processed and in which order they are used.
Basic example /etc/hosts file ( IPV4 based )
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.1.10 black
192.168.1.130 bigmac
Basic example /etc/resolv.conf file
nameserver 192.168.1.1
Basic example /etc/nsswitch.conf
[sshtest@littlemac ~]$ cat /etc/nsswitch.conf
#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
# Legal entries are:
#
# nisplus or nis+ Use NIS+ (NIS version 3)
# nis or yp Use NIS (NIS version 2), also called YP
# dns Use DNS (Domain Name Service)
# files Use the local files
# db Use the local database (.db) files
# compat Use NIS on compat mode
# hesiod Use Hesiod for user lookups
# [NOTFOUND=return] Stop searching if not found so far
#
# To use db, put the "db" in front of "files" for entries you want to be
# looked up first in the databases
#
# Example:
#passwd: db files nisplus nis
#shadow: db files nisplus nis
#group: db files nisplus nis
passwd: files
shadow: files
group: files
#hosts: db files nisplus nis dns
hosts: files dns
# Example - obey only what nisplus tells us...
#services: nisplus [NOTFOUND=return] files
#networks: nisplus [NOTFOUND=return] files
#protocols: nisplus [NOTFOUND=return] files
#rpc: nisplus [NOTFOUND=return] files
#ethers: nisplus [NOTFOUND=return] files
#netmasks: nisplus [NOTFOUND=return] files
bootparams: nisplus [NOTFOUND=return] files
ethers: files
netmasks: files
networks: files
protocols: files
rpc: files
services: files
netgroup: nisplus
publickey: nisplus
automount: files nisplus
aliases: files nisplus
The nsswitch.conf file is used for much more than just storing the configuration order of DNS resolution, but for this example this is the only aspect we are interested in.
Notice the lines:
#hosts: db files nisplus nis dns
hosts: files dns
The upper line is commented with the hash character '#' so it not actually active, but serves to remind of the available options.
This is known as commenting a line ( starting the line with a hash causes it to be skipped in the config and treated as a comment )
The lower line sets the DNS resolution order on this Linux system, specifying that it will look at files ( meaning the hosts file ) , and then dns in order to resolve a dns name request. Here is a practicle example of how this works in every day use
[sshtest@littlemac ~]$ ping black
PING black (192.168.1.10) 56(84) bytes of data.
--- black ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1009ms
[sshtest@littlemac ~]$ ping black.com
PING black.com (208.122.60.250) 56(84) bytes of data.
64 bytes from server3.fkmod.com (208.122.60.250): icmp_seq=1 ttl=52 time=87.5 ms
In this example ( and using the above example files ) , the first ping command shows that the host black is resolved by looking at the local /etc/hosts file. It also just so happens that the server black is down, and not responding, so I am 100% assured by the result.
The second part demonstrates that while the host black was featured in the /etc/hosts file, black.com is not present in the hosts file, so the resolution came from dns as configured in the /etc/nsswitch.conf file.
There is a further twist in the story of the basic config files, as we look at the role of the /etc/resolv.conf file





