«

»

Nov 04

Domain Name System (DNS) Setting Step by Step

(Note: Here I am Describing DNS Setting in FreeBSD. I hope this tutorial is helpful for Linux and other BSD distribution. )
FreeBSD utilizes, by default, a version of BIND (Berkeley Internet Name Domain), which is the most common implementation of the DNS protocol. DNS is the protocol through which names are mapped to IP addresses, and vice versa. For example, a query for www.drpaudel.com.np will receive a reply with the IP address of my blog server, whereas, a query for ftp.drpaudel.com.np will return the IP address of the corresponding FTP machine. Likewise, the opposite can happen. A query for an IP address can resolve its hostname. It is not necessary to run a name server to perform DNS lookups on a system.

Starting BIND

The default named configuration is that of a basic resolving name server, running in a chroot environment, and restricted to listening on the local IPv4 loopback address (127.0.0.1). To start the server one time with this configuration, use the following command:

# /etc/rc.d/named onestart
To ensure the named daemon is started at boot each time, put the following line into the /etc/rc.conf:

named_enable=”YES”

There are obviously many configuration options for /etc/namedb/named.conf that are beyond the scope of this document. However, if you are interested in the startup options for named on FreeBSD, take a look at the named_* flags in /etc/defaults/rc.conf and consult the rc.conf(5) manual page. The Section 12.7 section is also a good read.

Configuration Files

Configuration files for named currently reside in /etc/namedb directory and will need modification before use unless all that is needed is a simple resolver. This is where most of the configuration will be performed.
/var/named/etc/namedb/named.conf

options {
directory “/etc/namedb”;
pid-file “/var/run/named/pid”;
dump-file “/var/dump/named_dump.db”;
statistics-file “/var/stats/named.stats”;
allow-update {key rndc;};
}; 

zone “.”{
type hint;
file “named.root”;
};

zone “pc1f018.wakhok.ac.jp” {
type master;
file “master/pc1f018.wakhok.ac.jp.zone”;
};

zone “0.168.192.in-addr.arpa” {
type master;
file “master/pc1f018.wakhok.ac.jp.rev”;

};

zone “0.0.168.192.in-addr.arpa” {

type master;
file “master/pc1f018.wakhok.ac.jp.del”;

};

zone “localhost” {
type master;
file “master/localhost.zone”;
};

zone “0.0.127.in-addr.arpa” {
type master;
file “master/localhost.rev”;
};

# You don’t need to write rndc-key as you will generate and write later in this file.
key “rndc-key” {
algorithm hmac-md5;
secret “IZKpqlIsx87wJrjoc8vTbA==”;
};

/var/named/etc/namedb/master/pc1f018.wakhok.ac.jp.rev

$TTL 86400
@ IN SOA ns1.pc1f018.wakhok.ac.jp. postmaster.pc1f018.wakhok.ac.jp. (
2011102812
10800
3600
604800
86400

IN NS ns1.pc1f018.wakhok.ac.jp.

2 IN PTR ns1.pc1f018.wakhok.ac.jp.
3 IN PTR www.pc1f018.wakhok.ac.jp.
4 IN PTR mail.pc1f018.wakhok.ac.jp.
5 IN PTR drpaudel.pc1f018.wakhok.ac.jp.

/var/named/etc/namedb/master/pc1f018.wakhok.ac.jp.del

$TTL 86400
@ IN SOA ns1.pc1f018.wakhok.ac.jp. postmaster.pc1f018.wakhok.ac.jp. (
2011102810
10800
3600
604800
86400
)
IN NS ns1.pc1f018.wakhok.ac.jp. 

2 IN PTR ns1.pc1f018.wakhok.ac.jp.
3 IN PTR www.pc1f018.wakhok.ac.jp.
4 IN PTR mail.pc1f018.wakhok.ac.jp.

/var/named/etc/namedb/master/localhost.zone

$TTL 60800
@ IN SOA ns1.pc1f018.wakhok.ac.jp. postmaster.pc1f018.wakhok.ac.jp. (
2011102810
28800
3600
129600
3600

IN NS ns1.pc1f018.wakhok.ac.jp.

localhost. IN A 127.0.0.1

/var/named/etc/namedb/master/localhost.rev

$TTL 60800
@ IN SOA ns1.pc1f018.wakhok.ac.jp. postmaster.pc1f018.wakhok.ac.jp. (
2011102810
28800
3600
129600
3600

IN NS ns1.pc1f018.wakhok.ac.jp.

1 IN PTR localhost

Enable named in rc.conf by

named_enable=”YES”

The /etc/rc.conf file is in my case is as below.

# — sysinstall generated deltas — # Wed Nov 2 17:47:31 2011
# Created: Wed Nov 2 17:47:31 2011
# Enable network daemons for user convenience.
# Please make all changes to this file, not to /etc/defaults/rc.conf.
# This file now contains just the overrides from /etc/defaults/rc.conf.
hostname=”pc1f018.wakhok.ac.jp”
#ifconfig_em0=”DHCP”
ifconfig_sk0=”inet 192.168.0.1/24″
keymap=”jp.106″
sshd_enable=”YES”
named_enable=”YES”


Create rndc-key by following command

/usr/sbin/rndc-confgen -a -r keyboard

Start typing whatever you like until it says stop typing

send your key to name.conf by following command. First you must go to /etc/namedb

cat rndc.key >> named.conf

Restart named by following Command

/etc/rc.d/named restart < br /> or
/etc/rc.d/named stop< br /> /etc/rc.d/named start

It may give following error

named: the working directory is not writable

To fix this error, edit the following file:

/etc/mtree/BIND.chroot.dist

Change:

/set type=dir uname=root gname=wheel mode=0755

into:

/set type=dir uname=bind gname=wheel mode=0755

Then restart bind:

/etc/rc.d/named restart

Change ownership for named

# chown -R bind /var/named

Now You will must see the success reply

# /etc/rc.d/named start
. changed
user expected 0 found 53 modified
etc changed
user expected 0 found 53 modified
etc/namedb changed
user expected 0 found 53 modified
etc/namedb/master changed
user expected 0 found 53 modified
var changed
user expected 0 found 53 modified
Starting named.

Now you can dig using following command.

dig @192.168.0.1 drpaudel.pc1f018.wakhok.ac.jp A

You must get Query: 1, Answer :1 …………..

Also, do nslookup

nslookup drpaudel.pc1f018.wakhok.ac.jp

You will get server and Nameserver Host and IP.

Cheers !!

Leave a Reply