How to setup a DNS Server on ubuntu 12.04

This tutorial will help you in setting up a dns gateway in your ubuntu machine (I'm using 12.04 version, not sure if this would work on others).

First we need to install bind9, which is a dns server:

sudo apt-get install bind9

Open /etc/bind/named.conf.local and replace with:

acl internal {;

view "internal-view" {
 match-clients { internal; };
 include "/etc/bind/named.conf.default-zones";

 zone "" {
  type master;
  file "/etc/bind/zones/";


view "external-view" {
 match-clients { any; };
 include "/etc/bind/named.conf.default-zones";
Then create a file: /etc/bind/zones/, with the following contents:
$TTL 300
@ IN SOA (
   2012091800 ; Serial
   10800   ; Refresh
   3600  ; Retry
   604800  ; Expire
   300 )  ; Negative Cache TTL

ns1   A
                IN      MX  10

www  IN A
po1  IN A
db1  IN A
gw1  IN A
gw   CNAME gw1
po   CNAME po1
db   CNAME db1

The settings means that I have 3 servers:
1.) portal - po1, po
2.) gateways - gw1, gw
3.) database - db1, db

These settings are useful when you have a client (mobile app or another web application on another machine) and you don't want to change the IP setting. Because in mobile that means rebuild and redeploy. When you have these settings all you need to do is change your dns setting to, or the machine ip where you install  and configured bind9.

Finally edit, /etc/bin/named.conf and comment this line:
include "/etc/bind/named.conf.default-zones";

Restart bind9
sudo /etc/init.d/bind9 restart

In another machine all you need to do to change your dns server is to edit /etc/resolv.conf and add
How to setup a DNS Server on ubuntu 12.04 How to setup a DNS Server on ubuntu 12.04 Reviewed by Edward Legaspi on Thursday, September 20, 2012 Rating: 5

No comments:

Powered by Blogger.