Nameserver on CentOS

This post describes how to setup a nameserver on CentOS. The setup is intended to service DNS (domain name system) queries for this server itself. The nameserver is generic and can be used to provide DNS lookup for other websites as well, but the original intention of the post was to setup a fully contained server which services its own DNS queries. Since this original post I’ve started using Amazon Route53 which provides a highly available and scalable Domain Name System (DNS) web service.

SETUP NAMESERVER

  1. yum list bind-*
  2. yum install bind-chroot.x86_64 (if needed)
  3. cp /usr/share/doc/bind-/sample/etc/named. /var/named/chroot/etc
  4. cp /usr/share/doc/bind-/sample/var/named/named. /var/named/chroot/var/named
  5. chown -R named:named /var/named
  6. vi /etc/resolv.conf
  7. vi /var/named/chroot/etc/named.conf
  8. vi /var/named/chroot/var/named/mydomain.com.zone
  9. chmod 640 mydomain.com.zone
  10. chown root:named mydomain.com.zone
  11. service named restart
  12. chkconfig –level 235 named on
#FILE: /etc/resolv.conf

nameserver 127.0.0.1
#FILE: /var/named/chroot/etc/named.conf

options {
  listen-on     port 53 { any; };
  listen-on-v6  port 53 { any; };
  version             "none";
  directory           "/var/named";
  dump-file           "/var/named/data/cache_dump.db";
  statistics-file     "/var/named/data/named_stats.txt";
  memstatistics-file  "/var/named/data/named_mem_stats.txt";
};
logging {
  channel my_log {
    file "data/named.run" versions 3 size 5m;
    severity warning;
    print-time yes;
    print-severity yes;
    print-category yes;
  };
  category default {
    my_log;
  };
};
view "localhost_resolver" {
  match-clients       { localhost; };
  match-destinations  { localhost; };
  recursion yes;
  include "/etc/named.rfc1912.zones";
  zone "mydomain.com" {
    type master;
    file "/var/named/mydomain.com.zone";
  };
};
view "external" {
  match-clients       { any; };
  match-destinations  { any; };
  recursion no;
  allow-query-cache   { none; };
  zone "mydomain.com" {
    type master;
    file "/var/named/mydomain.com.zone";
  };
};
#FILE: /var/named/chroot/var/named/mydomain.com.zone

$TTL 1D
@   IN  SOA   ns1.mydomain.com. admin.mydomain.com. (
2012090601    ; serial, todays date, update with every edit
12H           ; refresh
4H            ; retry
28D           ; expire
1D )          ; minimum
IN    NS      ns1.mydomain.com.
IN    NS      ns2.mydomain.com.
IN    MX      1 ASPMX.L.GOOGLE.COM.
IN    MX      5 ALT1.ASPMX.L.GOOGLE.COM.
IN    MX      5 ALT2.ASPMX.L.GOOGLE.COM.
IN    A       123.456.789.100
ns1                 IN    A       123.456.789.100
ns2                 IN    A       123.456.789.101
localhost           IN    A       127.0.0.1
www                 IN    CNAME   mydomain.com.