Creating DNS Server with Ubuntu Linux - Primary DNS Server with Bind9

DNS Server with BIND9
DNS Server with BIND9

Creating Primary DNS Server with Bind9

This little tutorial will go through the steps of creating a DNS (domain name system) server on your ubuntu server machine. I recently setup a dns server to host some of my internal and public domains and found many tutorials confusing or caused problems.

For this example I will go through the steps for setting up a private domain name for a private network, the instructions will apply if you have decided to host a dns server for your domain name.

The bind9 dns server was tested on ubuntu server 8.04,8.10 and 9.04

Bind9 - Configuring Zone Files

A primary master server using Bind9 is setup to serve DNS records (groups of records referred to as zones) for a fictitious domain name which is restricted to a private network.

The first step is to boot up your ubuntu server system and ensure you have root privledges

sudo su

Once in root mode you can enter the main directory for bind9 /etc/bind

The first file you will need to modify is "named.conf.local" , this file is where we will be referencing our forward and reverse zone files for your domain names.

The below code shows the basic format for your named.conf.local file inside the /etc/bind directory. it specifies the domain which in this case is ubuntu.com, classified it as a master server and specified the location of the file which will store all information relating to that zone.

The reverse zone file is your ip address backwards e.g (192.170.68.7 becomes 68.170.192)

named.conf.local

zone "ubuntu.com" {
             type master;
             file "/etc/bind/db.ubuntu.com";
        };

Reverse Zone File

zone "68.170.192.in-addr.arpa" {
        type master;
        notify no;
        file "/etc/bind/db.192";
};

Creating the (SOA) Start of Authority Record

Db.ubuntu.com domain zone files contains all the regular DNS information for a (SOA) or Start of Authority Record which defines global parameters for the zone (domain).

The db.ubuntu.com zone file contains many different values and its important to know what each does for future reference.

name - The 'root name' of the zone. Most commonly written as @ or Origin Value.

ttl - Standard TTL values apply (range 0 to 2147483647 clarified by RFC 2181). The slave (Secondary) DNS does not use the the TTL value but various parameters defined within the SOA. set by an authoritative nameserver for a particular resource record.

name-server - Any name server that will respond authoritatively for the domain.

refresh - Signed 32 bit time value in seconds. Indicates the time when the slave will try to refresh the zone from the master

retry - Signed 32 bit value in seconds. Defines the time between retries if the slave (secondary) fails to contact the master when refresh (above) has expired. Typical values would be 180 (3 minutes) to 900 (15 minutes) or higher

expiry - Signed 32 bit value in seconds. Indicates when the zone data is no longer authoritative. Used by Slave or (Secondary) servers only.

Serial - The serial value is in the format YYYYMMDDSS for example 2009101101 , year 2009 10th month 11th day serial 01, remember the serial needs to be incremented by 1 every time a change is made in order for secondary dns server/slave to registry it.

db.ubuntu.com

$TTL    604800
@       IN      SOA     ns.ubuntu.com. root.ubuntu.com. (
                              1         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns.ubuntu.com.
@       IN      A       192.170.68.7
box     IN      A       192.170.68.7

Apply changes in Bind9

Remember to restart the naming service whenever you make any changes to your zones using

/etc/init.d/bind9 restart

remember to be in root mode

The reverse zone file is also created with similar format to db.ubuntu.com

db.192

db.192

;
; BIND reverse data file for local loopback interface
;
$TTL    604800
@       IN      SOA     ns.ubuntu.com. root.ubuntu.com. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns.
10      IN      PTR     ns.ubuntu.com.

Testing and Troubleshooting

Once you have modified the files , named.conf.local, db.ubunt.com and db.192

and restarted the naming service /etc/init.d/bind9 restart

You can test your domain name but before you do that you should set your linux systems DNS resolvers to point to the dns server you just created on 192.170.68.7

open up the file /etc/resolv.conf using vim /etc/resolv.conf

and enter your domain name information

domain ubuntu.com

search ubuntu.com

nameserver 192.170.68.7

once the DNS resolvers have been setup inside /etc/resolv.conf

you can test your dns server using

ping ubuntu.com , dig ubuntu.com or named-checkzone ubuntu.com /etc/bind/db.ubuntu.com

Troubleshooting

For any trouble shooting problems first consult the system logs using ,

/var/log/syslog 
to check for errors otherwise feel free to ask questions or let me know if i've made any mistakes.

More by this Author


Comments 7 comments

psychicdog.net profile image

psychicdog.net 6 years ago

Love this kind of hub. I recently had an issue with the SOA for a Domain name - the issue prevented the domain showing up so very interesting to read this. Thanks expectus!


expectus profile image

expectus 6 years ago from Land Downunder Author

thanks for the comment psychicdog.net:), yea those DNS problems can be very frustrating and hard to pin point the cause of the problems.


drprometheus 6 years ago

You are the Man! Thank you for such a lucid and simple explantion. Exceptional...


sukieboy 6 years ago

Hey man it was a nice topic though am new to Ubuntu/Linux. Was trying to follow your steps but when I restarted my DNS server, it failed.

Actually I am trying to settup up a private domain to connect my mail service (postfix)earlier installed and maybe connect MS office outlook to it.

So can you please help show the way?


expectus profile image

expectus 6 years ago from Land Downunder Author

if the dns server fails to start it usually means the zone files are formatted incorrectly, double check formatting or post in comments so i can take a look


cosscat 5 years ago

Hello expectus. i have read and applied your tutorial. overall good info. anyway, I have some trouble seeing my site online. Here is what I get after dig cvga.ro:

; DiG 9.7.1-P2 cvga.ro

;; global options: +cmd

;; Got answer:

;; ->>HEADER


dd_vv 4 years ago

I followed your suggestion and it failed when I first tried it; looked up logs in /var/log/syslog and got an error message that of an unknown expression "Reverse" while attempting to load the named.conf.local file.

I therefore went back to the named.conf.local file and commented out the line stating Reverse:

// Reverse Zone File

Restarted bind9 and it worked like a charm. Thank you so much. I have been having issues trying to set up a dns server for a very long time using multiple resources and never came out of it with a working server. I can't thank you enough!!!

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working