{"id":61,"date":"2011-08-06T10:19:38","date_gmt":"2011-08-06T09:19:38","guid":{"rendered":"http:\/\/www.simweb.ch\/blog\/?p=61"},"modified":"2011-08-06T10:33:39","modified_gmt":"2011-08-06T09:33:39","slug":"bind-nsd-zone-files-explained","status":"publish","type":"post","link":"https:\/\/www.simweb.ch\/blog\/2011\/08\/bind-nsd-zone-files-explained\/","title":{"rendered":"BIND \/ NSD zone files explained"},"content":{"rendered":"<p>At work there was a old physical Windows who run DNS for several small domains I got the job of transfering the DNS zones to a NSD server on a Linux VM - with lower memory footprint. I was able to transfer the zones either by copying and fixing the Window zone files (need to be fixed anyway) from C:\\Windows\\system32\\dns\\foo.ch.dns or by using dig if you can't copy zone files but the remote DNS allows zone transfer:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">dig @OriginatingNS myawesomedomain.com AXFR &gt; myawesomedomain.com.zone<\/pre>\n<pre class=\"brush: bash; gutter: true; first-line: 1\"><\/pre>\n<p>I've been used to edit zone files manually on my private BIND and\u00a0 NSD - while it compiles its own DB to be faster: It's the same source format. But my knowhow got a bit rusty on that topic and I learned I can write less to get the same result. (less repetitive and error prone). A big thanks goes to the helping hands in #DNS on the freenode IRC, who helped me to get back in the seat and fix the strangenesses of the Windows zones and refactor the stuff .<\/p>\n<p>If you have to cleanup a zone file anyway I hope this commented sample gives you some ideas:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">;\r\n; Zone file for foo.ch\r\n;\r\n\r\n$ORIGIN foo.ch.\r\n$TTL 86400\r\n\r\n@ IN SOA ns1.foo.ch. hostmaster.foo.ch. (\r\n40 ; serial number\r\n21600 ; refresh\r\n7200 ; retry\r\n691200 ; expire\r\n86400 ) ; default TTL\r\n\r\n; NS\r\nNS ns1.otherdomain.ch.\r\nNS ns2.otherdomain.ch.\r\n\r\n; MX\r\nMX 10 mySMTP\r\nMX 10 externalSMTP.null.ch.\r\n\r\n; A\r\n     A &lt;IP&gt;\r\nsub1 A &lt;IP&gt;\r\nsub2 A &lt;IP&gt;\r\n\r\n; CNAME\r\nwww2 CNAME @\r\nwww2 CNAME sub1\r\nwww1 CNAME www.null.ch.<\/pre>\n<h4 class=\"brush: actionscript3; gutter: true; first-line: 1\">Explanations<\/h4>\n<p class=\"brush: actionscript3; gutter: true; first-line: 1\"><strong>About the SOA record:<\/strong> There are people who know better about TTL and other settings. But more about the mail address you put in the zone file: RFC2142 says hostmaster@domain should exist (or forwarded) to someone on charge for this DNS zone. You can put any other valid address but the RFC strongly encourages you to have hostmaster@domain available for commidity. (as is postmaser@domain btw)<\/p>\n<p class=\"brush: actionscript3; gutter: true; first-line: 1\">If you do it manually, I'd recommend using a zone serial of YYYYMMDD01, I read that in some BIND book, I hope this is still valid.<\/p>\n<p class=\"brush: actionscript3; gutter: true; first-line: 1\"><strong>Shorter entries<\/strong><\/p>\n<p class=\"brush: actionscript3; gutter: true; first-line: 1\">By adding a $ORIGIN variable (don't forget to a \".\" at the end)\u00a0 you can already write less. Here is acorrect but long example (i.e. via AXFR from dig):<\/p>\n<pre class=\"brush: actionscript3; gutter: true; first-line: 1\">foo.ch       86400 IN A &lt;IP&gt;\r\nsub1.foo.ch. 86400 IN A &lt;IP&gt;<\/pre>\n<p class=\"brush: actionscript3; gutter: true; first-line: 1\">Short but sufficient if $TTL and $ORIGIN set:<\/p>\n<pre class=\"brush: actionscript3; gutter: true; first-line: 1\">@    A &lt;IP&gt;\r\nsub1 A &lt;IP&gt;<\/pre>\n<p class=\"brush: actionscript3; gutter: true; first-line: 1\">Explanation: @ uses $ORIGIN variable and replaces it, $TTL\u00a0 is also inserted automatically without mentioning it and IN can be left out as it seems to <a href=\"http:\/\/www.zytrax.com\/books\/dns\/ch8\/soa.html\">be automatically assumed of not present<\/a>. For A records pointing to foo.ch you can even leave out the @, it's also sufficient:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">A &lt;IP&gt;<\/pre>\n<p class=\"brush: actionscript3; gutter: true; first-line: 1\">With CNAMEs you can also use the @ if the A record is pointing to foo.ch:<\/p>\n<pre class=\"brush: actionscript3; gutter: true; first-line: 1\">demo CNAME @\r\n     CNAME @<\/pre>\n<p class=\"brush: actionscript3; gutter: true; first-line: 1\">Be warned this one won't work:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">demo CNAME<\/pre>\n<p class=\"brush: actionscript3; gutter: true; first-line: 1\">If you have external names, let's say you don't operate your own MX, you can add this entry ending with the FQDN completed with \".\"<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At work there was a old physical Windows who run DNS for several small domains I got the job of transfering the DNS zones to a NSD server on a Linux VM &#8211; with lower memory footprint. I was able to transfer the zones either by copying and fixing the Window zone files (need to &#8230; <a class=\"moretag\" href=\"https:\/\/www.simweb.ch\/blog\/2011\/08\/bind-nsd-zone-files-explained\/\">more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[11,9,10],"class_list":["post-61","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-bind","tag-dns","tag-nsd"],"_links":{"self":[{"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/posts\/61","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/comments?post=61"}],"version-history":[{"count":0,"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/posts\/61\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/media?parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/categories?post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/tags?post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}