SkillPilotAI

dnscmd (1/2)

dnscmd is the command-line tool of Microsoft DNS Server: it manages zones, records, forwarders and the cache of a local or remote server. This part covers the server, forwarders, records and zones, with a BIND 9 (rndc, nsupdate, dig) lab showing the same ideas on Linux.

203.1 Why is it used?

  • Script DNS changes (records, zones, forwarders) instead of clicking through DNS Manager.
  • Manage a remote DNS server by FQDN or IP; no name = the local server.
  • Troubleshoot: read settings and statistics, clear a stale cache, check zone transfers.
  • Comes with the DNS Server role or RSAT (admin rights); new scripts should use the DnsServer PowerShell module.
  • On Linux the equivalent is BIND 9 with rndc, not dnscmd.

203.2 How it works

dnscmd -> DNS Server service -> forwarders
  1. 1.Admin PC runs dnscmd dnssvr1 /info

  2. 2.Request goes over RPC to the DNS Server service on dnssvr1.contoso.com

  3. 3.Service sends the settings back (no server name = local server)

  4. 4.Client (192.168.10.20) asks for a name that is in no zone

  5. 5.Server forwards it to the forwarders (8.8.8.8, 1.1.1.1) and caches the answer

203.3 Server selection, info and statistics

Output
dnscmd /info                       local DNS serverdnscmd dnssvr1.contoso.com /info   remote server by FQDNdnscmd 10.0.0.1 /info              remote server by IPdnscmd /?                          all commandsdnscmd /<command> /?               help for one command

On the office PC, where dnscmd found nothing (RSAT DNS tools not installed), so Windows outputs come from the Microsoft Learn examples:

Output
C:\> where dnscmdINFO: Could not find files for the given pattern(s).(exit 1)
Output
dnscmd reskit.com /info isslavednscmd reskit.com /info recursiontimeoutdnscmd reskit.com /statistics 00000001
Output
$ dnscmd reskit.com /info isslaveQuery result:Dword: 0 (00000000)Command completed successfully.$ dnscmd reskit.com /info recursiontimeoutDword: 15 (0000000F)$ dnscmd reskit.com /statistics 00000001DNS Server reskit.com statistics:DNS Server Time Statistics:Server start time 3/7/2001 1:07:31 PMSeconds since start 8482Stats last cleared 3/7/2001 1:07:31 PM
  • /info alone shows common settings; /info <setting> returns only that value (isslave 0 = server resolves on its own when forwarders fail).
  • /statistics <statid> shows one counter group (00000001 = Time, 00000002 = Query, 00000003 = both).
  • /clearcache clears the cache; /exportsettings writes the config to DnsSettings.txt.

Linux lab: ns1 (192.168.223.53) is the BIND primary of lab.local; rndc status is the /info equivalent and rndc stats the /statistics equivalent.

Terminal
rndc statusrndc stats && grep -A12 "++ Incoming Requests ++" /var/bind/named.stats
Output
$ rndc statusversion: BIND 9.18.49 (Extended Support Version) <id:cd4a53b>configuration file: /etc/bind/named.confnumber of zones: 3 (0 automatic)xfers running: 0recursive clients: 0/900/1000tcp clients: 0/150server is up and running$ rndc stats && grep -A12 "++ Incoming Requests ++" ...++ Incoming Requests ++                   6 QUERY++ Incoming Queries ++                   4 A                   1 SOA                   1 AXFR++ Outgoing Rcodes ++                   3 NOERROR                   1 NXDOMAIN                   1 REFUSED

203.4 Forwarders and listen addresses

