How to Setup a DNS Server in Ubuntu

Would you like to setup a DNS Server in Ubuntu? How about setting up a private internal domain name at home? Well, you’ve come to the right place. There are number of tutorials on the internet showing you how to setup a DNS Server with Ubuntu using Bind 9. So, why another how-to document? That’s a good question. I’ve decided I needed to write a simple tutorial that anyone with a little bit of Linux knowledge would be able to follow. In the process, I hope readers are also able to learn how DNS works. Ok, let’s jump right to it!

What is DNS?

First of all, let’s cover the basics. What is DNS? DNS stands for Domain Name Server. It’s a service that runs on a server that translates humanly recognizable domain names such as or into its assigned IP addresses. If the DNS server does not recognize the domain name being requested, it will forward the domain name request to another DNS server and so on until the name is resolved.

A typical DNS request is when someone is accessing a website. Let’s use the domain as an example. When a user clicks a Yahoo link or types the Yahoo URL on the address bar of the browser, the DNS server processes the domain request. If it doesn’t find on its DNS table, it will forward the request to another DNS server with a higher authority and so on until it finds a server with the URL entry. The IP address information is then sent back to the user’s browser. If the domain name is not found, a “server not found” message is displayed on the browser.


Enough with the DNS background. Let’s now start configuring our own DNS server. Let’s assume that we have the following: we want to create a private internal domain name called, our private internal network is 192.168.0.x and our router and gateway is set at Let’s assume all devices are going to be configured with static IP addresses. Normally, most computer systems nowadays are configured to automatically obtain IP addresses from the DHCP server/router. In this example, we will use static IP addresses to show how DNS works. Finally, we have 3 computers connected to our network:

  • Ubuntu Server, the DNS server –
  • Ubuntu Desktop –
  • PC –


1. To install the DNS server, we need to install Bind 9.

sudo apt-get install bind9

2. Let’s configure Bind. We need to touch 5 files.

We will edit 3 files.

  • /etc/bind/named.conf.local
  • /etc/bind/named.conf.options
  • /etc/resolv.conf

We will create 2 files.

  • /etc/bind/zones/
  • /etc/bind/zones/

A. First step. Lets add our domain zone –

sudo vi /etc/bind/named.conf.local
# Our domain zone
zone "" {
   type master;
   file "/etc/bind/zones/";
# For reverse DNS 
zone "" {
   type master;
   file "/etc/bind/zones/";

Save file. Exit.

We just created a new domain. Please note: later we will create two files named and files. Also, notice the reverse IP address sequence in the reverse DNS section.

B. Let’s add the DNS servers from your ISP. In my case, I’m using Comcast DNS servers. You can place the primary and secondary DNS servers here separated by semicolons.

sudo vi /etc/bind/named.conf.options
forwarders {;

Save file. Exit.

C. Now, let’s modify the resolv.conf file found in /etc and place the IP address of our DNS server which is set to

$ sudo vi /etc/resolv.conf

D. Now, let’s define the zones.

sudo mkdir /etc/bind/zones
sudo vi /etc/bind/zones/
@ IN SOA (
);  IN      NS
ubuntudesktop  IN      A
www            IN      CNAME      ubuntudesktop
pc             IN      A
gw             IN      A
                       TXT        "Network Gateway"

The TTL or time to live is set for 3 days
The nameserver is defined
ubuntudesktop, pc and gateway are entered as an A record
An alias of www is assigned to ubuntudesktop using CNAME

E. Let’s create a “” file for reverse lookup.

sudo vi /etc/bind/zones/
@       IN      SOA (
        IN      NS
1       IN      PTR
10      IN      PTR
11      IN      PTR

3. Let’s restart Bind to activate our latest changes.

sudo /etc/init.d/bind9 restart

4. Finally, let’s test our new domain and DNS entries.


$ dig


nslookup gw

5. That’s it.

Driving My Ubuntu Desktop

Pictured above is how I drive my Ubuntu Desktop. It’s clean, fast and it’s brown all over. That’s Ubuntu for sure. Some people don’t really care for the earthy tones, but I don’t mind. My screen resolution is set to 1280 x 1024 pixels. I’ve decided to use this background for a bit of a change. By the way, the Compiz Fusion Desktop Effects are super. I love the applications: OpenOffice, Gimp, MoviePlayer, Rythymbox Music Player and the Bluefish Editor are just a few. The only thing I miss in Windows are the games. It may be time for some virtualization using VMWare. That’s my next project.