In previous posts, I shared instructions for setting up a Ubuntu LAMP (Linux, Apache, mySQL, PHP) server and configuring Apache and mySQL to host new sites complete with phpmyadmin and cgi-bin access. I thought it would be useful to write a follow-up guide on setting up of an Ubuntu DNS (Domain Name Service) server on your LAN (local area network). For newcomers, DNS is a service that maps IP addresses to domain names (e.g., a public DNS server is responsible for mapping www.google.com to 74.125.19.103 and vise versa). There are several reasons why you may want to set up a private DNS server on you LAN. If your LAN includes more than a few machines, a private DNS server may be a more convenient way to map client host names to IP addresses then having to maintain a hosts configuration files on each client. A private DNS server can also help increase network performance by caching IP addresses of commonly visited websites instead of retrieving them from the public DNS servers maintained by ISPs at each request. This post describes how to set up a caching DNS server using BIND9 (Berkley Internet Naming Daemon Version 9), the most widely used DNS program and the DNS server that ships with Ubuntu. In a follow-up post I describe how to set up a master DNS server to serve DNS records for an imaginary domain (i.e., your LAN).
Step 1: Install BIND DNS server on Ubuntu
There are two ways to install BIND on Ubuntu. If you are performing a fresh installation of Ubuntu Server Edition (version 7.04 at time of writing) as per this post, at some point the install shell will ask if you wish to install a DNS and/or LAMP server. Select DNS (and LAMP if you so desire using the arrow keys and spacebar) and continue (using tab and enter). On the other hand, if you have already completed the installation of your LAMP server then use Ubuntu’s built in package management program aptitude to install BIND. Open a terminal and type
sudo aptitude install bind9
You may need to insert the Ubuntu install CD to perform this installation.
Step 2: Configure BIND Caching DNS server
By default, BIND installs on Ubuntu configured to act as a caching DNS server. However, you need to edit the configuration options file /etc/bind/named.conf.options to specify a public DNS server operating on the wide area network (WAN) to which un-cached domain names should be forwarded. Open this file with the text editor of your choice (I use vi here).
Uncomment and edit the forwarders section of this file to point to your internet service provider’s DNS server. You may enter multiple DNS server addresses (separated by semicolons) if you desire. When finished, the forwarders section should look like the following with the xxx.xxx.xxx.xxx replaced with the appropriate IP address(es).
xxx.xxx.xxx.xxx;
xxx.xxx.xxx.xxx;
};
You must also edit the /etc/resolv.conf configuration file of all machines on your LAN (including the DNS server itself) to point to your new DNS server. Open this file
and add
to the top of the file where xxx.xxx.xxx.xxx is the IP address of your new DNS server. When configuring the DNS server itself, change the nameserver address to 127.0.0.1, which points to localhost. You may delete any additional nameserver lines appearing in the resolv.conf file although it may be prudent to leave lines in place that point to your ISP’s DNS server so that client machines continue to function in the event of your server going offline (just make sure your DNS server is listed first). To implement the changes to your DNS server, restart BIND.
Finally, test your server by typing the following command in a terminal on any machine on your LAN configured to use your new DNS server.
Near the end of the output of this command there should be a line that reads Query time: 24 ms (of course the actual time may be different). Execute the dig www.zaphu.com command again and you should notice that the query time significantly decreased indicating that your DNS server is caching DNS information for www.zaphu.com. Note that BIND caches DNS information to RAM and not disk. In most cases this will not be a problem since most machines have plenty of memory and old records are purged from memory after a period of time. However, if you expect your server to get a lot of traffic you may want to periodically flush the cache using
or set the maximum amount of memory to use (in essence forcing overflow data to be deleted before it expires) by setting the max-cache-size option in the configuration file.
Congratulations! you are finished setting up your Ubuntu caching name server. See my next post where I discuss configuring a master DNS server to serve hostnames to machines on your LAN.
Update, Oct. 24, 2007: Ubuntu 7.10 has been released and is receiving great reviews.
Update, May 5, 2008: Updated for Ubuntu Hardy Heron 8.04.

Add New Comment
Viewing 9 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks
(Trackback URL)
September 11, 2007 at 9:18 pm
[...] and continue (using tab and enter). You may also select DNS and follow the instructions of this post if ...
September 14, 2007 at 11:21 pm
[...] a previous post I walked you through the installation of BIND9 (Berkley Internet Name Daemon Version 9) on Ubuntu ...
January 17, 2008 at 3:29 pm
[...] If you wish to install a name server as well, you may select DNS and follow the instructions of ...
May 15, 2008 at 11:11 am
[...] coursework files. Zaphu.com has good tutorials how to setup a BIND master server and Caching Name Server. This Two-in-One ...
May 21, 2008 at 7:24 pm
[...] coursework files. Zaphu.com has good tutorials how to setup a BIND master server and Caching Name Server. This Two-in-One ...
August 9, 2008 at 12:20 pm
[...] BIND Caching Name Server Setup BIND Master Server Setup [...]
April 20, 2009 at 3:54 pm
[...] Read the original here: Ubuntu DNS Server Guide - BIND Caching Name Server Setup : Zaphu [...]
June 18, 2009 at 2:53 pm
[...] tried a how to from net to configure dns.Since it was a failure as you said,today i tried this ...
June 28, 2009 at 1:38 am
[...] DNS server’s as backups. This is the tutorial I used if anyone’s interested, here No TweetBacks yet. (Be the ...