DNS Export/Import


Exporting / Importing Standard DNS zone records are relatively easy; just copy the zone (eg. orange.com.dns) files from existing server (C:\WINDOWS\system32\dns) and place these .dns files in the same location (C:\WINDOWS\system32\dns) in the target (new) server, restart the DNS service and you are done.

Note: if you are hosting mix DNS record (AD and Standard) then copy zone file may not work. Your need to create empty primary standard domain in forward lookup zone and open this zone file from C:\WINDOWS\system32\dns and copy the contents from the source .dns file and reload or restart the dns server for refresh. .

Exporting AD Integrated DNS zone records:

Generally exporting AD DNS to files is recording purpose. We can build a new DNS server and all these record will be replicated.

Step 1. Mouse right click on the every zone record and click on

Export list….


Alternative (using dnscmd command)

F.Y.I – DNSCMD comes with the Windows Support Tools.

  1. C:\> dnscmd DNSSERVERNAME /ZoneExport orage.com dns.txt
    Note: above command doesn’t take alternative path for export file eg. > c:\dns.txt

Output:

DNS Server PMGDC exported zone

orage.com to file %windir%\system32\dns\dns.txt on the DNS server

Command completed successfully.

  1. dnscmd servername /enumrecords zonename @ /type A /detail > c:\filename.txt

.servername: your DNS server name eg. myDNS
.zonename: orange.com

Export DNS zones:
Run REGEDIT and navigate to: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\DNS Server\Zones (Right-Click the key ZONES and export to a .reg file). 

Alternatively, use command line: regedit /e c:\dns.reg “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\DNS Server”

Now copy *.dns from: %windir%\system32\dns
Note: you can put above regedit /e command to script and run as task to backup schedule time. Skip cache.dns as this contains cached DNS lookups.

Import DNS zones:
To import on Server 2003 or Server 2008, first create a test zone such as testdomain.com. The DNS server needs one zone created, but you can remove it after the import.

Copy the .DNS files into %windir%\system32\dns on the new (target) server. 

Next double click on the .reg file you created to load all the zones into the new server’s registry (For Windows 2008: Right click the reg. file and run as Administrator) 

Now, restart the DNS Server service and open the DNS manager. You are done.


Other references:

Migrate AD DNS to windows 2008 R2 using windows migration tools:

http://technet.microsoft.com/en-us/library/dd379558(WS.10).aspx

DNS dump

http://dns.measurement-factory.com/tools/dnsdump/

http://dns.measurement-factory.com/tools/dnsdump/src/

Script:

Script name: dnstohtml.bat

Following script export standard primary zone file and show in HTML:

————

@ECHO OFF

TITLE DNS Dump to HTML

ECHO.

ECHO.

SETLOCAL EnableDelayedExpansion

REM Directory where the HTML pages should be generated.

SET OutPath=C:\dns

SET HTMLPage=index.html

REM HTML page title/header.

SET Title=DNS Records

REM Delete DNS record files which are not currently loaded in the DNS server (1=Yes, 0=No)

SET DeleteNotFound=0

DEL /Q “%OutPath%\*”

SET OutFile=”%OutPath%\%HTMLPage%”

REM HTML header info. Customize as needed.

ECHO ^<HTML^> >> %OutFile%

ECHO ^<HEAD^> >> %OutFile%

ECHO ^<TITLE^>%Title%^</TITLE^> >> %OutFile%

ECHO ^</HEAD^> >> %OutFile%

ECHO ^<BODY^> >> %OutFile%

ECHO ^<H1^>%Title%^<H1^> >> %OutFile%

ECHO ^<H3^>Machine Name: %ComputerName%^</H3^> >> %OutFile%

ECHO ^<H5^>Generated on: %Date% %Time%^</H5^> >> %OutFile%

SET DNSDir=%WinDir%\system32\dns

FOR /F %%A IN (‘DIR /A:-D /B /L %DNSDir%\*.dns’) DO (

    SET Zone=%%A

    SET Zone=!Zone:.dns=!

    SET ZoneFile=!Zone!.dns.zone.txt


    ECHO Exporting: !Zone!

    DNSCmd . /ZoneExport !Zone! !ZoneFile!


    IF NOT EXIST %DNSDir%\!ZoneFile! (

        ECHO !Zone! is not currently loaded in DNS Server.

        IF {%DeleteNotFound%}=={1} DEL /F /Q %DNSDir%\%%A

    ) ELSE (

        ECHO ^<A HREF=”!ZoneFile!”^>!Zone!^</A^>^<BR/^> >> %OutFile%

        REM Output is always to DNS directory, so move the file to the HTML dir.

        MOVE /Y %DNSDir%\!ZoneFile! “%OutPath%\!ZoneFile!”

    )

    ECHO.

)

ECHO ^<BR/^> >> %OutFile%

ECHO ^</BODY^> >> %OutFile%

ECHO ^</HTML^> >> %OutFile%

ENDLOCAL

@ECHO OFF

Advertisements

About Robiul

Robiul has 15 years of continuous successful career experience in ICT with extensive background in System Engineering, IT infrastructure design, operations and service delivery, managing IT projects / MIS functions for local and multi-national companies with in-depth knowledge of multiple operating systems as well as construct / manage small to medium size Data Center. Proven ability to design and implement medium to semi-large scale LAN/WAN/WLAN and system infrastructures. Academic qualification: Master of Science in Information Systems. Professional certifications are: MCSE, CCNA, ITIL and FoundStone Security Professional, VCP, NetAPP, CISSP etc.
This entry was posted in Windows and tagged . Bookmark the permalink.