Tuesday, July 27, 2010

How to setup a simple DNS Server in easy steps?

It has been long I was thinking of writing something about DNS(Domain Name Server).DNS is a database of the IP to Name and Name to IP conversion.I went through lots of tutorials related to DNS but couldnt satisfy myself unless and until I started writing commands and configuring files for the initial setup.After lot of tweaking and commandline I was able to setup a simple DNS server.

Lets travel into the world of DNS.
I have a RHEL 4 Machine ready with bind packages installed.The Minimal requirement are:

[root@localhost ~]# rpm -qa bind*
bind-libs-9.2.4-24.EL4
bind-utils-9.2.4-24.EL4
bind-9.2.4-24.EL4
bind-chroot-9.2.4-24.EL4
bind-devel-9.2.4-24.EL4
bind-libs-9.2.4-24.EL4
[root@localhost ~]#

The IP Details of my Machine are:
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:16:17:C6:BE:47
inet addr:10.14.77.33 Bcast:10.14.77.127 Mask:255.255.255.128
inet6 addr: fe80::216:17ff:fec6:be47/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:36287 errors:0 dropped:0 overruns:0 frame:0
TX packets:19141 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5408275 (5.1 MiB) TX bytes:2370680 (2.2 MiB)
Interrupt:201

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:18714 errors:0 dropped:0 overruns:0 frame:0
TX packets:18714 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:10174891 (9.7 MiB) TX bytes:10174891 (9.7 MiB)

[root@localhost ~]#

The Exact Steps I followed are mentioned Below:

1. Open a file /etc/hosts and make it look like this:


[root@localhost ~]# 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

[root@localhost ~]#

2.Edit the file /etc/resolv.conf:

[root@localhost ~]# cat /etc/resolv.conf
; generated by /sbin/dhclient-script

search tuxbuddy.logica.com
nameserver 10.14.77.33
[root@localhost ~]#

3. Run this Command:

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:16:17:C6:BE:47
ONBOOT=yes
TYPE=Ethernet
PEERDNS=no
[root@localhost ~]#

4. Follow this step:

[root@localhost etc]# pwd
/var/named/chroot/etc
[root@localhost etc]# vi named.conf

//
// named.conf for Red Hat caching-nameserver
//

options {
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
/*
* 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
//
controls {
inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};

zone "." IN {
type hint;
file "named.ca";
};

zone "tuxbuddy.logica.com" IN {
type master;
file "tuxbuddy.logica.com.zone";
allow-update { none; };
};

zone "33.77.14.10.in-addr.arpa" IN {
type master;
file "10.14.77.33.zone";
allow-update { none; };
};

zone "localhost" IN {
type master;
file "localhost.zone";
allow-update { none; };
};

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

zone "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.ip6.local";
allow-update { none; };
};

zone "255.in-addr.arpa" IN {
type master;
file "named.broadcast";
allow-update { none; };
};

zone "0.in-addr.arpa" IN {
type master;
file "named.zero";
allow-update { none; };
};

include "/etc/rndc.key";


Save the file.

5.Edit the Database Files:

[root@localhost named]# pwd
/var/named/chroot/var/named
[root@localhost named]#vi tuxbuddy.logica.com

$TTL 86400
@ IN SOA station1.tuxbuddy.logica.comroot.station1.tuxbuddy.logica.com. (
2009091100; Serial
28800 ; Refresh
14400 ; Retry
3600000 ;Expire
0 ) ; Negative

@ IN NS station1.tuxbuddy.logica.com.
@ IN A 10.14.77.33

station1.tuxbuddy.logica.com. IN A 10.14.77.33
www IN A 10.14.77.33
ftp IN A 10.14.77.33
pop IN A 10.14.77.33

www1 IN CNAME station1.tuxbuddy.logica.com.
www2 IN CNAME station2.tuxbuddy.logica.com.
www.station1.tuxbuddy.logica.com IN A 10.14.77.33
Innovation2.groupinfra.com. IN A 10.14.16.215
@ IN MX 10 station1.tuxbuddy.logica.com.
station1 IN MX 10 station1.tuxbuddy.logica.com.
~


[root@localhost named]#

6. Edit this file too:

[root@localhost named]# pwd
/var/named/chroot/var/named
[root@localhost named]#

[root@localhost named]# cat 10.14.77.33.zone
$TTL 86400
@ IN SOA station1.tuxbuddy.logica.comroot.station1.tuxbuddy.logica.com. (
4 10800 3600 604800 86400 )
IN NS station1.tuxbuddy.logica.com.
33.77.14.10.IN-ADDR.ARPA. IN PTR station1.tuxbuddy.logica.com.
[root@localhost named]#

JUST REMEMBER DONT MISS ANY . during the configuration.
DNS IS VERY SENSITIVE TO SINGLE SIGN.

Thats ALL !!!

YOUR SIMPLE DNS SERVER IS READY.

Testing the DNS SERVER

[root@localhost named]# dig -x 10.14.77.33

; <<>> DiG 9.2.4 <<>> -x 10.14.77.33
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48322 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;33.77.14.10.in-addr.arpa. IN PTR ;; ANSWER SECTION: 33.77.14.10.in-addr.arpa. 86400 IN PTRstation1.tuxbuddy.logica.com. ;; AUTHORITY SECTION:33.77.14.10.in-addr.arpa. 86400 IN NS station1.tuxbuddy.logica.com.

;; ADDITIONAL SECTION:
station1.tuxbuddy.logica.com. 86400 IN A 10.14.77.33
;; Query time: 1 msec
;; SERVER: 10.14.77.33#53(10.14.77.33)
;; WHEN: Wed Oct 7 07:28:30 2009
;; MSG SIZE rcvd: 114

[root@localhost named]#


Just See..Your IP is resolving to Hostname and vice versa.

Other Way to see if things work or not !!

[root@localhost named]# host 10.14.77.33
33.77.14.10.in-addr.arpa domain name pointerstation1.tuxbuddy.logica.com.
[root@localhost named]#

These too,
[root@localhost named]# host www
www.tuxbuddy.logica.com has address 10.14.77.33
[root@localhost named]#