Output
dnscmd /resetforwarders 10.0.0.1 10.0.0.2 /timeout 7 /slavednscmd /resetforwarders                 (no IP) clear the listdnscmd /resetlistenaddresses 10.0.0.1   listen only on this IPdnscmd /ipvalidate /forwarders 10.0.0.1 can it work as a forwarder?dnscmd /clearcache                      clear the RR cache
Lab: ns2 forwards only to ns1
  1. 1.Client asks ns2 (192.168.223.54) for intranet.corp.local

  2. 2.ns2 forwards to ns1 (192.168.223.53)

  3. 3.ns1 answers authoritatively: A 192.168.223.70; ns2 caches it (300 s)

  4. 4.Client asks ns2 for example.com; ns1 refuses it (recursion off)

  5. 5.ns2 has no internet route: client gets SERVFAIL

forward only = never iterate on its own (like /slave)

Terminal
# ns2:grep -n -E "recursion|forward" /etc/bind/named.conf# client:dig @192.168.223.54 intranet.corp.localdig @192.168.223.54 example.com +tries=1 +timeout=3 | grep -E "status|SERVER"
Output
$ grep -n -E "recursion|forward" /etc/bind/named.conf6:    recursion yes;7:    allow-recursion { 192.168.223.0/24; 127.0.0.1; };8:    forward only;9:    forwarders { 192.168.223.53; };$ dig @192.168.223.54 intranet.corp.local;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3114;; ANSWER SECTION:intranet.corp.local. 300 IN A 192.168.223.70;; SERVER: 192.168.223.54#53(192.168.223.54) (UDP)$ dig @192.168.223.54 example.com +tries=1 +timeout=3 | grep -E "status|SERVER";; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 63128

203.5 Cache: /clearcache vs rndc flush

Terminal
rndc dumpdb -cache && grep -i intranet /var/bind/named_dump.dbrndc flush && rndc dumpdb -cache && grep -c -i intranet /var/bind/named_dump.db
Output
$ rndc dumpdb -cache && grep -i intranet /var/bind/named_dump.dbintranet.corp.local. 297 IN A 192.168.223.70$ rndc flush && rndc dumpdb -cache && grep -c -i intranet /var/bind/named_dump.db0

203.6 Scavenging and aging

Output
dnscmd /startscavenging                       start scavenging nowdnscmd /ageallrecords test.contoso.com        time stamp the zone (irreversible)dnscmd /ageallrecords <zone> @ /tree          child nodes toodnscmd /zoneresetscavengeservers <zone> <IPs> only these servers scavenge
  • Scavenging deletes old dynamic records, but only ones with a timestamp; ageallrecords stamps all records and cannot be undone.
  • Scavenging must be enabled; zoneresetscavengeservers limits which servers may scavenge.
  • BIND has no scavenging; the DHCP server removes records with nsupdate.

203.7 Resource records

Output
dnscmd /recordadd <zone> host1 A 10.0.0.5dnscmd /recordadd <zone> www CNAME host1.<zone>dnscmd /recordadd <zone> test MX 10 mailserver.<zone>dnscmd /recordadd 0.0.10.in-addr.arpa 5 PTR host1dnscmd /recordadd <zone> _ldap._tcp SRV 0 100 389 dc1dnscmd /recorddelete <zone> host1 A /f        all A records of host1dnscmd /nodedelete <zone> sub /tree           node + childrendnscmd /enumrecords <zone> @ /type A          records at the rootdnscmd /zoneprint <zone>                      whole zone

BIND lab: nsupdate sends a TSIG-signed update (like /recordadd), AXFR lists the whole zone (like /zoneprint):

