How DNS works on Linux
Whenever
we contact a server by its name whether by ping, browsing for example, this is
what happens.
Ping www.google.com
The
resolver’s libraries get invoked (Resolvers are just C libraries, which look up
IP addresses and map them to names). These libraries read the configuration
files /etc/hosts.conf (older Linux) or
/etc/nsswitch.conf (newer Linux) each
time they are called.
Depending
on how these libraries - /etc/hosts.conf and /etc/nsswitch.conf - are configured, the resolvers will choose to use /etc/hosts FILE, DNS or NIS for mapping IPs to names.
My
Linux servers use the new glibc, so the configuration file they will check is the /etc/nsswitch.confm see
a snippet of this file below:
# hosts: db files nisplus nis dns
hosts: files dns
This is telling us:
Check first /etc/hosts file. If the address is
not found on the /etc/hosts file, check DNS.
If DNS is requested, another
configuration file gets read: /etc/resolv.conf. The /etc/resolv.conf should be set with the nameservers for the
network. See an example below:
# cat /etc/resolv.conf
domain adlinux.int
search adlinux.int
nameserver 192.168.1.22
The resolver’s libraries will extract
the ‘nameserver’ from the resolv.conf file and query them, to map www.google.com to its IP address.
The nameserver
in turn, if authoritative for the DNS zone where www.google.com resides, will look the name up in
its own database and return Google’s IP. If the nameserver is
not authoritative for the zone, which is most
likely, then it will return another IP for another nameserver,
which can resolve .com.
Then the .com nameservers will be queried and they will look up in their own
databases, and return an IP address for the authoritative nameserver for google.com domain.
Another query will be initiated to the
google.com authoritative DNS server, and this time, it will look in its own
database and find an IP address which matches a host named www.
Guys, this is the first version of this post. I will try and correct the mistakes and improve it.
This should give you a good idea how names are resolved on Linux.
I hope it will be useful to you
by Renato de Oliveira
No comments:
Post a Comment