Adding DNS entries with command line on Windows

If you are lazy (as we are) or you don’t want to waste all your time adding DNS entries manually, you can use dnscmd via command line on Windows. It’s a nice way to put a large entries from a file or something that needs further configuration.

PROMPT> dnscmd help
dnscmd yourdnsserver /RecordAdd mynewrecord A ip
(creates that points to
dnscmd localhost /RecordAdd ftp A

(creates that points to
dnscmd localhost /RecordAdd www A

You can use A, CNAME, PTR, TXT etc.

An example of a batch file putting entries in the same IP using loops.

PROMPT> type records.txt
etc …

type dns.bat
@echo off

set dnshost=localhost
set type=A (dns type, PTR, CNAME etc)
set ipserver=

echo “We are reading line by line records.txt”
for /f %%record in (records.txt) do dnscmd %dnshost% /RecordAdd %domain% %%record %type% %ipserver%

See you!

Leave a comment