Terminal
cat /root/add.txtnsupdate -k /root/ddns.key /root/add.txtdig @192.168.223.53 app.lab.local +noall +answerdig @192.168.223.53 lab.local AXFR
Output
server 192.168.223.53zone lab.localupdate add app.lab.local 300 A 192.168.223.90send$ dig @192.168.223.53 app.lab.local +noall +answerapp.lab.local.  300  IN  A  192.168.223.90$ dig @192.168.223.53 lab.local AXFRlab.local.  300 IN SOA ns1.lab.local. admin.lab.local. 2026110902 3600 600 86400 300lab.local.  300 IN NS  ns1.lab.local.lab.local.  300 IN NS  ns2.lab.local.lab.local.  300 IN MX  10 mail.lab.local.app.lab.local.  300 IN A  192.168.223.90mail.lab.local. 300 IN A  192.168.223.25ns1.lab.local.  300 IN A  192.168.223.53ns2.lab.local.  300 IN A  192.168.223.54www.lab.local.  300 IN A  192.168.223.80;; SERVER: 192.168.223.53#53(192.168.223.53) (TCP);; XFR size: 10 records (messages 1, bytes 289)
Terminal
nsupdate -k /root/ddns.key /root/del.txt   # update delete app.lab.local Adig @192.168.223.53 app.lab.localnsupdate /root/add.txt                     # no key
Output
$ dig @192.168.223.53 app.lab.local;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 28589$ nsupdate /root/add.txtupdate failed: REFUSED(exit 2)
  • /recordadd order: zone, node, type, data; @ means the zone root.
  • /recorddelete with data deletes one record; /nodedelete deletes all records of a name (/tree: children too).
  • Without the key the update is REFUSED: allow-update permits only the ddns key.

203.8 Listing, creating and deleting zones

Output
dnscmd reskit.com /enumzonesdnscmd reskit.com /enumzones /auto-created /reverse
Output
$ dnscmd reskit.com /enumzonesEnumerated zone list:     Zone Count = 6..                             0 DS            Up=00.0.10.in-addr.arpa           0 DS   Rev      Up=10.in-addr.arpa                1 file Rev Auto Up=0255.in-addr.arpa              1 file Rev Auto Up=0reskit.com                    1 DS            Up=0test.reskit.com               1 file          Up=1Command completed successfully.$ dnscmd reskit.com /enumzones /auto-created /reverse     Zone Count = 2.
Output
dnscmd /zoneadd <zone> /dsprimary [/dp ForestDnsZones.contoso.com]dnscmd /zoneadd <zone> /primary /file test.contoso.com.dnsdnscmd /zoneadd <zone> /secondary 10.0.0.2dnscmd /zoneadd <zone> /forwarder 10.0.0.2 /file p.dnsdnscmd /zonedelete <zone> [/dsdel] [/f]dnscmd /zoneresettype <zone> /secondary 10.0.0.2
Zone typednscmd switchStored in
Primary (AD-integrated)/dsprimaryAD DS (/dp, /domain, /enterprise, /legacy partition)
Primary (file)/primary /file x.dnsZone file
Secondary/secondary <master IP>File, copy via zone transfer
Stub/stub or /dsstubOnly NS/SOA/glue of the zone
Conditional forwarder/forwarder or /dsforwarderForwards one domain to given IPs
Terminal
rndc addzone test.local '{ type primary; file "/var/bind/test.local.zone"; };'dig @192.168.223.53 host1.test.local +noall +answerrndc delzone test.localdig @192.168.223.53 host1.test.local | grep -E "status|WARNING"
Output
$ dig @192.168.223.53 host1.test.local +noall +answerhost1.test.local.  300  IN  A  192.168.223.5$ rndc delzone test.local$ dig @192.168.223.53 host1.test.local | grep -E "status|WARNING";; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 31901;; WARNING: recursion requested but not available

203.9 Zone operations

  • /zoneinfo shows settings; /zonepause and /zoneresume stop and start answering for a zone.
  • /zonerefresh makes a secondary check the SOA serial; /zonereload re-reads the source.
  • /zonewriteback and /writebackfiles flush memory to storage; /zoneexport writes records to a file.
  • /zoneresetmasters sets the primaries of a secondary; /zoneresettype changes the type without deleting the zone.
