Share This:

Okay so we have spent quite some with our LAMP Server. Now lets setup some DNS so we can offer subdomains using CNAMES, A Records and AAAA Records. We will also want to have our own Name Servers and MX Records for mail. All of these things are part of the DNS. Which means we will need to setup our server to act as a DNS server.

Their are several programs for setting up a DNS server. But we will most likely want to use the most common one. This program is called BIND. And I will say this right now. It is very complex to get the hang of. I truly hate it. But I’m forced to use it like 90% of everyone else that runs a DNS server.

Setting Up BIND

Before anything we will need to first install the proper programs. In the post we will be using Fedora. I however have tested this on Fedora and Cent OS and they are pretty much the same. To install the software type the following commands as a root user.





yum install bind bind-libs bind-utils caching-nameserver -y

After installing BIND we will have new directory located in the /var directory. The directory will be called named. To check to see if the named directory is their we can use the following commands.


ls -l /var

Or we can use the following commands.


cd /var
dir

If you see the named directory inside of the /var directory then we can continue. This is where we will need to make our Zone file. But before we make our Zone file we will need to get some information. So first we will type the following commands.


awk 'NR==3 {print substr($0,1,14)}' /etc/hosts

Once we find out our IP address we will write it down so we remember it.

Now we will need a text editor. I usually prefer nano so in the next example I will use nano to create the Zone file.




So now we will type the following commands as root.


nano /var/named/mywebsite.com.db


Please keep in mind that mywebsite.com.db should be replaced with the another name with the .db extension.

Nano should open up a blank page for us to add content to. This is where we will add our bind configuration info. We will add the following.


$TTL 14400
@ 86400 IN SOA ns1.mywebsite.com. yourname.mywebsite.com. (
2012061201 ; serial, todays date+todays
86400 ; refresh, seconds
7200 ; retry, seconds
3600000 ; expire, seconds
86400 ) ; minimum, seconds
mywebsite.com. 86400 IN NS ns1.mywebsite.com.
mywebsite.com. 86400 IN NS ns2.mywebsite.com.
ns1 IN A XXX.XXX.XXX.XX
ns2 IN A XXX.XXX.XXX.XX
mywebsite.com. IN A XXX.XXX.XXX.XX
localhost.mywebsite.com. IN A 127.0.0.1
mywebsite.com. IN MX 0 mywebsite.com.
mail IN CNAME mywebsite.com.
www IN CNAME mywebsite.com.
ftp IN A XXX.XXX.XXX.XX


Please note that where you see XXX.XXX.XXX.XX in the file it should be replaced with your servers IP address. And where you see mywebsite.com. replace it with your domain name followed by a period.

Once we have added our configuration info into Nano we will save it. To do this we will press CTRL + X. This will ask us if we want to save the file. We say yes. Then Nano will close.

Now we will need to start the BIND service. To do this we will type the following commands.


service named start

You should be all done.  Everything should work. However you will also need to go to the place where you registered your domain name and create the proper records to point to your server. These updates usually take up to 48 hours. So be patent before you just give up. I’ve added some same BIND files for you to look at.

Here is the Sample BIND configuration file.