이와 같은 문제를 해결할 때 가장 먼저 해야 할 일은 DNS 디버그 로깅을 활성화하는 것입니다. 그러나 로그 디버그 로깅을 살펴봐야 할 때마다 놀랄 것입니다. PowerShell을 사용하여 DNS 디버그 로그 파서 스크립트를 만들어서 간편하게 만들어보세요!
PowerShell로 DNS 디버그 로그 파서를 만드는 방법
디버그할 다양한 옵션들이 있지만, 내 경우에는 동적 업데이트에 대한 자세한 정보가 필요합니다. 다음은 DNS 서버 중 하나에 대한 구성 예입니다.

이를 활성화하면 지정한 파일 경로에 로그 파일을 생성하게 되며, 다음과 같은 형식을 가집니다:

마킹된 첫 번째 행은 IP 주소이고, 마지막 행은 업데이트를 시도한 DNS 레코드입니다. 이들은 명백한 이유로 마킹되었습니다. 선택한 옵션에 따라 이 로그 파일은 매우 커질 수 있으며, 가장 쉽게 읽을 수 있는 형식은 아닙니다.
하나의 IP만 필터링하거나 특정 시간 범위로 좁히려면 어떻게 해야 할까요? 기본 로그 파일로는 이를 할 수 없습니다. 이것이 PowerShell로 DNS 디버그 로그 파서 스크립트를 만든 이유입니다.
아래 스크립트는 이 로그 파일을 가져와서 다음과 같은 멋진 CSV 파일로 파싱합니다:

그건 훨씬 나아 보이지 않나요? 스크립트는 로그 파일을 검색하여 오류를 파싱하고 날짜, IP 및 오류를 깔끔한 형식의 CSV로 정리합니다. 또한 모든 DNS 서버 IP를 제외합니다.
무슨 이유에서인지 어떤 옵션을 선택하든 DNS 서버 IP 자체가 계속 나타나는 것을 발견했습니다. DNS 레코드를 업데이트하는 데 문제가 있는 클라이언트 IP 주소만 알고 싶습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -Module ActiveDirectory | |
$dnsServer = ‘‘ ## This is the server name as a NETBIOS or FQDN | |
$OutputFilePath = ‘C:\DNSDebugLogSummary.csv‘ ## The CSV file that will be created | |
## The log file you specified in the debug logging dialog box | |
$DnsDebugLogFilePath = “\$dnsServer\c$\DnsDebugLog.log“ | |
## Find all of the DNS server IPs in the current domain | |
$DnsServerIPs = ((Get-ADDomain).ReplicaDirectoryServers | Resolve-DnsName).IPAddress | |
Write-Verbose –Message “Found DNS servers $($DnsServerIPs -join ‘,‘)“ | |
## Find all lines in the log file that don’t contain the strings ‘NOERROR’ or are blank. This | |
## retrieves only the lines with errors in them. | |
Select-String –Pattern ‘NOERROR|^\s*‘ –Path $DnsDebugLogFilePath -NotMatch | foreach { | |
try { | |
## Find lines containing an IP address | |
if ($_.Line -match ‘\b(?:\d{1,3}\.){3}\d{1,3}\b‘) { | |
Write-Verbose –Message ‘Found line with IP address.‘ | |
$IP = $Matches[0] | |
## If the IP isn’t a DNS server it must be a client IP | |
if ($DnsServerIPs -notcontains $IP) { | |
Write-Verbose “Processing IP ‘$IP‘“ | |
$Split = $_.Line.Split(‘ ‘) | |
$Date = $Split[0] | |
$Time = $Split[1] + $Split[2] | |
$Err = [regex]::Match($_.Line, ‘\[(.*)\]‘).Groups[1].Value | |
[pscustomobject]@{ ‘Date‘ = “$Date $Time“; ‘IP‘ = $IP; ‘Error‘ = $Err } | |
} | |
} | |
} catch { | |
Write-Warning $_.Exception.Message | |
} | |
} | Export-Csv –Path $OutputFilePath –Append –NoTypeInformation |