Terminal
rndc zonestatus lab.local      # ns1rndc reload lab.local          # ns1rndc freeze lab.local; rndc thaw lab.local
Output
[ns1] $ rndc zonestatus lab.localname: lab.localtype: primaryfiles: /var/bind/lab.local.zoneserial: 2026110903dynamic: yesfrozen: no[ns1] $ rndc reload lab.localrndc: 'reload' failed: dynamic zone(exit 1)[ns1] $ rndc freeze lab.local; rndc thaw lab.localA zone reload and thaw was started.Check the logs to see the result.

203.10 Zone transfers and notify

Update, NOTIFY and transfer between ns1 and ns2
  1. 1.Client sends a TSIG-signed UPDATE to ns1

  2. 2.ns1 increases the serial (2026110903)

  3. 3.ns1 sends NOTIFY to ns2

  4. 4.ns2 requests IXFR and receives the zone changes

  5. 5.Client tries AXFR from ns2: refused (allow-transfer none) -> Transfer failed

Output
dnscmd /zoneresetsecondaries <zone> /securelist 11.0.0.2 /notifylist 11.0.0.2 BIND: allow-transfer { 192.168.223.54; };      also-notify { 192.168.223.54; };
Terminal
rndc notify lab.local                 # ns1rndc retransfer lab.local             # ns2dig @192.168.223.54 lab.local AXFR | tail -3   # client
Output
[ns1] $ rndc notify lab.localzone notify queued[ns2] $ grep -E "notify|transfer" /var/bind/named.log | tail -409-Nov-2026 12:48:36.136 client @0x72ae8e5dc270 192.168.223.53#33672: received notify for zone 'lab.local'09-Nov-2026 12:48:36.136 zone lab.local/IN: notify from 192.168.223.53#33672: zone is up to date[ns2] $ rndc retransfer lab.local[ns2] $ grep -E "transfer" /var/bind/named.log | tail -309-Nov-2026 12:48:41.264 zone lab.local/IN: transferred serial 202611090309-Nov-2026 12:48:41.264 transfer of 'lab.local/IN' from 192.168.223.53#53: Transfer status: success[ns1] $ grep -E "AXFR|transfer" /var/bind/named.log | tail -409-Nov-2026 12:48:41.264 client @0x7d977c4573f0 192.168.223.54#34771 (lab.local): transfer of 'lab.local/IN': AXFR started (serial 2026110903)[client] $ dig @192.168.223.54 lab.local AXFR | tail -3; Transfer failed.
GroupOptionsMeaning
Transfer/noxfr, /nonsecure, /securens, /securelist <IPs>Who may pull the zone
Notify/nonotify, /notify, /notifylist <IPs>Who is told about changes

203.11 Comparison: dnscmd vs BIND

Taskdnscmd (Windows)BIND 9 (Linux)
Server status/inforndc status
Statistics/statisticsrndc stats
Clear cache/clearcacherndc flush
Add/delete record/recordadd, /recorddeletensupdate (TSIG key)
Print zone/zoneprintdig AXFR
Create/delete zone/zoneadd, /zonedeleterndc addzone, rndc delzone
Zone details/zoneinforndc zonestatus
Secure transfers/zoneresetsecondaries /securelist /notifylistallow-transfer + also-notify

203.12 Common mistakes

  • Fixing a wrong record with /clearcache: the cache is fine, the zone is wrong; use /recorddelete + /recordadd (or nsupdate).
  • rndc reload on a dynamic zone fails; freeze then thaw it.
  • Running /ageallrecords casually: the timestamp is irreversible.
  • Leaving zone transfers as /nonsecure: anyone can download the whole zone.
  • Thinking dnscmd is dead: it is still supported on Windows Server 2025 and many batch scripts use it.

203.13 Interview tips

  • Stale IP for users: dnscmd /clearcache on Windows, rndc flush on BIND.
  • Secure zone transfers: /zoneresetsecondaries /securelist + /notifylist; BIND allow-transfer + also-notify, plus TSIG.
  • NOTIFY -> secondary checks SOA serial -> IXFR/AXFR.
  • New scripts use the DnsServer PowerShell module, but you should still be able to read dnscmd.