{"id":237,"date":"2006-12-21T03:41:17","date_gmt":"2006-12-21T00:41:17","guid":{"rendered":"http:\/\/www.void.gr\/kargig\/blog\/?p=237"},"modified":"2008-06-06T01:29:24","modified_gmt":"2008-06-05T22:29:24","slug":"dynamic-hostname-updates-with-dhcpd-bind","status":"publish","type":"post","link":"https:\/\/www.void.gr\/kargig\/blog\/2006\/12\/21\/dynamic-hostname-updates-with-dhcpd-bind\/","title":{"rendered":"dynamic hostname updates with DHCPd + BIND"},"content":{"rendered":"<p>The following text describes the way to make DHCPd create DNS records of dhcp clients. This scenario is usually called a DDNS server.<\/p>\n<p>We will first setup up BIND and then DHCPd.<br \/>\n1) We need to create a &#8220;key&#8221;. A key is a password that allows dhcpd to update bind&#8230; imagine something like an authentication scheme. In order to create such a key file to the following:<br \/>\n<code># rndc-confgen -a<\/code><br \/>\nA key file will be created. On Gentoo Linux this file is put inside \/etc\/bind\/ and is called &#8220;rndc.key&#8221;.<br \/>\nNow open up your named.conf file and put these line inside:<br \/>\n<code>include \"\/etc\/bind\/rndc.key\";<br \/>\ncontrols {<br \/>\ninet 127.0.0.1 allow { localhost; } keys { rndc-key; };<br \/>\n};<br \/>\n<\/code><br \/>\nIf you already have a controls section just modify it to include the keys { }  directive.<\/p>\n<p>Now, in your zones that you want to be dynamically updated modify them to look like this:<\/p>\n<p><code>zone \"0.168.192.in-addr.arpa\" {<br \/>\n        type master;<br \/>\n        file \"pri\/192.168.0.zone\";<br \/>\n        allow-update { key \"rndc-key\"; };<br \/>\n        notify yes;<br \/>\n};<br \/>\nzone \"home-sweet-home.gr\" {<br \/>\n        type master;<br \/>\n        file \"pri\/home-sweet-home.gr.zone\";<br \/>\n        allow-update { key \"rndc-key\"; };<br \/>\n        notify yes;<br \/>\n};<br \/>\n<\/code><\/p>\n<p>The &#8220;allow-update&#8221; is the crucial part here.<br \/>\nIf you&#8217;ve done that changes we are finished from the BIND configuration. Restart the service and you are done.<\/p>\n<p>2)Time for DHCPd configuration.<br \/>\nRemember your rndc-key file ? Open it and paste it contents inside your dhcpd.conf file so it looks a bit like this:<br \/>\n<code>key \"rndc-key\" {<br \/>\nalgorithm hmac-md5;<br \/>\nsecret \"goa6aw7a9WwapCyai0naZQ==\";<br \/>\n};<\/code><\/p>\n<p>Among others you have to put the zone files that you want to be updated. Following my previous zone declaration in named.conf and supposing that the primary nameserver is 192.168.0.50, that should be:<br \/>\n<code><br \/>\nzone home-sweet-home.gr {<br \/>\nprimary 192.168.0.50;<br \/>\nkey rndc-key;<br \/>\n}<br \/>\nzone 0.168.192.in-addr.arpa. {<br \/>\nprimary 192.168.0.50;<br \/>\nkey rndc-key;<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Now some generic configuration stuff to allow dynamic dns updates:<br \/>\n<code><br \/>\nddns-update-style interim;<br \/>\nddns-domainname \"home-sweet-home.gr.\";<br \/>\nuse-host-decl-names on;<br \/>\nallow client-updates;<br \/>\noption oe-key     code 159 = string;<br \/>\noption oe-gateway code 160 = ip-address;<br \/>\non commit {<br \/>\n  if (not static and<br \/>\n      ((config-option server.ddns-updates = null) or<br \/>\n       (config-option server.ddns-updates != 0))) {<br \/>\n      if exists oe-key {<br \/>\n        set ddns-rev-name =<br \/>\n           concat (binary-to-ascii (10, 8, \".\",<br \/>\n                                     reverse (1, leased-address)), \".\",<br \/>\n                    pick (config-option server.ddns-rev-domainname,<br \/>\n                          \"in-addr.arpa.\"));<br \/>\n        set full-oe-key = option oe-key;<br \/>\n        switch (ns-update (delete (IN, 25, ddns-rev-name, null),<br \/>\n                            add (IN, 25, ddns-rev-name, full-oe-key,<br \/>\n                                lease-time \/ 2)))<br \/>\n        {<br \/>\n        default:<br \/>\n          unset ddns-rev-name;<br \/>\n          break;<br \/>\n        case NOERROR:<br \/>\n          on release or expiry {<br \/>\n            switch (ns-update (delete (IN, 25, ddns-rev-name, null))) {<br \/>\n            case NOERROR:<br \/>\n              unset ddns-rev-name;<br \/>\n              break;<br \/>\n            }<br \/>\n          }<br \/>\n        }<br \/>\n      }<br \/>\n  }<br \/>\n}<br \/>\n<\/code><br \/>\n(weird huh ? Nope that&#8217;s not mine &#8230; I just copied it from someplace on the web)<\/p>\n<p>I will now show you my subnet configuration. Change it to fit your needs:<br \/>\n<code><br \/>\nsubnet 192.168.0.1 netmask 255.255.255.0 {<br \/>\n  range 192.168.0.100 192.168.0.200;<br \/>\n  option domain-name-servers 192.168.0.50;<br \/>\n  option domain-name \"home-sweet-home.gr\";<br \/>\n  option routers 192.168.0.10;<br \/>\n  default-lease-time 600;<br \/>\n  max-lease-time 7200;<br \/>\n  update-static-leases on;<br \/>\n  host PC1 {<br \/>\n  hardware ethernet 00:12:34:56:78:ab;<br \/>\n  fixed-address 192.168.0.21;<br \/>\n  option host-name \"PC1\";<br \/>\n  DDNS-hostname \"PC1\";<br \/>\n  }<br \/>\n}<br \/>\n<\/code><\/p>\n<p>With this configuration, all clients on the subnet will be given IP addresses in the range 192.168.0.100 &#8211; 192.168.0.200, except from the PC with MAC address 00:12:34:56:78:ab that will be given IP 192.168.0.21.  The &#8221; update-static-leases on;&#8221; is very important for PC1. Unless it is defined no updates to DNS records would be created for it. <\/p>\n<p>Now restart DHCPd, make a client DHCP request and check your log file (\/var\/log\/messages probably) for the results.<\/p>\n<p>You can read more about the ddns server subject at the following places:<br \/>\nhttp:\/\/kristijan.org\/?q=node\/69<br \/>\nhttp:\/\/alex.kruijff.org\/FreeBSD\/Dynamic_DNS.html<br \/>\nhttp:\/\/www.ops.ietf.org\/dns\/dynupd\/secure-ddns-howto.html<br \/>\nhttp:\/\/www.southwestern.edu\/pipermail\/netreg\/2005-October\/001074.html<\/p>\n<p>It&#8217;s quite usefull if you have a need for it \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following text describes the way to make DHCPd create DNS records of dhcp clients. This scenario is usually called a DDNS server. We will first setup up BIND and then DHCPd. 1) We need to create a &#8220;key&#8221;. A key is a password that allows dhcpd to update bind&#8230; imagine something like an authentication [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"footnotes":""},"categories":[12,3,8],"tags":[],"class_list":["post-237","post","type-post","status-publish","format-standard","hentry","category-gentoo","category-linux","category-networking"],"aioseo_notices":[],"views":37187,"_links":{"self":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/comments?post=237"}],"version-history":[{"count":0,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/237\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/media?parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/categories?post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/tags?post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}