photo
Jordan Sissel
geek

Thu, 29 Nov 2007

Dynamic DNS and DHCP - Easy to do, and you'll thank yourself later

Preface

This article will cover how to setup dns with dynamic updates aswell as configuring your dhcp server to push updates to it aswell.

I assume you already know how to setup plain old dns aswell as plain old dhcp. This is not an introduction to either of those. I used BIND 9 and ISC DHCPD v3 for this article.

If there's anything this article doesn't cover with respect to what you are looking for, leave a comment and I'll do what I can.

What is Dynamic DNS?

Dynamic DNS is the means by which to push new records into your dns server while it is running, without having to edit any zone files. It is quite often coupled with dhcp to provide dynamic network services that have hostnames follow the appropriate machines around.

Dynamic DNS

Setting up dynamic dns is pretty straight forward. To do it securely, you need to first create a secret key. This secret key will be used to authenticate our dns update clients with the dns server. Luckily for us, there's a tool that'll do that for us.

Create a dnssec key

That tool is called dnssec-keygen. Don't feel like reading the manpage? Fine. dnssec-keygen is a tool to create dnssec keys, much like ssh-keygen creates ssh keys. Pick a name for your key, it can be any name. I usually name it appropriately. For this example, I will call our key dhcpupdate.

Create the key as such:
% dnssec-keygen -a hmac-md5 -b 128 -n USER dhcpupdate
Kdhcpupdate.+157+14638
        
This will create a 128bit HMAC-MD5 keyfile called dhcpupdate.

The output is the file prefix. If you do ls Kdhcpupdate* you will see two files. The .key file is most useful, in my opinion. Looking at the .key file:
dhcpupdate. IN KEY 0 3 157 N8Hk2RUFO84bEVl3uGTD2A==
No, that is not the key I use. No, you shouldn't use that key for your server ;)

The last token in that file is the key (N8Hk...). Keep that secret. Forever.

named.conf changes

The updates to named.conf are pretty straightforward. For every zone you want to allow dynamic updates (for this specific key), you need to add an allow-update section. First, you'll want to add a key section. The following goes in the global portion of your named.conf:
key dhcpupdate {
  algorithm hmac-md5;
  secret "YOURKEYGOESHERE";
  # example:
  # secret "N8Hk2RUFO84bEVl3uGTD2A==";
};
Simple enough. Just remember that it goes in quotes!

Next, we need to add allow-update entries to all zones we would like to update. Let's say I have two zones:
  • home
  • 0.168.192.in-addr.arpa
In my named.conf, I'll want to add the following to those zone declarations:
allow-update { key dhcpupdate; };
For example:
zone "home" {
  type master;
  file "master/db-home"
  allow-update { key dhcpupdate; };
};

zone "0.168.192.in-addr.arpa" {
  type master;
  file "master/db-home_rev";
  allow-update { key dhcpupdate; };
};
That's all we have to do. Restart named and you should be able to push updates dynamically to the dns server.

Testing with nsupdate

nsupdate is the tool we'll be using to test if we have setup the server correctly. nsupdate takes commands like nslookup does, if run without arguments:
nightfall(~/t) % nsupdate
> 
The following commands are good to know:
server [server address]
Sets the target server for who to send updates
key [keyname] [secret]
Tell nsupdate what your key is
zone [zonename]
Explicitly choose a zone to send updates for. If unspecified, nsupdate will guess.
update [...]
Request an update to record
send
Send updates
show
Show updates that haven't been sent
update will not update the dns server automatically. It will queue the update request until you tell nsupdate to send.

For this example, my dns server is dns.home:
% nsupdate
> server dns.home
> key dhcpupdate N8Hk2RUFO84bEVl3uGTD2A==
> zone home
> update add 50.0.168.192.in-addr.arpa 600 IN PTR happynode.home.
> send
> update add happynode.home. 600 IN A 192.168.0.50
> send
If all goes well, there will be nothing printed after you type send. Let's check that we've added it!
% host happynode.home
happynode.home has address 192.168.0.50
% host 192.168.0.50
50.0.168.192.in-addr.arpa domain name pointer happynode.home.
You can delete entries from dns with (for example):
update delete happynode.home
However, if something went wrong:
update failed: NOTZONE
You didn't specify a hostname the dns server has zone information for. Make sure you're using a full domain name. That is, do not use happynode. Use happynode.home.
; TSIG error with server: tsig indicates error
update failed: NOTAUTH(BADSIG)
You are providing the wrong key, or the server is refusing your key for another reason?
update failed: SERVFAIL
The number one cause for this error (for me) is permissions in the directory of your zonefile. Dynamic updates will create a journal file as: /etc/namedb/home/home.jnl (or wherever your zonefile is). If the user named is running as cannot create files in /etc/namedb/home then it will fail. This error should show up as 'permission denied' errors in the logs with a reference to what file it is trying to create.
Worst case, run named with a high debug level. Also, don't reload named, restart named when debugging. Reloading doesn't reinitialize some things.

