Welcome to the first of a number of DNS related articles I will write to help explain the different tasks needed to configure and manage your own DNS server using bind under Linux.
The article assumes you have already installed bind and it is all running. If not, then you will need to setup bind first. Once you have setup bind, you are now ready to create DNS record for subdomain. You can also checkout my next article (which is more of a prequel) about adding Adding New Zone To Bind DNS Server.
What is a DNS Zone?
Essentially a zone in DNS terms is a domain along with all it’s subdomains. Typically you will have one zone config file per domain (which includes its subdomains and any mail records, alias’ and other entries associated with that domain) however you can also have multiple domains using a single zone file. If you have multiple domains to a zone file, each of those domains will be configured identically which includes the IP addresses and subdomains each of the entries point to. The zone file tells the DNS server what IP addresses are associated to each of the domains and subdomains. Each record in the zone file can also be configured to be any type of DNS record such as A record, MX record, TXT record, etc.
Editing a zone file
The zone files are located under /etc/bind/ and the zone files generally (but not always) are in the format of db.domain.com.conf. For example, my zone file for darian-brown.com is under:
So now we simply edit the zone file using vi or your preferred editor
sudo vi /etc/bind/db.darian-brown.com.conf
Create DNS Record For Subdomain
In your zone file you will see a couple existing DNS records. You should see a section similar to this where 192.168.0.2 is the IP address on our internal network where these domains point to. The @ symbol simply means the current domain which in our case is darian-brown.com
@ IN A 192.168.0.2
www IN A 192.168.0.2
Now we are going to add a subdomain called blog and point it to a different server. So we add the line after those two entries (or even at the bottom of the file) like so.
@ IN A 192.168.0.2
www IN A 192.168.0.2
blog IN A 192.168.0.10
Update Config File Serial
You need to update the serial in the zone config file. Change it so the serial number is higher than it used to be. This will allow bind to see that the config file has been updated and that it need to load in the new config file.
@ IN SOA ns1.exampledns.com. root.example.com. (
2014082301 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
43200 ) ; Negative Cache TTL
I like to use the current date for the serial and a two digit to show the number of times it edited the file that day. This ensures the serial is unique, always higher and has the added benefit of showing when I last updated the config file. So use the format of YYYYMMDDXX where xx is the edit that day. Starting at 01 for the first edit, 02 for the second edit, etc.
Save And Restart Bind DNS Server
Once you have added your new subdomain and updated the serial in your DNS config file, you need to restart the bind daemon in order to reload the new config file. You can do so by issuing the following command.
Debian / Ubuntu Linux
Restart bind dns server on Debian and Ubuntu Linux.
service bind9 start
Alternate method to restart bind dns server on Debian and Ubuntu Linux.
Redhat / Fedora Linux
Restart bind dns server on Redhat and Fedora Linux.
service named restart
Alternate method to restart bind dns server on Redhat and Fedora Linux.
Note: you may need to use sudo to run these commands if your account doesn’t have enough privileges.
Testing new subdomain
In order to test your new entry is working, you can dig the new address. See my article on What is Dig and When Should I use it for more information. Dig is a lot more informative and can be extremely useful as you can directly query your DNS server rather than waiting for the DNS to refresh.
An example of how to do would be
dig @ns1.mynameserver.com -t A blog.darian-brown.com
and if the DNS entry was added successfully, you should see a section in the response that is something like
;; ANSWER SECTION:
blog.darian-brown.com. 3600 IN A 192.168.0.2
Alternately you can ping the subdomain using
Once you have create DNS record for subdomain, it may take a while before it comes into effect. The reason is that your DNS server must send the new information to other DNS servers around the world, so that other DNS server all over know your new subdomain details and are able to find it on the internet. This process is commonly called DNS propagation.
This process may take up to 48 hours however a few hours usually does the trick. Updating a subdomain usually takes longer than creating a new domain or subdomain. This is because the other DNS servers will wait for their cache to expire before refetching your updated DNS zone file.