powershell - Powershell 出现奇怪的 DNS 记录重复?

标签 powershell dns

最近在使用 native Powershell DNS commandlet(特别是 Get-DNSServerResourceRecord)时,我注意到一些奇怪的东西对我来说没有意义。

当我使用 native DNS 工具、LDAP 查询工具甚至 ADSIedit 查看我的区域时,我只看到一个代表给定主机名的 DNS 对象。

但是,当我使用 Powershell 执行相同操作时,我会获得给定主机的两个对象,一个用于 NETBIOS 名称,另一个用于 FQDN。所有其他属性都相同,包括 IP。

例如,如果我有一台名为 computer1 的计算机:这就是我所看到的。

PS C:\> Get-DnsServerResourceRecord -ZoneName 'mydomain.local' -RRType A -ComputerName 'DNSServer1' | Where-Object {$_.hostname -like "Computer1*"}  | fl *


DistinguishedName     : DC=computer1.mydomain.local,DC=mydomain.local,cn=MicrosoftDNS,DC=DomainDnsZones,DC=mydomain,DC=local
HostName              : COMPUTER1.mydomain.local
RecordClass           : IN
RecordData            : DnsServerResourceRecordA
RecordType            : A
Timestamp             :
TimeToLive            : 01:00:00
Type                  : 1
PSComputerName        :
CimClass              : root/Microsoft/Windows/DNS:DnsServerResourceRecord
CimInstanceProperties : {DistinguishedName, HostName, RecordClass, RecordData...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties

DistinguishedName     : DC=computer1,DC=mydomain.local,cn=MicrosoftDNS,DC=DomainDnsZones,dc=mydomain,dc=local
HostName              : COMPUTER1
RecordClass           : IN
RecordData            : DnsServerResourceRecordA
RecordType            : A
Timestamp             :
TimeToLive            : 01:00:00
Type                  : 1
PSComputerName        :
CimClass              : root/Microsoft/Windows/DNS:DnsServerResourceRecord
CimInstanceProperties : {DistinguishedName, HostName, RecordClass, RecordData...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties


我很困惑为什么 Powershell 会显示这个以及它实际上是从哪里提取它的。我无法使用 native LDAP 工具(甚至 ADFind)找到这些 FQDN 对象。

这是 Powershell DNS cmdlet 的一些奇怪的工件/错误吗?或者 DNS 记录是否存储给定主机的双重条目,但仅使用 native 工具显示一个条目?

对我来说都没有意义,因为我不希望 cmdlet 动态地组成 DN 值,并且所有主机记录不会发生这种情况。后者似乎不可能因为该区域中的所有记录并未发生这种情况。没有 FQDN 的记录比有 FQDN 的记录多大约 100 条(10926 与 10824)。

编辑如果有帮助,这里是同一对象(和通配符)的 ADFind 查询。

C:\temp>adfind -h dnsserver1 -domaindns -f "(&(name=computer1*))" name

AdFind V01.57.00cpp Joe Richards (<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97e4e2e7e7f8e5e3d7fdf8f2e0f6e5f2b9f9f2e3" rel="noreferrer noopener nofollow">[email protected]</a>) November 2021

Using server: dnsserver1.mydomain.local:389
Directory: Windows Server 2016
Base DN: DC=DomainDnsZones,DC=ad,DC=ewsad,DC=net

dn:DC=computer1,DC=mydomain.local,CN=MicrosoftDNS,DC=DomainDnsZones,DC=mydomain,DC=local
>name: computer1


1 Objects returned

最佳答案

我可以确认此行为。

在 powershell 中,这会为许多计算机返回 2 个结果(也许是全部,我没有检查)

Get-DnsServerResourceRecord -ZoneName 'domain.com' -RRType A -ComputerName dnserver1 | where hostname -like Computer1*

DistinguishedName     : DC=Computer1.domain.com,DC=domain.com,cn=MicrosoftDNS,DC=DomainDnsZones,DC=domain,DC=com
HostName              : Computer1.domain.com
RecordClass           : IN
RecordData            : DnsServerResourceRecordA
RecordType            : A
Timestamp             : 12/8/2022 9:00:00 AM
TimeToLive            : 00:20:00
Type                  : 1
PSComputerName        :
CimClass              : root/Microsoft/Windows/DNS:DnsServerResourceRecord
CimInstanceProperties : {DistinguishedName, HostName, RecordClass, RecordData...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties

DistinguishedName     : DC=Computer1,DC=domain.com,cn=MicrosoftDNS,DC=DomainDnsZones,DC=domain,DC=com
HostName              : Computer1
RecordClass           : IN
RecordData            : DnsServerResourceRecordA
RecordType            : A
Timestamp             : 12/8/2022 9:00:00 AM
TimeToLive            : 00:20:00
Type                  : 1
PSComputerName        :
CimClass              : root/Microsoft/Windows/DNS:DnsServerResourceRecord
CimInstanceProperties : {DistinguishedName, HostName, RecordClass, RecordData...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties

但是 dsquery 会生成一条记录。

dsquery computer -name computer1* -s dnsserver1

"CN=Computer1,OU=Computers,DC=domain,DC=com"

您只能确认其中一个是真实的 AD 对象。

$recordlist = Get-DnsServerResourceRecord -ZoneName 'domain.com' -RRType A -ComputerName dnserver1 | where hostname -like Computer1*

foreach($record in $recordlist){
    Write-Host "Checking DN $($record.DistinguishedName)" -ForegroundColor Cyan
    
    $found = $record.DistinguishedName |
        Get-ADObject -ErrorAction SilentlyContinue

    if($found){
        Write-Host "Record found in AD" -ForegroundColor Green
    }
    else{
        Write-Host "Record not in AD" -ForegroundColor DarkGray
    }
}

所以我必须得出结论,到目前为止,证据确实表明 Get-DnsServerResourceRecord 也在添加带有 FQDN 的重复记录。希望有人能够找到或知道为什么以这种方式实现。

关于powershell - Powershell 出现奇怪的 DNS 记录重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74817387/

相关文章:

powershell - 将JSON文件上传到Web API

php - 尝试通过 PHP 中的 IP(具有已知主机名)连接到 HTTPS 站点,得到 "Peer certificate ... does not match expected CN ..."

powershell - 如何使用powershell获取每个文件的文件名和行数

xml - 来自另一个文件的 PowerShell XML 节点

linux - Hosts 文件在 Fedora 上部分工作

php - javascript、php、ajax - AJAX 响应始终为空

android - 在 Lollipop 中清除 DNS 缓存的 Root Shell 命令?

nginx - 域名不适用于 nginx 中的某些端口

powershell - 如何通过 "The site' 的安全证书不受信任!”同时在 powershell 中监视 URL

regex - 正则表达式用于匹配特定单词并忽略换行