{"id":21,"date":"2015-03-06T08:13:15","date_gmt":"2015-03-06T13:13:15","guid":{"rendered":"http:\/\/blog.voipxswitch.com\/?p=21"},"modified":"2015-03-27T08:36:01","modified_gmt":"2015-03-27T12:36:01","slug":"syncing-dns-zones-from-windows-dns-server-to-linux-bind9-dns-server","status":"publish","type":"post","link":"https:\/\/blog.voipxswitch.com\/?p=21","title":{"rendered":"Syncing DNS Zones from Windows DNS Server to Linux Bind9 DNS Server"},"content":{"rendered":"<h3>Windows Setup<\/h3>\n<p>First step is to dump the DNS zones from Windows into a file. Then generate an FTP command file which will upload the DNS zone file dump to your bind server. I&#8217;ve created a batch script to handle all of this:<\/p>\n<blockquote class=\"tr_bq\">\n<pre><span style=\"font-family: 'Courier New',Courier,monospace;\">@echo off\r\ndnscmd \/enumzones &gt; dns.zones.txt\r\necho user ftp_bind_user&gt; ftpcmd.dat\r\necho ftp_bind_password&gt;&gt; ftpcmd.dat\r\necho bin&gt;&gt; ftpcmd.dat\r\necho put dns.zones.txt&gt;&gt; ftpcmd.dat\r\necho quit&gt;&gt; ftpcmd.dat\r\nftp -n -s:ftpcmd.dat 192.168.1.101\r\ndel ftpcmd.dat\r\ndel dns.zones.txt<\/span><\/pre>\n<\/blockquote>\n<p>Some notes about the above script:<\/p>\n<blockquote class=\"tr_bq\"><p><b>192.168.1.101<\/b> is the bind9 server&#8217;s IP address.<\/p>\n<p><b>ftp_bind_user<\/b> is the ftp user name setup on the bind9 server<\/p>\n<p><b>ftp_bind_password<\/b> is the ftp password setup on the bind9 server<\/p><\/blockquote>\n<p>I have this batch script run every hour, on the hour, using the Window task scheduler. This script will most likely need to run as an administrator in order to dump the DNS zones to a file.<\/p>\n<h3>Linux Setup<\/h3>\n<p>Now we setup the bash script. This script will first parse and format dns.zones.txt into a usable bind format, then it will scan all the current zone files and remove any that are not listed in the updated zone file. I set this script to run every hour, ten minutes after each hour. This script assumes you have bind running as user &#8220;bind&#8221; in group &#8220;bind&#8221;, please change the chown line accordingly.<\/p>\n<blockquote class=\"tr_bq\">\n<pre><span style=\"font-family: 'Courier New',Courier,monospace;\">#!\/bin\/bash\r\n\r\n<\/span>ZONE_PATH=\"\/home\/bind\"\r\nBIND_PATH=\"\/var\/lib\/bind\"\r\nTMP=$(mktemp)\r\nFC=\"dns.zones.txt\"\r\n\r\nfor ZONE in $(awk '$2==\"Primary\" {print $1}' \"${ZONE_PATH}\/${FC}\") do\r\n   printf \"zone ${ZONE} {\\n\\ttype slave;\\n\\tmasters { 192.168.1.100; };\\n\\tfile \\\"${BIND_PATH}\/${ZONE}.zone\\\";\\n};\\n\"\r\ndone &gt; ${TMP}\r\n\r\nfor ZONE in \"$BIND_PATH\"\/*.zone do\r\n   grep -q \"${ZONE}\" \"${TMP}\" || rm -rf \"${ZONE}\"\r\ndone\r\n\r\nmv ${TMP} \/etc\/bind\/named.conf.slave-zones\r\nchown bind:bind \/etc\/bind\/named.conf.slave-zones\r\n\r\nrndc reload<\/pre>\n<\/blockquote>\n<p>Some notes about the above script:<\/p>\n<blockquote class=\"tr_bq\"><p><b>ZONE_PATH<\/b> is where the dns.zones.txt file is uploaded to, this is of course determined by your FTP server setup (I setup proftpd with SQL backend, but you could easily setup vsftpd)<\/p>\n<p><b>BIND_PATH<\/b> is where we are telling bind to store the zone files.<\/p>\n<p><b>192.168.1.100<\/b> is the IP Address of the Windows DNS Server<\/p>\n<p><b>\/etc\/bind\/named.conf.slave-zones<\/b> is setup to be included in the &#8220;named.conf&#8221; file with the line:<\/p>\n<p>include &#8220;\/etc\/bind\/named.conf.slave-zones&#8221;;<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Windows Setup First step is to dump the DNS zones from Windows into a file. Then generate an FTP command file which will upload the DNS zone file dump to your bind server. I&#8217;ve created a batch script to handle all of this: @echo off dnscmd \/enumzones &gt; dns.zones.txt echo user ftp_bind_user&gt; ftpcmd.dat echo ftp_bind_password&gt;&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-21","post","type-post","status-publish","format-standard","hentry","category-dns"],"_links":{"self":[{"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=\/wp\/v2\/posts\/21","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=21"}],"version-history":[{"count":6,"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":27,"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=\/wp\/v2\/posts\/21\/revisions\/27"}],"wp:attachment":[{"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}