Creating DNS Server with Ubuntu Linux - Primary 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.