We, humans, are good at names while computers require IP numbers to communicate. To help us with that DNS comes to our rescue. BIND is open-source software that implements the Domain Name System (DNS) protocols for the Internet. The name BIND stands for “Berkeley Internet Name Domain”, because the software originated at the University of California at Berkeley. BIND is by far the most widely used DNS software on the Internet. In this tutorial I will show you how to set up simple but complete DNS system on Red Hat or Centos.
First we need to install Bind9
yum -y install bind
After installing Bind we need to configure it. Bind9 on Red Hat and Centos provide sample configuration files but we will create them from scratch. Bind9, by default, look for named.conf file in /etc. In named.conf file, zones data files directory location and zone names are specified. Domain names like linuxgravity.com and zones are synonymous. In this tutorial, I will take linuxgarvity.com as an example. You can substitute it with the domain name you want Bind9 to configure for.
The following is the minimalist named.conf. You can copy and paste it with ctrl+shift+v after typing in
nano /etc/named.conf
and then save by pressing ctrl+w , enter and y.
options
{
directory "/var/named"; // the default
};
zone "localhost" {
type master;
file "localhost.zone";
};
zone "linuxgravity.com" {
type master;
file "linuxgravity.com.db";
};
Let’s explain what all this means. directory specifies the data files or zones files that Bind9 will search for. Then we have a zone “localhost ” defined which is of type “master” and the name of the zone file is “localhost.zone”. This zone is needed otherwise our DNS will send queries to the root domains even for localhost. Similarly, we have defined another zone called “linuxgravity.com” which is of type “master” and whose zone file, “”linuxgravity.com.db, is located in /var/named/.
We will just copy the sample localhost zone file supplied with Bind9 installation and not create it from scratch. To do that type the following:
cp /usr/share/doc/bind-9.3.4/sample/var/named/localhost.zone /var/named/
localhost.conf looks like this
$TTL 86400
@ IN SOA @ root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS @
IN A 127.0.0.1
IN AAAA ::1
Now we have to set up our linuxgravity.com zone. According to our /etc/named.conf file, it must be in /var/named/linuxgravity.com so go ahead and copy the following code, do
nano /var/named/linuxgravity.com
paste it there and then save it.
$TTL 1H
@ IN SOA ns1.linuxgravity.com. root (
2009091114 ; serial
1H ; refresh
15M ; retry
4W ; expire
1H ; Negative caching TTL of 1 hour
)
; Name servers
IN NS ns1.linuxgravity.com.
ns1 IN A 192.168.2.11
www IN A 192.168.2.50
ftp IN A 192.168.2.100
The first line shows default TTL for records when no ttl is defined.
The @ symbol represents our zone name which is linuxgravity.com in our case and we are saying that for linuxgravity.com SOA (Start of authority), authoritative DNS is ns1.linuxgravity.com and contact email is admin@linuxgravity.com (no, that is not a typo. In Bind parlance we have . instead of @ in email addresses).
The next entries are used by slave DNS servers. Whenever Serial number is incremented the slave DNSes will know that zone data has changed and will download it. Every hour slave will check with this master server to see if zone data has been changed by looking at serial number.
If, for some reasons, it cannot contact master, then it will retry every 15 minutes until 4 weeks has passed. When that happens and slave is still unable to contact master, it will expire the zone data and will stop answering name resolution queries for this zone.
Next is negative caching TTL. This is how long a remote name server can cache negative responses about the zone. These are answers that say that a particular domain name or the type of data sought for a particular domain name doesn’t exist.
Next are different record types. First is NS, name server type. Names server for our zones is defined here which we have only one here (at least two name servers are required for internet domains). Next we have an A record type (name to IP mapping) for our authoritative dns server. We have to set this record because if our DNS server name cannot be resolved, how come someone could contact it for name resolutions of other hosts.
Note that we have mentioned only ns1 and the zone name is appended to it because it does not end in a dot (.).
Next we have A records for ftp.linuxgravity.com.
And we are finished with configuring DNS for our zone.
Start DNS server
service named start
To test if it works either use dig and specify the DNS server to use for name resolution like
dig @ns1.linuxgravity.com localhost
or change /etc/resolv.conf and put the IP of our configured DNS server. Then type in
dig ftp.linuxgravity.com
host and nslookup can also be used to test name resolution.
dig ftp.linuxgravity.com
and the dig will append linuxgravity.com and look for ftp.linuxgravity.com.
Please tuned in for the next upcoming tutorials where I will show you advanced configuration of Bind9 such as configuring master and slave zones, views, use of different records types and much more…
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=b9aa6003-5d65-411d-8432-f0fa629f6f9a)

















Thanks for the info i will try it.
Its not working, can you recheck please with the file names and values? So urgent it was, and it doesnt work like all other website..
Thank you for your close look and fix.
It’s very urgent for me as well. So instead of muddling through it myself, “AGAIN” I copied this tutorial verbatim.”except for the NANO stuff,” Changed the domain names to mine. Changed the IP’s “if you missed that one you need lot’s of help” and I’m back up in five minutes instead of hours.
Thanks,
Pete G
P.S. I do think you should have gone ahead for those who need it and explicitly stated the changes needed, “IP and Domain” etc.
Also your stated use of NANO is totally unclear. I don’t use NANO but I copied your text with highlight and copy and pasted into a clean file in VI.
[root@posocity named]# service named start
After service named start:
Starting named:
Error in named configuration:
zone localhost/IN: loaded serial 42
zone mydomain.com/IN: loading master file mydomain.com.db: file not found
_default/mydomain.com/IN: file not found
how to create db file for my domain?
Thanks
You are getting error since mydomain.com.db file does not exist. This probably occured since this tutorial has a typo error.
The tutorial tell you to do “nano /var/named/linuxgravity.com” and create this new file. But the filename is wrong. It should be “nano /var/named/linuxgravity.com.db”. In your case, you should do “nano /var/named/mydomain.com.db”.
This should fix your problem and good luck.