Skip to content

Microsoft DNS Replication


HOWTO: Sync secondary and primary DNS or setup new secondary DNS


 

HELM restore tool uses HELM’s database to handle DNS zones. So if you have any zone settings outside HELM, my experience might come handy.

This is for MSDNS only.

1.) I always setup MSDNS to use files, not registry, because files are much easier to migrate and make backup.
To set MSDNS to use DNS zone files only, right click you server in DNS console, select Properties -> Advanced and set "Load zone data on startup" = From File
Then restart DNS
2.) If you want to setup your new SECONDARY DNS, this script might come handy. It scans your primary DNS and copies all zones to secondary DNS server. It also secures zone transfer settings to allow transfers only to servers, listed in NS tab, with automatic notify option, so secondary’s are updated almost in real time.

Script copyToSecondary.bat

Code:

@echo off
SET DNSCMDPATH="C:\Program Files\WebHost Automation\Helm\System\dnscmd.exe"
echo.
echo ###############################################################################
echo #                                                                             #
echo #                        MSDNS copy zone utility                              #
echo #                  Copyright 2006 Labsy @ seznam DOT org                      #
echo #                                                                             #
echo ###############################################################################
echo.

IF NOT EXIST %DNSCMDPATH% (
ECHO ERROR: dnscmd.exe not found in given path:
echo %DNSCMDPATH%
echo.
echo Please, install Windows Server Admin pack or get dnscmd.exe elsewhere
echo and update DNSCMDPATH in this script accordingly.
echo.
)
IF NOT "%1"=="/?" IF NOT "%1"=="/h" IF NOT "%1"=="?" GOTO skiphelp

echo This batch will copy PRIMARY DNS zones to SECONDARY server or repair primary.
echo It scans all PRIMARY FORWARD zones on this machine and then creates apropriate
echo SECONDARY zones on given secondary server.
echo.
echo This tool is very handy when setting up new secondary DNS servers.
echo.
echo IMPORTANT:
echo It works ONLY FOR MSDNS server!
echo You must have "dnscmd" utility installed. It is part of server admin pack. 
echo Before first usage edit this file and set PATH to dnscmd in this script!
echo.
echo USAGE:
echo    copyToSecondary [SecName/IP] [SecDns] [PriIP] (optionally [DomainName])
echo    copyToSecondary [PriName/IP] updatemaster
echo where
echo    [SecName/IP] = Secondary Server NetBios Name or local IP (eg: ENGINE1)
echo    [SecDns]     = Secondary Server Dns Name (eg: ns1.domain.com)
echo    [PriIP]      = Primary DNS Server IP. This will be set as master DNS
echo    [DomainName] = Optional parameter, domain name for single zone transfer
echo.
echo    when used with "updatemaster" parameter
echo    [PriName/IP] = Primary DNS NEtBios name or IP
echo.
echo EXAMPLES:
echo To copy all zones from primary 123.123.123.123 to secondary SERVER5 (ns5):
echo.
echo    copyToSecondary SERVER5 ns5.domain.com 123.123.123.123
echo. 
echo Same as above, but just for one particular domain:
echo.
echo    copyToSecondary SERVER5 ns5.domain.com 123.123.123.123 foobar.com
echo.
echo To update only master DNS and repair Zone transfer and notify settings:
echo (this will set AllowUpdate to servers listed in NS tab, and set to AutoNotify)
echo.
echo    copyToSecondary MASTER1 updatemaster
echo. 
echo ###############################################################################
echo.
goto END
:skiphelp

echo IMPORTANT!
echo This script can modify your DNS server settings, so BE SURE you have BACKUP!
echo Press CTRL+C to stop and make BACKUP of your DNS zones first!
pause

IF NOT "%2"=="updatemaster" GOTO normal
if NOT "%1"=="" %DNSCMDPATH% %1 /EnumZones /Forward>allzones.txt
ECHO #----------------------------- PRIMARY UPDATE --------------------------------#
ECHO #                                  START                                      #
if NOT "%1"=="" FOR /f %%D IN (allzones.txt) DO (
IF NOT "%%D" == "Enumerated" IF NOT "%%D" == "Zone" IF NOT "%%D" == "." IF NOT "%%D" == "Command" (

ECHO  Updating master DNS for %%D ...
%DNSCMDPATH% %1 /ZoneResetSecondaries %%D /securens /notify
)
)
GOTO END
:normal
if NOT "%1"=="" %DNSCMDPATH% %1 /EnumZones /Forward>allzones.txt
if NOT "%4"=="" GOTO SINGLE
if NOT "%2"=="" FOR /f %%D IN (allzones.txt) DO (
IF NOT "%%D" == "Enumerated" IF NOT "%%D" == "Zone" IF NOT "%%D" == "." IF NOT "%%D" == "Command" (
ECHO #---------------------------- BULK ZONE UPDATE -------------------------------#
ECHO #                                 START                                       #

ECHO Processing zone %%D... 

ECHO  Adding %2 as DNS server on primary...
%DNSCMDPATH% %3 /RecordAdd %%D "@" NS %2

ECHO  Set Allow only secure zone transfers with autonotify on primary...
%DNSCMDPATH% %3 /ZoneResetSecondaries %%D /securens /notify

ECHO  Transfering zone %%D to %2... 
%DNSCMDPATH% %1 /ZoneAdd %%D /Secondary %3 /file %%D.dns

ECHO #----------------------------------- END -------------------------------------#
)
)
GOTO END
REM C:\Program Files\WebHost Automation\Helm\System\dnscmd 81.29.69.137 /RecordAdd gradteater.com "@" NS ns5.hostmachine.net

:SINGLE
if "%4"=="" goto END
ECHO #---------------------------------- START ------------------------------------#
ECHO Processing zone %4... 
ECHO Adding %2 as DNS server on primary...
%DNSCMDPATH% %3 /RecordAdd %4 "@" NS %2

ECHO  Set Allow only secure zone transfers with autonotify on primary...
%DNSCMDPATH% %3 /ZoneResetSecondaries %4 /securens /notify

ECHO Transfering zone %4 to %2... 
%DNSCMDPATH% %1 /ZoneAdd %4 /Secondary %3 /file %4.dns

ECHO #----------------------------------- END -------------------------------------#

:END
SET DNSCMDPATH=
echo.

 

Requirements for this script to work:

– secondary DNS must run MSDNS server

– secondary DNS must be inside local network (either LAN, either via VPN)

– you must run this script with Admin user, which has Admin privileges on both, primary and secondary server (I run it as HELM_ADMIN)

Do not forget to make a BACKUP of your DNS zone files before you go playing with this script!

2 Comments Post a comment
  1. We are a bunch of volunteers and opening a brand new scheme in our community.
    Your site provided us with useful information to work on.
    You have performed a formidable process and our entire
    group might be thankful to you.

    2013/07/16
  2. Hi there! I knpw this is somewat off-topic however I needed to ask.
    Does managing a well-established website such as yours
    take a large amount of work? I’m completely new to running a blog however I do write in my diary every
    day. I’d like to start a blog so I can share my experience and feelings
    online. Please leet me know if you have any suggestins or tips
    for brand new aspiring blog owners. Appreciate it!

    2013/09/21

Leave a comment