使用 dnscmd 更改 SOA 上的 TTL

使用 dnscmd 更改 SOA 上的 TTL

你好,我在 Windows Server 2012 上使用 dnsmcd 命令从 csv 文件创建新区域。

但是我需要更改 SOA 记录上的 TTL,因此我尝试执行以下操作:

dnscmd /recordadd example.com `@ 300 SOA

但我有这个错误:

Command failed:  DNS_ERROR_RECORD_FORMAT     9702    0x25E6

有办法吗?

答案1

以下是修改授权开始记录的正确格式

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

答案2

如果你想知道为什么会出现这个错误DNS_ERROR_RECORD_ALREADY_EXISTS尝试更改 SOA 记录(即增加区域的序列号)时,请检查要更改为的序列号(新序列号)是否实际上高于当前序列号。此错误消息令人困惑,因此我希望它能让您省去一些头疼,直到您弄清楚原因为止。

如果您发现这个脚本有用的话我会使用它,因为对我来说,单击 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

相关内容