Windows-Server-2012

使用 dnscmd 更改 SOA 上的 TTL

  • April 25, 2017

嗨,我在我的 Windows Server 2012 上使用 dnsmcd 命令來從 csv 文件創建新區域。

但我需要更改 SOA 記錄上的 TTL,所以我嘗試這樣做:

dnscmd /recordadd example.com `@ 300 SOA

但我有這個錯誤:

Command failed:  DNS_ERROR_RECORD_FORMAT     9702    0x25E6

有辦法嗎?

這是修改授權開始記錄的正確格式

dnscmd /recordadd zonename @ SOA primaryDNSservername responsibleemailipaddress serialnumber refreshinterval retryinterval expireinterval defaultTTL

如果您想知道為什麼在嘗試更改 SOA 記錄(即增加區域的序列號)時收到此錯誤DNS_ERROR_RECORD_ALREADY_EXISTS,請檢查您要更改的序列號(新序列號)是否實際上高於目前序列號. 此錯誤消息令人困惑,所以我希望它不會讓您頭疼,直到您弄清楚原因。

如果您覺得它有用,我會使用此腳本,因為在 200 左右的區域上點擊“增加”對我來說太過分了。

rem  To increase serial on all zones: copy this to a script, as functions cannot be use from CLI

echo on

rem  get the intersting zones first that you want to change
echo. > %TEMP%\dnszones.txt
for /f %%z in ('dnscmd /enumzones ^| findstr in-addr.arpa') do echo %%z >> %TEMP%\dnszones.txt

rem  take existing serials from all zones
for /f %%z in (%TEMP%\dnszones.txt) do dnscmd /zoneprint %%z | findstr SOA > %TEMP%\dns.%%z.txt

rem  read the serials and increase them
for /f %%z in (%TEMP%\dnszones.txt) do for /f "tokens=1-8*" %%a in (%TEMP%\dns.%%z.txt) do call:increase_serial %%z %%e

goto end

:increase_serial
rem arg1=%~1 is the zone name, arg2 is existing serial
@rem  example format of the SOA record
@rem         3600 SOA   servername.domain.com. hostmaster.domain.com. 13 900 600 86400 3600

@rem  as per https://technet.microsoft.com/en-us/library/cc816941(v=ws.10).aspx
@rem  var a is minimum-default-ttl - optional
@rem  var b is string SOA
@rem  var c is PrimSvr - server name with dot
@rem  var d is Admin - contact for admin
@rem  var e is serial
@rem  var f is Refresh - in seconds
@rem  var g is Retry - in seconds
@rem  var h is Expire - in seconds
@rem  var i is MinTTL - in seconds

set /a INCREASED_SERIAL=%~2+1
@echo increase serial from %~2 to %INCREASED_SERIAL% on zone %1
for /f "tokens=1-8*" %%a in (%TEMP%\dns.%~1.txt) do dnscmd /RecordAdd %~1 @ SOA %%c %%d %INCREASED_SERIAL% %%f %%g %%h %%i
goto :eof

:end

引用自:https://serverfault.com/questions/801283