DHCPD

A few minor changes are necesary to your dhcpd.conf (isc dhcp3 server). First, in the global portion:
ddns-update-style interim;

# If you have fixed-address entries you want to use dynamic dns
update-static-leases on;
Furthermore, you need to tell dhcpd.conf about the dnssec key and zone information. The following still goes in your dhcpd.conf:
key dhcpupdate {
  algorithm hmac-mdd5
  secret N8Hk2RUFO84bEVl3uGTD2A==;
}

zone 0.168.192.in-addr.arpa {
  primary dns.home;
  key dhcpupdate;
}

zone 10.168.192.in-addr.arpa {
  primary dns.home;
  key dhcpupdate;
}

zone home {
  primary dns;
  key dhcp_updater;
}
*NOTE!* Notice that the secret is entered WITHOUT QUOTES. Doing so with quotes is a syntax error. If you see errors about invalid base64 characters, this is likely the reason.

The primary values are the primary dns server entries so dhcpd knows where to send updates. In this case, my primary dns is dns.home. Yours will obviously vary, as your key should vary.

Next, I'll show you a few different examples.
Sample entry without fixed-address (roamer)
host happylaptop {
  hardware ethernet 00:0a:39:22:da:39;
  option host-name "happylaptop";
  option domain-name "home";
  ddns-hostname "happylaptop";
  ddns-domain-name "home";
}
When happylaptop requests an address via dhcp, the dhcp server will tell the dns server. Specifically, it will push forward (A) and reverse (PTR) lookup entries. Excellent. Now I can access my laptop from the network without having to lookup, find, or discover it's IP address, becuase I can simply point at happylaptop.home and it resolves to my laptop, wherever it is.
Sample entry set with 'group'
group {
  option domain-name "home";
  ddns-domainname "home";

  host happylaptop {
    hardware ethernet 00:0a:39:22:da:39;
    option host-name "happylaptop";
    ddns-hostname "happylaptop";
  }

  host dellstation  {
    hardware ethernet 00:b1:48:2a:ad:9c;
    option host-name "dellstation";
    ddns-hostname "dellstation";
  }
}
Sample fixed-address
host jukebox {
  hardware ethernet 01:d0:06:b8:68:34;
  fixed-address 192.168.0.5;
  ddns-hostname "jukebox";
  ddns-domain-name "home";
  option host-name "jukebox";
  option domain-name "home";
}
That should be a decent set of examples.

dhcpd.conf caveats

  1. The option, use-host-decl-names does NOTHING (it seems?) to aid in automatic specification of ddns-hostname. This sucks. If you find otherwise, let me know.
  2. You must specify ddns-hostname and ddns-domainame. dhcpd will not "figure it out" if you just specify host-name and domain-name.
  3. I don't know how to get dynamic-generated roamer addresses working, if it's possible. That is, I want to specify a range of roamers in 192.168.0.160/27, and want dhcpd to autogenerate dns names for those based on a given pattern. Possible? Perhaps not.

My example config files

Comments: 25 (view comments)

Permalink: /articles/dynamic-dns-with-dhcp/main
posted at: 02:08


25 responses to 'Dynamic DNS and DHCP - Easy to do, and you'll thank yourself later'

Branko posted at Thu Sep 14 08:41:56 2006...
Hello from Belgrade Serbia

This article help me to solve the problem when I try to  dynamically update the fixed address which dhcp server assigns to the dhcp clients. I used it only for test purposes but I want to solve the problem. In man pages for dhcpd.conf
for update-static-leases flag is said
"It is not recommended because the DHCP server has no way to tell  that  the  update  has  been done, and therefore will not delete the  record when it is notin use." 

Best regards from
Branko Petakovic
Belgrade,Serbia

Joe Terry posted at Sun Sep 17 17:04:37 2006...
Straightforward.  Seems to work for my forward lookups, but will not update reverse .in-addr.arpa addresses.  Thanks for your time.

xuser posted at Fri Sep 22 10:13:22 2006...
I had a problem with updates of direct in reverce DNS zones while both "ddns-domainname" and "option domain-name" was set.
It means that when updating zones both of this things was used....

