Bind9 DNS on Ubuntu

Installing the bind9 dns server on Ubuntu is as simple as installing an Apache web server and creating a virtual host and start serving sites. All done in 10 minutes :). Yes…. sounds crazy…but it is quite simple.

This blog about installing bind9 dns server assumes following

  1. Fully patched, updated, upgraded Ubuntu server as far as possible the latest LTS one, else any LTS version will do. This has been tried and tested on a Precise (12.04.05 LTS) version of Ubuntu and on Trusty Thar as well. In general, I prefer a 64 bit version.
  2. For a 1500 clients a virtual machine with one core and 512 MB ram is more than sufficient. If you also want to add isc-dhcp server on the same machine, bump up the RAM to 1 GB and you are all set. A basic 10 GB hard disk is more than enough for this kind of a setup.
  3. You are comfortable using the terminal

Coming to actual implementation

  1. ssh into the server using the standard credentials (we shall be using the recommended ‘sudo’ method)
  2. install the bind9 package – sudo apt-get install bind9…….  This has to be done before the below steps and internet will be available right now. Once you change the ip address and the gateway and dns-nameservers, internet will not be available till the dns server is fully configured
  3. assign a static ip to the server
    1. sudo nano /etc/network/interfaces (this should be the content of the file. suit yourself to change the IP address, netmask, network, gateway, broadcast, dns-nameservers
      # This file describes the network interfaces available on your system
      # and how to activate them. For more information, see interfaces(5).

      # The loopback network interface
      auto lo
      iface lo inet loopback

      # The primary network interface
      auto eth0
      iface eth0 inet static
      address 10.1.49.5
      netmask 255.255.255.0
      network 10.1.49.0
      broadcast 10.1.49.255
      gateway 10.1.49.1
      dns-nameservers 10.1.49.5

    2. Save the above file and restart the server by typing (sudo init 6)
  4. Configuring bind9 – For configuring bind9, you need to edit four files in /etc/bind/ folder. Thats it. Nothing more and nothing less
    1. named.conf.options
    2. named.conf
    3. named.conf.custom-zones (thi we will create. It is not available by default)
    4. For each domain (zone) you have to create a file from a template and make necessary changes
  5. Editing /etc/bind/named.conf.options
    • uncomment the forwarders section. It must look like this. Add your internet or ISP DNS servers if you have. I use the google DNS to make things simpler.                                                                                                     forwarders {
      8.8.8.8;
      };
    • You can add the ISP DNS servers if you have below 8.8.8.8; as a new line. Don’t forget to put a ‘ ; ‘
    • save the file and exit
  6. Editing /etc/bind/named.conf
    • It should look like the below
    • include “/etc/bind/named.conf.options”;
      include “/etc/bind/named.conf.local”;
      include “/etc/bind/named.conf.default-zones”;
      include “/etc/bind/named.conf.custom-zones”;
  7. Editing /etc/bind/named.conf.default-zones
    • Create the above file and start making entries for the domain file path. For each domain, we will make a file called as db.domain name and named.conf.custom-zones file will store the path where this db. domain file is stored on the server
    • Taking an example of two domains : abc.in and xyz.sa – we will create A records for these domains and if apache or a web server is installed then the default web page for both domains will be displayed.
    • sudo nano /etc/bind/named.conf.custom-zones and paste the following
    • //Zones file paths where to find the db files

      zone “abc.in” {
      type master;
      file “/etc/bind/zones/abc/db.abc”;
      };

      zone “xyz.sa” {
      type master;
      file “/etc/bind/zones/xyz/db.xyz”;
      };

    • In the above, we have defined the domain and mentioned that the actual entries for the domain will be found in db.abc or db.xyz that is stored in a folder called zones inside the /etc/bind/ folders
  8. Making the actual zone files (domain files where all the details about a domain will be stored such as A records, MX records, etc.)
    • make a folder called as zones in /etc/bind/ (cd /etc/bind and then sudo mkdir zones)
    • create a folder called as abc and xyz in the folder zones. One folder per domain to keep it organized.
    • create a new file called as db.abc in the abc folder and paste the following content
    • copy the following content in the file. Only change the IP address and the email id
    • Copy it as it is                                                                                                                                                             abc Repeat the above for xyz.sa domain
    • Once above is done restart bind9 by : sudo service bind9 restart
    • You will need to tell the dhcp server to pass the DNS server as 10.1.49.5 tp all clients while issuing the IP address.
  9. Your DNS server is ready to use. Enjoy ! Don’t forget to like if this setup works for you.
Advertisements

2 thoughts on “Bind9 DNS on Ubuntu

    • Hey thanks Jenny for pointing this out. Actually, I had kept it as 500 because it is a test environment and it just makes testing simpler. In real world scenario, you should keep it default or whatever is suitable for your network.

      Good catch though.
      Cheers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s