Recommended VPS Complete list of best VPS hosting providers.

How To Install and Setup Bind9 On Ubuntu Server

So you knew how to manually install and setup a Linux, Apache, MySQL and PHP (also known as LAMP Stack) on a server based on Ubuntu. You may be wondering how to make your server being accessible by domain not by IP address. Well, there are several ways you can do that but the key method is simple: by using DNS Server. There are two methods to have DNS Server connecting your domain to your server: First, you can simply use DNS management service which is usually offered freely by most of domain registrar like GoDaddy and NameCheap; Another method is to install and setup your own DNS server right inside your operating system to manage how the way your domain resolves to your server. I will explain the first method another day while today in this page you’ll see the second method.

p.s: When I say “server” it refers to both VPS or Dedicated server

Requirements

  1. This tutorial is done on Ubuntu-based server. I am running Ubuntu 12.0.4 (see my playground server).
  2. Windows users should download Putty while Mac and Linux users can simply use Terminal
  3. You’ll also need a basic skill to use Putty and to navigate through SSH. Read: Most common Unix commands used to SSH.
  4. In this tutorial I will use Bind9 which is a free DNS management software available for most Operating System including Unix-based OS. I will not explain what is BIND and what are its key features as Wikipedia covers that topics better.
    Read: What is DNS Management Software and comparison of available software.
  5. You may firstly install LAMP stack or any other stack you wish.
  6. About 15 minutes of your time and a cup of tea if you like.

Step 1. Login to your server

Launch Putty (or Terminal) and login to your server via SSH connection. Please remember if you’ve followed our very basic guide here, you may already have disabled root login or changing default SSH port from 22 to other numbers. If you really did disable root login, then login by using new username and password you created then type following command once you logged in, otherwise you can simply skip this command:

sudo su

then you have to enter root password.

Step 2. Install Bind9

Type this command then hit enter:

apt-get install bind9

install bind9

Once done you’ll see a message saying:

* Starting domain name service... bind9      [OK]

Step 3. Basic Configuration

So you have installed BIND9 on your server. It is time to show you a basic configuration how to setup your domain to resolve to your server. Here’s what I did. Type following command then hit Enter on your keyboard:

nano /etc/bind/named.conf.local

Nano editor screen will appear. Copy-paste command below into your favorite text editor like Notepad, Notepad2 or Notepad++:

zone "domain.com" {
type master;
file "/etc/bind/zones/domain.com.db";
};

zone "3.2.1.in-addr.arpa" {
type master;
file "/etc/bind/zones/rev.3.2.1.in-addr.arpa";
};

Again, in any command in this page you’ll need to replace “domain.com” with your own domain name and corresponding TLD. E.g: servermom.com. Also, you have to replace xxx.xxx.xxx.xxx with IP address of your server.

Once you’ve done editing necessary values, you can paste it to Nano editor screen. You can also simply type command syntax above to Nano editor screen while replacing necessary value during your typing.

edit config file

Now hit Control+O on your keyboard to save the file then hit Control+X to exit Nano editor.

Then go to bind directory to make things easier. Type this command:

cd /etc/bind

Create new directory called “zones” inside it.. Use this command:

mkdir zones

Now go enter that directory as well..

cd zones

cd zones

Then create new file called “nano domain.com.db“. Type this command:

nano domain.com.db

of course at this part you’ll also need to replace “domain.com” with your own domain name. Example:

nano servermom.com.db

That command brings Nano editor screen up once again. Next, you can either copy these syntax to Notepad first then edit it or simply type it in Nano editor directly:

; BIND data file for domain.com
;
$TTL 14400
@ IN SOA ns1.domain.com. host.domain.com. (
201006601 ; Serial
7200 ; Refresh
120 ; Retry
2419200 ; Expire
604800) ; Default TTL
;
domain.com. IN NS ns1.domain.com.
domain.com. IN NS ns2.domain.com.

domain.com. IN MX 10 mail.domain.com.
domain.com. IN A xxx.xxx.xxx.xxx

ns1 IN A xxx.xxx.xxx.xxx
ns2 IN A xxx.xxx.xxx.xxx
www IN CNAME domain.com.
mail IN A xxx.xxx.xxx.xxx
ftp IN CNAME domain.com.
domain.com. IN TXT "v=spf1 ip4:xxx.xxx.xxx.xxx a mx ~all"
mail IN TXT "v=spf1 a -all"

Here’s an example of mine:

; BIND data file for servermom.com
;
$TTL 14400
@ IN SOA ns1.servermom.com. host.servermom.com. (
201006601 ; Serial
7200 ; Refresh
120 ; Retry
2419200 ; Expire
604800) ; Default TTL
;
servermom.com. IN NS ns1.servermom.com.
servermom.com. IN NS ns2.servermom.com.

servermom.com. IN MX 10 mail.servermom.com.
servermom.com. IN A 141.0.170.144

ns1 IN A 141.0.170.144
ns2 IN A 141.0.170.145
www IN CNAME servermom.com.
mail IN A 141.0.170.144
ftp IN CNAME servermom.com.
servermom.com. IN TXT "v=spf1 ip4:141.0.170.144 a mx ~all"
mail IN TXT "v=spf1 a -all"

If you have two IPs, you can replace “ns2 IN A xxx.xxx.xxx.xxx” with your second IP address. Otherwise simply use the same IP.

servermom.com.db

Once done editing, hit Control+O to save that file then hit Control+X to exit Nano editor.

Next step, it’s time to define reverse DNS lookup. Sounds not so familiar? Don’t worry simply repeat my steps. Type this command syntax:

nano /etc/bind/zones/rev.3.2.1.in-addr.arpa

That will open Nano editor screen again but this time you will edit another file. Add following lines inside that file..

@ IN SOA domain.com. host.domain.com. (
2010081401;
28800;
604800;
604800;
86400 );

IN NS ns1.domain.com.
4 IN PTR domain.com.

Replace “host.domain.com” with your own server’s host name. Once done, press Control+O to save followed by Control+X to exit.

Example:

@ IN SOA servermom.com. host.servermom.com. (
2010081401;
28800;
604800;
604800;
86400 );

IN NS ns1.servermom.com.
4 IN PTR servermom.com.

screenshot:

arpa address

That’s not done yet. There is another file you have to edit. Run this command:

nano /etc/resolv.conf

Now add following line at very top of any lines you see there:

search domain.com

Example:

resolver

Once done, press Control+O to save followed by Control+X to exit. That is it. But to make sure that Bind9 can apply all recent changes above, you better restart Bind9 service using this command:

/etc/init.d/bind9 restart

To conclude, in your Putty screen it will show all the command syntax used which is something like this:

all command syntax

Step 4. Change Nameserver In Your Domain Registrar

I will not explain this last step because the way it can be done is really vary. It depends on which registrar you purchased the domain from. E.g: GoDaddy, NameCheap, Name, and so on.

The key point is to add ns1.domain.com and ns2.domain.com there. Once done, wait for about 24 hours for your domain to resolve to your server but sometimes it takes faster and done within few hours.

You can confirm it easily via web browser then type your newly configured domain name:

it works

Step 5. Test Your DNS

In this case lets install additional tool called “DNS Utility”. Here’s how to install it:

apt-get install dnsutils

Once the install process finished, type following command:

dig domain.com

If everything is set correctly you’ll see something like this one below..

You can also test it using third-party service like Pingdom.com DNS test tool here.

62 Comments

Add a Comment

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

Get more stuff like this
in your inbox

Subscribe and get interesting stuff plus faster updates to your email.