DDNS posted at Thu Nov 2 10:25:14 2006...
subnet 192.168.0.160 netmask 255.255.255.224 {
range 192.168.0.160 192.168.0.191;
option broadcast-address 192.168.0.255;
option routers 192.168.0.160;
ddns-hostname = concat ("dhcp-", binary-to-ascii (10, 8, "-", leased
address));
}

Jordan Sissel posted at Thu Nov 2 17:24:31 2006...
DDNS,

Thanks! I'll try that at home shortly and update the article to reflect this. I hadn't though about what you suggested :)

James Braid posted at Thu Jan 25 12:19:54 2007...
You can use:

ddns-hostname = host-decl-name;

As a workaround for use-host-decl-name; not working.

Hope that helps someone, the documentation for dynamic DNS updates is pretty lacking I have found.

Frank posted at Sun Mar 18 18:22:22 2007...
I have always the same error in /var/log/messages:

Mar 18 23:18:52 gateway dhcpd: Internet Software Consortium DHCP Server V3.0.1rc13
Mar 18 23:18:52 gateway dhcpd: Copyright 1995-2003 Internet Software Consortium.
Mar 18 23:18:52 gateway dhcpd: All rights reserved.
Mar 18 23:18:52 gateway dhcpd: For info, please visit http://www.isc.org/products/DHCP
Mar 18 23:18:52 gateway dhcpd: Wrote 0 deleted host decls to leases file.
Mar 18 23:18:52 gateway dhcpd: Wrote 0 new dynamic host decls to leases file.
Mar 18 23:18:52 gateway dhcpd: Wrote 3 leases to leases file.
Mar 18 23:18:52 gateway dhcpd: Listening on Socket/eth0/192.168.1.0/24
Mar 18 23:18:52 gateway dhcpd: Sending on  Socket/eth0/192.168.1.0/24
Mar 18 23:18:52 gateway dhcpd: Sending on  Socket/fallback/fallback-net
Mar 18 23:19:03 gateway named[26770]: client 192.168.1.1#32781: updating zone '1.168.192.in-addr.arpa/IN': deleting an rrset
Mar 18 23:19:03 gateway named[26770]: client 192.168.1.1#32781: updating zone '1.168.192.in-addr.arpa/IN': adding an RR
Mar 18 23:19:03 gateway dhcpd: added reverse map from 30.1.168.192.in-addr.arpa to duke.apollo.lokal
Mar 18 23:19:03 gateway dhcpd: DHCPREQUEST for 192.168.1.30 from 00:0c:6e:2b:84:bb via eth0
Mar 18 23:19:03 gateway dhcpd: DHCPACK on 192.168.1.30 to 00:0c:6e:2b:84:bb via eth0
Mar 18 23:19:03 gateway named[26770]: client 192.168.1.30#1431: update 'apollo.lokal/IN' denied

The forward zone update is denied. The machine with 192.168.1.30 is a windows xp host. Is this the problem ? how can i fix the update denied error ?

Thanks in advance
Frank

ajay posted at Fri Jun 22 16:54:23 2007...
I couldn't get nsupdate to work (NOTAUTH) until I moved the "key" definition inside the view.  SO if you're using views, make sure that the key isn't in the "global" space, but the scope for each view that is updating the nameserver.

--Ajay

torsten posted at Wed Jul 4 18:10:26 2007...
Hi Guys

I try to get DDns with DHCP3 and BIND9 runnning for over 4 days now

Is there any way that people would actualy stop fragmenting conf files and hiding internal configurations so that a copy and paste is possible before doing customisations.
The above guide is useless because of fagmented (missing parts) config files and too many comments which are just confusing.
regards
Torsten

Jordan Sissel posted at Wed Jul 4 18:57:48 2007...
@torsten,

The goal of this article wasn't to hide parts of the configuration. The intended audience of this article is for those who are already familiar with BIND and isc-dhcp server and not an introductory reference to either software. That is, this article is no substitute for pulling up references or manpages for these tools.

For what it's worth, I know of many folks who have successfully used this article as reference.

At any rate, I updated the article with the configuration files I use. You'll find them at the bottom of the article.

R.Smits posted at Tue Aug 21 15:35:20 2007...
update-static-leases flag - I know that the dhcp server will not notify the dns server for removal of a ddns (static dhcp) record when this flag is set.
But are you able to CHANGE a record ? (host statement)

robert posted at Thu Oct 18 22:03:28 2007...
The laptop I'm plugging in to my network has its own name (a windows XP laptop) and the MAC address isn't known. How do I get the name of the laptop into the DNS records. Any ideas how to do this?

David L Ballenger posted at Fri Oct 19 08:54:48 2007...
Hi Jordan,

Thanks for the article, it's been a great help at getting started.  I do have one question, is there a way to get dhcpd to update DNS two IP address for one host name?  For exampled, a laptop with with wired and wireless connections both connected? 

