Monday, January 09, 2006

How DNS Works

DNS - Domain Name System is used to resolve domain name like sriram.com to IP - 10.10.93.x.

Rules of DNS

The Rules as Defined in (RFC 952)

Names can be up to 24 Characters long
Names should be more than 1 character long
Names may contain letters, numbers, dashes and dots.
Names Should start with a letter
Names should not end with a dash or dot.

Levels

First Level -

The root of a domain name system is represented by a dot ( . )

Root - This is Managed by Internic

There are 14 root servers around the world mentioned in /var/named/named.ca

Second Level -

Second Level Domain name is Managed by Registrars like ( .net, .com, .org, .us)

Third Level -

Third level Domain are managed by whomever registers them through Registrars for eg. (sriram.com)

Some Important Files

Bind - The Utility for DNS

Files

/etc/named.conf

This is the main configuration file where you add the Master, Slave servers.

Master Server - Primary Name Server.

Slave Server - Secondary Name Server.

In Case the Master Fails then Slave resolves.

/var/named - Default place where zone files are stored.

eg.
[root@mybox named]# cat sriram.com.hosts
$ttl 38400
sriram.com. IN SOA mybox.sriram.com. sriram.gmail.com. (
1136737633
10800
3600
604800
38400 )
sriram.com. IN NS mybox.sriram.com.
windows.sriram.com. IN A 192.168.0.20
linux.sriram.com. IN A 10.10.93.220

Note the above lines should be seperated by way of Tab


/var/named/named.ca

Hint file (cache file)(/var/named/named.ca): It actually provides the name of root server which gets activated in case the machine name, which is to be searched, is not there in user defined zone (discussed below).

The copy of same can be obatined from internic... Very rarely it changes

localhost file (/var/named.local): All configuration have a local domain Database for resolving address to the host name localhost.

Zone: Basically a zone that keeps the information about the domain database

Reverse Zone file: This is responsible for mapping Ipaddress to host names, which is exactly the opposite of what the zone file does.

In previous post I have given complete configuration of DNS on LINUX



Configuring DNS on linux for your LAN Network

How to Configure a DNS

Files You will need to edit to configure a Local DNS on your Lan's are:

/etc/resolv.conf

/etc/host.conf

/etc/named.conf

and you need to create a zone file.

For Eg. /var/named/sriram.com.hosts.

Let me tell Scenario,

I have VMware running on my linux host and Guest OS as Windows Pro 2k

Networking I have used as a Bridged Network.

Ip Address in Linux Host - 10.10.93.x

Ip Address in Windows Guest - 192.168.0.x

Both are 32 Bit Mask.

I have added the gateway and DNS in Windows Guest as 10.10.93.x (Linux Host IP)

Now all I need is :

windows.sriram.com should ping to 192.168.0.x - Win2k Pro

linux.sriram.com should ping to 10.10.93.x - Linux

I am Pasting Below the configuration I have in the above 4 Files.

File 1

/etc/resolv.conf

[root@mybox named]# cat /etc/resolv.conf
#nameserver 202.144.115.4
#nameserver 202.144.66.6
#nameserver 10.10.93.220

nameserver 10.10.93.220

Since it should resolve sriram.com internally I am using My own DNS.

Rest of the DNS Entry I have Hashed.


File 2

/etc/host.conf

[root@mybox named]# cat /etc/host.conf
#order hosts,bind
order bind,hosts
multi on
nospoof on

The order in which you want to resolve. You need to give first preference to bind than to the host file.


File 3

/etc/named.conf

[root@mybox named]# cat /etc/named.conf
// generated by named-bootconf.pl


// secret must be the same as in /etc/rndc.conf
key "key" {
algorithm hmac-md5;
secret
"c3Ryb25nIGVub3VnaCBmb3IgYSBtYW4gYnV0IG1hZGUgZm9yIGEgd29tYW4K";
};

controls {
inet 127.0.0.1 allow { any; } keys { "key"; };
};


options {
pid-file "/var/run/named/named.pid";
directory "/var/named";
/*
* If there is a firewall between you and nameservers you want
* to talk to, you might need to uncomment the query-source
* directive below. Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
// query-source address * port 53;
};

//
// a caching only nameserver config
//
zone "." {
type hint;
file "named.ca";
};

zone "0.0.127.in-addr.arpa" {
type master;
file "named.local";
};


// workaround stupid stuff... (OE: Wed 17 Sep 2003)
zone "ac" { type delegation-only; };
zone "cc" { type delegation-only; };
zone "com" { type delegation-only; };
zone "cx" { type delegation-only; };
zone "museum" { type delegation-only; };
zone "net" { type delegation-only; };
zone "nu" { type delegation-only; };
zone "ph" { type delegation-only; };
zone "sh" { type delegation-only; };
zone "tm" { type delegation-only; };
zone "ws" { type delegation-only; };

zone "sriram.com" {
type master;
file "/var/named/sriram.com.hosts";
};

[root@mybox named]#

I have added the last 4 lines Mentioned in the file.

File 4

Lastly I have Created a Zone file :

/var/named/sriram.com.hosts

[root@mybox named]# cat sriram.com.hosts
$ttl 38400
sriram.com. IN SOA mybox.sriram.com. sriram.gmail.com. (
1136737633
10800
3600
604800
38400 )
sriram.com. IN NS mybox.sriram.com.
windows.sriram.com. IN A 192.168.0.20
linux.sriram.com. IN A 10.10.93.220

Now Reload named, for changes to take effect.

/etc/rc.d/init.d/named reload

Thats it,

[root@mybox named]# ping linux.sriram.com
PING linux.sriram.com (10.10.93.220) 56(84) bytes of data.
64 bytes from mybox.sriram.com (10.10.93.220): icmp_seq=1 ttl=64 time=0.037 ms

[root@mybox named]# ping windows.sriram.com
PING windows.sriram.com (192.168.0.20) 56(84) bytes of data.
64 bytes from 192.168.0.20: icmp_seq=1 ttl=128 time=1.24 ms

If you are finding it difficult to add these entries, than you may try Webmin.

Relatively Webmin is much simple to configure.

In this example I have not talked about Slave, Since we are configuring this in a very small environment Slave is not needed, rather we would take the backup of the files.