Notes on DNS—details for turning af-blackpearl.site into a DNS server

Russ Bateman
2 May 2013
last update:

This is very tentative and unfinished; it's mostly research right now.

You may be looking for this post:
Failure to ping outside of LAN, ping google.com.

Links

First, discover your existing DNS service by it primary and secondary IP addresses:

    [email protected]:/etc/bind# cat /etc/resolv.conf
    domain americas.hpqcorp.net
    search americas.hpqcorp.net
    nameserver 16.110.135.51                <---------- primary DNS server
    nameserver 16.110.135.52                <---------- secondary DNS server

Assume all commands here from root...

  1. Install DNS server.
        $ apt-get install bind9 dnsutils
    
  2. Modify /etc/hosts (maybe not!?)
        127.0.0.1       af-blackpearl.site       localhost.localdomain    localhost
        16.86.192.110   af-blackpearl.example.com   af-blackpearl
    
  3. Edit named.conf.options to add forwarders to use in case your additional DNS settings don't cover what's asked for.
        $ vim /etc/bind/named.conf.options
    
        forwarders
        {
                16.110.135.51
                16.110.135.52
        };
    
    At this point, there is something different to do if the host your new DNS server is running on gets its IP address via DHCP (dynamically) or just has its own static IP address. If dyanmic, please see this URL:
    http://lani78.wordpress.com/2012/07/22/setting-up-a-dns-for-the-local-network-on-the-ubuntu-12-04-precise-pangolin-server/

  4. Edit /etc/network/interfaces. Change or add the following directives (in bold).
        # 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 dhcp		(originally DHCP; we want static IP now...)
        iface eth0 inet static
    	    address   16.86.192.110
    	    netmask   255.255.255.0
    	    network   16.86.192.0
    	    broadcast 16.86.192.255
    	    gateway   16.86.192.1
    	    dns-nameservers 127.0.1
    	    dns-search example.com
    	    dns-domain example.com
    
        # Use this address for our Tomcat ReST URIs!
        #auto eth0:0
        #iface eth0:0 inet static
        #	address 16.86.192.119
        #	netmask   255.255.255.0
    
  5. Define zones for the new, local domain in named.conf.local.
        zone "example.com" IN
        {
            type master;
            file "/etc/bin/zones/example.com.db";
        }
    
  6. Also, add a zone for reverse DNS look-ups on the local network. If this looks funny, it's because the IP address is backwards (on purpose).
        zone "192.86.16.in-addr.arpa"
        {
            type master;
            file "/etc/bind/zones/rev.192.86.16.in-addr.arpa";
        };
    
  7. Create subdirectory zones.
        $ mkdir /etc/bind/zones
    
  8. Create the local domain database. There are some comments here you can add in case you ever need to edit this file. See especially Howto: Setup a DNS server with bind here.
        $ cd zones
        $ vim example.com.db
    
        ; Use semicolons to add comments.
        ; Host-to-IP Address DNS Pointers for example.com
        ; Note: The extra dots at the end of the domain names are important.
    
        ; The following parameters set when DNS records will expire, etc.
        ; The serial number must always increase to prevent undesirable
        ; consequences. A good format to use is YYYYMMDDII where the II index
        ; is in case you make more than one change on the same day.
        $ORIGIN .
        $TTL 86400      ; 1 day
        example.com. IN SOA ubuntu.example.com. hostmaster.example.com.
        (
            2008080901 ; serial
            8H ; refresh
            4H ; retry
            4W ; expire
            1D ; minimum
        )
    
        ; NS indicates that Ubuntu is the name server on example.com
        ; MX indicates that Ubuntu is (also) the mail server on example.com
        example.com. IN NS ubuntu.example.com.
        example.com. IN MX 10 ubuntu.example.com.
    
        $ORIGIN example.com.
    
        ; Set the address for localhost.example.com
        localhost    IN A 127.0.0.1
    
        ; Set the hostnames in alphabetical order
        print-srv    IN A 16.86.192.9
        router       IN A 16.86.192.1
        server       IN A 16.86.192.5
        ubuntu       IN A 16.86.192.2
        xbox         IN A 16.86.192.3
    
  9. Create the reserve look-up database. (I'm not adding the comments).
        ; IP Address-to-Host DNS Pointers for the 16.86.192 subnet
        @ IN SOA ubuntu.example.com. hostmaster.example.com.
        (
            2008080901 ; serial
            8H ; refresh
            4H ; retry
            4W ; expire
            1D ; minimum
        )
        ; define the authoritative name server
                   IN NS ubuntu.example.com.
        ; our hosts, in numeric order
        1         IN PTR router.example.com.
        2         IN PTR ubuntu.example.com.
        3         IN PTR xbox.example.com.
        5         IN PTR server.example.com.
        9         IN PTR print-srv.example.com.
    
  10. Restart the bind9 service to use the new settings.
        $ service bind9 restart
        - or -
        $ /etc/init.d/bind9 restart
    
  11. Restart the network interface
    $ nohup sh -c "ifdown eth0 && ifup etch0"
    

    --this has been deprecated if you're using DHCP. See http://lani78.wordpress.com/2012/07/19/change-to-static-ip-on-the-ubuntu-precise-pangolin-server/

  12. Change /etc/resolv.conf?
        search example.com
        nameserver 16.86.192.110
    

    instead of it continuing to use what's been (before setting up local DNS).

    Warning: Most *nicies have changed how /etc/resolv.conf works! Please see here.

  13. Check out that host works. (Much to be changed here.)
        $ host ping.sunet.se
    

    The response should be ping.sunet.se has address 16.86.192.18 ping.sunet.se has IPv6 address blah:blah:blah::blah

  14. Test that computers at are listed. (Much to be changed here.)
        $ host -l example.com
        example.com name server ubuntu.example.com.
        localhost.example.com has address 127.0.0.1
        print-srv.example.com has address 192.168.0.9
        router.example.com has address 192.168.0.1
        server.example.com has address 192.168.0.5
        ubuntu.example.com has address 192.168.0.2
        xbox.example.com has address 192.168.0.3
    
  15. Step. Test reverse look-up.
        $ host 16.86.192.1
    
        1.192.86.16.in-addr.arpa domain name pointer ubuntu.example.com.
    

Last, a firewall is needed if this is being done behind a router at home to keep from exposing your network. Port 53 nust not be forwarded to your DNS server!