How To: DNS with BIND9 on Debian – Part 1/2

Part 2 now available

This two part tutorial will guide you in creating a DNS caching server and DNS zones. Part 1 will focus on setting up a simple caching nameserver with BIND. Part 2 will go into Zones and how to configure them.

The instructions in this guide should be compatible with Ubuntu 10+ as well as Debian 6 and 7.

This tutorial presumes you have basic knowledge of how DNS works. Additionally basic knowledge on how to navigate the Linux terminal.

As most of you know DNS is the system that machines use to convert hostnames (google.com) to an IP address (173.194.32.32). Most business and home networks use their ISPs DNS servers for resolving hostnames.

This is acceptable, but we can speed up name resolution by adding a caching DNS within your network infrastructure. Additionally, you can create your own DNS zone(s) to create and handle hostnames of machines on your own network.

To start, let’s take a look at what caching does. When you type a hostname in your browser, you will send a request to a DNS server to find the matching IP address of that domain. Once the DNS returns the IP address you can then proceed to the website. In the event the DNS server does not have the answer it must ask other DNS servers or even the root name servers for the IP address. This process takes some time.

Because of this and to reduce the load on the root name servers DNS will keep a local copy of previous requests – caching. This local copy will be used for all future requests for the same domain name speeding up response time.

Usually a home or small business network will be using an offsite DNS service, more than likely from your ISP. All requests sent will be to your ISP and you will then get an answer in reply. Hopefully the ISP has the request in its own cache so that the response time is as fast as possible.

Having a caching DNS server on your own network will improve DNS performance substantially. It will work in the same way as your ISPs DNS server, but it will be local, available and fast!

Best of all, a simple caching name server is quick and easy to setup. All that is required is some spare hardware or a virtual machine.

Settings up a caching DNS server
Prerequisites: Installed, updated and setup Debian with a static IP

1. install BIND9 and DNS utilities

Once the packages are installed all we have to do to setup the caching server is to tell BIND which DNS server it can use if it doesn’t know the answer. These are called DNS forwarders. A good choice are your current DNS servers, the ones provided by your ISP for example. So when your caching DNS server doesn’t know the answer it will ask these forwarding servers. Usually leveraging their large cache for a fast response.

2. Open the following file:

Edit the file as shown below. Remove the // to un-comment the block concerning forwarders and replace the zeroed out IP addresses with the address of your ISP DNS servers. You can have as many forwarders as you like. Remember to save the file.

3. Restart BIND9

4. It’s also worthwhile changing the default DNS to 127.0.0.1 (Its self) in Debian. Just comment out your current nameservers in case you want to use them again.
Open:

5. restart networking

6. Test your DNS.
Start by typing the following command:
dig google.com
You should get an output similar to this (Note, the “Query Time”):

Now run it one more time:

The Query time went from 238ms to 0ms. That’s because the previous request is now cached locally in BIND.

Caching is now setup and this server is ready to handle queries from clients. Just change your clients DNS address to the address of the Debian server with BIND to take advantage of your new DNS server.

We can optimize the server further and also be further secured, but that is outside the scope of this post.

The next post in this series will cover how to create your own DNS Zone which we can use in either a small business or at home. The advantage to having your own DNS zone is that you can have hostnames within your local LAN. That saves you from remembering IP addresses and lets you use machine named instead :)

 

Jack.

Part 2 now available

Comments

  1. sohrab says

    I am iranian and i can’t good speak English but VERY VERY VERY VERY VERY VERY VERY Tank you

    Good Luck My frind….!

Trackbacks

Leave a Reply

Your email address will not be published. Required fields are marked *