I can get it to work with different ddns host names, but with the same name one will overwrite the other if both are interfaces are connected.

Thanks -David

Nick posted at Wed Nov 28 20:38:46 2007...
In dhcpd.conf, the stanza beginning "zone 10.168..", is that a typo?  Should that not be "zone home.."?

Jordan Sissel posted at Thu Nov 29 02:09:30 2007...
Nope, not a typo. I have two /24 networks in my house. 192.168.0/24 is wired, and 192.168.10/24 is wifi.

I forgot to include the 'home' zone in addition to the others. I'll update the page.

Robert posted at Thu Feb 21 07:38:53 2008...
For "Sample fixed-address" to work you have to add a "update-static-leases on;" directive in dhcpd.conf

null posted at Thu Mar 20 06:25:16 2008...
208.67.222.222
206.67.220.220

Tommy posted at Tue Mar 25 12:08:47 2008...
So,how can i get dhcpd to not only:not allow clients to update DNS themselves, but also get the dhcpd server to update the PTR and A records for the client computer, and append the appropriate FQDN for PTR and A records?

Tommy posted at Tue Mar 25 12:10:42 2008...
So,how can i get dhcpd to not only:not allow clients to update DNS themselves, but also get the dhcpd server to update the PTR and A records for the client computer, and append the appropriate FQDN for PTR and A records?

fRANK Miller posted at Wed Apr 30 13:39:21 2008...
I do not want clients to be able to pick their own hostnames. I want to set this in the


host {
}


declaration. How can I do this ? Setting ddns-hostname "myhostname" doesn't seem to work.

Andrew posted at Thu May 8 17:11:05 2008...
I have configuration that seems to be working fine. DNS gets updated both fwd and reverse, but I keep getting this in the logs.

"has an A record but no DHCID, not mine"

When looking at the zone file, it seems some of the A records have a TXT line afterwards with a hex string (The DHCID, I assume), but other do not. It is as if BIND is not adding the DHCID to some records....

egrep posted at Sun Jun 8 17:04:55 2008...
A friend of mine and I want to provide dynamic dns to his father in law's server which is on a dynamic IP. We both run our own authoritative DNS servers on static IPs. He is the master, and I am slave for the domain in question.

We want to configure the dynamic client to update the master DNS server, and this looks like it will work very nicely (thanks!), and then I will receive the slave zone file updates.

Since in-law's server gets it's IP info from his ISP, do we need to do any of the DHCP configurations? This is for updating zone files for a server out on the internet, much liek being our own dynDNS service. We already have an allow-updates set of rules, so we can just embed the key definition as a allowed host instead of the static IP of all the other allowed hosts. Is my thinking correct? -egrep

Andrej posted at Sat Jul 26 15:52:50 2008...
> subnet 192.168.0.160 netmask 255.255.255.224 {
> range 192.168.0.160 192.168.0.191;
> option broadcast-address 192.168.0.255;
> option routers 192.168.0.160;
> ddns-hostname = concat ("dhcp-", binary-to-ascii > (10, 8, "-", leased
> address));
> }

No, this doesn't work. (It is not a legal subnet definition.) Please test your config before you post...

Perhaps it works in a non-standard implementation of dhcpd you might be using. More details about that would be helpful.

Jordan Sissel posted at Sat Jul 26 16:39:57 2008...
WHat about it is illegal? 192.168.0.160 with netmask 255.255.255.224 (/27) seems legal enough.

Jordan Sissel posted at Sat Jul 26 16:42:15 2008...
I tried that in my dhcpd.conf, and it worked fine.
subnet 192.168.0.160 netmask 255.255.255.224 {
range 192.168.0.160 192.168.0.191;
option broadcast-address 192.168.0.255;
option routers 192.168.0.160;
ddns-hostname = concat ("dhcp-", binary-to-ascii (10, 8, "-", leased-address));
}


Works just fine! :)


Leave a reply

You need javascript enabled to use this form. Anti-spam efforts ongoing. Also, if the comment doesn't show up, it's because the form expired. Go back and copy your comment, reload the form, and resubmit. Apologies if this is a hassle, I'm just playing with antispam methods right now. If this insists on not working, please email me about it.

Name (required)
E-mail (optional, if you want me to be able to email you back)
URL (also optional)
Comment:


Search this site

Navigation

Metadata

Home About Resume My Code (SVN)

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials

Tag Cloud

Calendar

< November 2007 >
SuMoTuWeThFrSa
     1 2 3
4 5 6 7 8 910
11121314151617
18192021222324
252627282930 

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati