Setting Up your own DNS server with bind9

July 25, 2010

After setting up our Ubuntu server and successfully deploy our Rails application, we need to setup our own DNS server with bind9 to publish our Rails application to the world via a meaningful domain name.

Install bind9:

sudo aptitude install bind9 dnsutils
sudo nano /etc/bind/named.conf.local

Add the following lines in ‘named.conf.local’:

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

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

Add a zone config file

sudo cp /etc/bind/db.local /etc/bind/zones/db.domain.com
sudo nano /etc/bind/zones/db.domain.com
$TTL    604800
domain.com.        IN      SOA     ns1.domain.com. support.domain.com. (
                     2010072504         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL

; DNS
domain.com. IN NS ns1.domain.com.

; Sub-domains
@       IN      A       202.181.234.41
ns1     IN      A       202.181.234.41
www     IN      A       202.181.234.41

Configue bind9 options:

sudo nano /etc/bind/named.conf.options

Add the following lines to ‘/etc/bind/named.conf.options’:

        query-source address * port 53;
        notify-source * port 53;
        transfer-source * port 53;

        forwarders {
                202.181.224.2;
                202.181.224.3;
                202.181.224.130;
                202.181.224.140;
        };

Edit ‘/etc/ressolv.conf’:

search domain.com
nameserver 127.0.0.1
nameserver 123.456.789.123
nameserver 202.181.224.2
nameserver 202.181.224.3
nameserver 202.181.202.130
nameserver 202.181.224.140

Add the following lines to ‘/etc/iptables.up.rulse’ and restart iptables:

iptables -I INPUT -p udp -m udp --dport 53 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 53 -j ACCEPT

Install nscd and clear DNS lookup cache:

sudo aptitude install nscd
sudo /etc/init.d/nscd restart

Test the result:

dig @localhost domain.com
dig domain.com

Settings for your domain name in GoDaddy.com

I registered my domain on GoDaddy.com, so i need to set the nameserver to point to the newly created DNS server and set the host ip for ns1.domain.com.

Setting Host ip address for DNS server (It will takes 24-48 hours to be effective) :

  1. Login your account on GoDaddy.com
  2. Account Manager>My Products>Domain>Domain Manager
  3. Host Summary (At the lower left corner)
  4. Add a Host
  5. Host name: ns1
  6. Host IP: [Your DNS server fixed ip address]
  7. OK

Setting nameservers:

  1. Login your account on GoDaddy.com
  2. Account Manager>My Products>Domain>Domain Manager
  3. Name Server>Set Nameservers
  4. Add your own DNS server and any secondary DNS server in your region

References:

DNS (bind9) Configuration HowTo
Ubuntu Hardy – Installing a DNS Server with BIND

Related Posts

|

Leave a Comment

Previous post:

Next post: