static dns entries via script

Sometimes you have do add static DNS names to IP addresses. For Example all your network equipment, switches routers … are mostly not able to register themselves into Windows DNS.

I had a similar problem. I hat a lot of Linux servers and cisco equipment that need to have an DNS name for my NMS.
I looked for an solution and found a solution on: Tools4net

With an simple batch script I can add now all my equipment to all my Windows DNS Servers

First you need you host file named hosts_import.txt:


Further you need the script:

@echo on
set SRV=nmsaddc.nbs-nms.local
set FZONE=nbs-nms.local
set RZONE=
set IN=hosts_import.txt

echo exists hosts_import.txt within the following structure ...
choice /c jn /m "Hostname;IP-Adresse ?"
if errorlevel 2 goto exit

echo .
echo "read %IN% and create A records ..."
for /f "tokens=1-2 delims=;" %%a in (%IN%) do (
echo %%a %%b
dnscmd %SRV% /RecordAdd %FZONE% %%a A %%b >> Add2DNS_A.log)

echo "read %IN% and create PTR records ..."
for /f "tokens=1-2 delims=;" %%a in (%IN%) do (
echo %%b %%a
for /f "tokens=3,4 delims=." %%e in ('echo %%b') do (
dnscmd %SRV% /RecordAdd %RZONE% %%f.%%e PTR %%a.%FZONE% >> Add2DNS_PTR.log



Now simply run the script and check the log files.

If you want to try vbscript: activexperts

Leave a Reply

Your email address will not be published. Required fields are marked *