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!


9 thoughts on “Adding DNS entries with command line on Windows

  1. Hi All,

    I need help on this. I need to ADD a SYSTEM DNS from a Command Prompt.

    And the DNS uses a driver Microsoft Access Driver (*.MDB).

    Please Need your help.


  2. Good job! I used this to determine the reverselookup-addresses of PCs in our network. The Netbiosname is vt1-05,

    Add a CNAME (=alias)
    dnscmd localhost /RecordAdd pc-richard CNAME

    Change a reverselookup:

    # delete old record
    # ip: _only_ the last number -> 5
    dnscmd localhost /RecordDelete 5 PTR /f
    dnscmd localhost /RecordAdd 5 PTR

  3. Thanks for the info!
    Once I started playing around with this, I found it a little smoother if I had the contents of the text file as host and ip, ie:
    host1 ip1
    host2 ip2

    and then slightly modified the batch file to be:
    FOR /f “tokens=1,2” %a IN (records.txt) DO dnscmd localhost /RecordAdd %domain% %a %type% %b

    Hope this comes in handy for others!

    Thanks again,

    • typo in my FOR line above (it’ll work on command line but not embedded in a batch file)… should have double %’s in front of a and b:
      FOR /f “tokens=1,2” %%a IN (records.txt) DO dnscmd localhost /RecordAdd %domain% %%a %type% %%b

  4. I knew this would be possible. Day after day I have to use public IP’s for remote management and it gets tedious! this way I can just add memorable names to the IP’s saving me a load of hassle. Great article, very well laid out and demo’d.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s