How-to configure DNS and DHCP Server Ubuntu Server 11.04

Today we build a DNS and DHCP Server with Ubuntu 11.04. The goal is to have a DNS server for your local LAN with automatically updated DNS addresses for DHCP clients and the DNS caching feature activated. I used some example addresses, which your to replace with yours.

  • Install Ubuntu and choose “DNS Server” during the setup routine
  • Change your NIC to static IP
  • Install with apt-get install “dhcpd” and if not already done “bind9″
sudo apt-get install dhcpd
sudo apt-get install bind9
  • Open “/etc/dhcp/dhcpcd.conf” with your preferred editor and add the following lines:
    local-address 192.168.1.2;
    ddns-update-style interim;
    ddns-updates on;
    ignore client-updates;
    option domain-name “yourdomain.xxx”;
    option domain-name-servers 192.168.1.2;
    ddns-rev-domainname “1.168.192.in-addr.arpa”;
    option routers 192.168.1.1;
    option broadcast-address 192.168.1.255;
    authoritative;
    include “/etc/bind/rndc.key”;
    zone    yourdomain.xxx. {
            primary 192.168.1.2;
            key “rndc-key”;
    }
    zone 1.168.192.in-addr.arpa. {
            primary 192.168.1.2;
            key “rndc-key”;
    }
    log-facility local7;
    default-lease-time 172800;
    max-lease-time 604800;
    subnet 192.168.1.0 netmask 255.255.255.0 {
      range 192.168.1.100 192.168.1.199;
    }
  • Add the follgwing lines to “/etc/bind/named.conf.options” between the “options”:
allow-query {
                    any;
            };
 forwarders {
                    192.168.1.1;
            };
  • Create a file under “/etc/bind/” named like “db.yourdomain.xxx” and add the following lines:
$TTL    3600
yourdomain.xxx.  IN  SOA  servername.yourdomain.xxx.  root.yourdomain.xxx. (
                       20100112;   Serial
                       10800   ;   Refresh
                       3600    ;   Retry
                       604800  ;   Expire
                       86400   ;   Minimum TTL
                       )
; DNS servers
yourdomain.xxx.          IN      NS     servername.yourdomain.xxx.
; Machine names
servername.yourdomain.xxx.   IN      A      192.168.1.2
; Aliases
ns1                   IN      CNAME  servername.yourdomain.xxx.
; MX record
;yourdomain.xxx.          IN      MX     10 mailserver.yourdomain.xxx.
  • Next create a file under “/etc/bind/” named like “db.192.168.1″ and add the following lines:
$TTL    3600
1.168.192.in-addr.arpa.    IN    SOA  servername.yourdomain.xxx.     root.yourdomain.xxx. (
                            20090504;               Serial
                            10800   ;               Refresh
                            3600    ;               Retry
                            604800  ;               Expire
                            86400   ;               Minimum TTL
                            )
; DNS servers
1.168.192.in-addr.arpa.         IN      NS    servername.yourdomain.xxx.
; Machine IPs
1                               IN      PTR   servername.yourdomain.xxx.
1                               IN      PTR   ns1.yourdomain.xxx.
  • Add the following lines to “/etc/bind/named.conf.local”:
zone “yourdomain.xxx” {
  type master;
  file “/var/cache/bind/db.yourdomain.xxx”;
  allow-update { key “rndc-key”; };
};
zone 1.168.192.in-addr.arpa {
  type master;
  file “/var/cache/bind/db.192.168.1″;
  allow-update { key “rndc-key”; };
};
include “/etc/bind/rndc.key”;
controls {
        inet 127.0.0.1 port 953
        allow { 127.0.0.1; } keys { “rndc-key”; };
};
  • Create two symbolic links for the “caching” and “ddns” feature:

ln -sf /etc/bind/db.yourdomain.xxx /var/cache/bind/

ln -sf /etc/bind/db.192.168.1 /var/cache/bind/

  • Create the key for interfacing DHCPD and BIND9
rndc-confgen -a
rndc-confgen -r /dev/urandom -a
  • You have to modify the permission
sudo chown root:bind /etc/bind/rndc.key
sudo chmod 644 /etc/bind/rndc.key
  • Next modify “/etc/apparmor.d/usr.sbin.dhcpd3″
/etc/bind/ r,
/etc/bind/** r,
  • Last restart all three services
sudo /etc/init.d/apparmor restart
sudo /etc/init.d/isc-dhcp-server restart
sudo /etc/init.d/bind9 restart
  • Now you are ready to user your own DNS Server with DHCP, caching and automatic registering DHCP Client to your DNS server
  • If you find any failures or not used or necessary settings, please write in the comments or send me a mail, I will correct it immediately

Sources:

3 thoughts on “How-to configure DNS and DHCP Server Ubuntu Server 11.04

  1. hi

    i followed this guide to get my local LAN up and running. all 3 daemons were able to restart ok (initially had issues with DNS config syntax, as I had followed an earlier static DNS guide until I realised it didn’t do what i wanted).

    all devices seem to get allocated a DHCP lease, but they do not get registered dynamically into DNS. could you offer where to look for or what to change to enable better logging to see what the issue(s) are?

    I have hard-coded the DNS server’s record itself into my /etc/bind/zones/jingo.local.db file and any DHCP clients are able to resolve this ok, as:

    ; Machine names
    jingoserver.jingo.local. IN A 192.168.1.10

    hoping you can help. i am so close…

    cheers

    • Hi Dan,
      I am not sure if I understood all your steps correct but I can imagine what the issue are, I did it also wrong at the beginning.

      You should not modify by hand any of the zone files because otherwise the zone files are corrupt for ISC-DHCP daemon and he is no able to update the files.

      To add static entries to your zone file you have to use your the command “nsupdate”. I don’t have the exact syntax for you now, but if you give me a few days, I will write a detailed blog post. If you can’t wait and you have the syntax, please post it at this place.

      Last, I need definitely to review the article, I did some mistake at the How-to. In short words, the zone files should you create add /var/cache/bind/ and the symbolic links you should place under /etc/bind. Otherwise the the zone files will be always overwritten.

      Hope that helps, cheers.

  2. thanks for the quick reply.

    i started following some other guides from further searching. the main source i used was this:

    http://brunogirin.blogspot.com/2007/11/dhcp-and-dynamic-dns-on-ubuntu-server.html

    which was very similar to your own, though i guess used the amendments you mentioned.

    though i had some errors in my DNS config files, which i also corrected using the log files to troubleshoot, i think the main problem was the following section in my dhcpd.conf file:

    zone jingo.local. {
    primary 127.0.0.1;
    key “rndc-key”;
    }

    i had this pointed at an unused IP address originally, following your guide word-for-word (192.168.1.2). resetting this to the loopback address (guess could have also used 192.168.1.10 which is my server) and restarting the daemon, all dhcp clients now register in dns.

    the new registrations cannot be viewed in the /var/cache/bind/zone.db file. i think its contained the /var/cache/bind/zone.db.jnl file, though this easily viewable. is it dynamic or encoded or something?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s