Resolve SGU-DC02 and SI short names from Sala Inmersiva

This commit is contained in:
alexrg committed 2026-10-01 16:31:40 -06:00
1 parent 0dd4c4d629
commit b9756ad3b2
4 files changed
+129

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
# Administrative setup for workgroup clients that have no AD DNS suffix.
# This narrowly scoped authoritative zone answers only the bare server name;
# the normal lci.lasalle.mx zone continues to handle its FQDN.
[CmdletBinding()]
param()
$ErrorActionPreference = 'Stop'
Import-Module DnsServer
if ($env:COMPUTERNAME -ne 'SGU-DC02') { throw 'Run this setup on SGU-DC02.' }
$zone = 'sgu-dc02'
$address = '192.168.54.211'
$existingZone = Get-DnsServerZone | Where-Object ZoneName -eq $zone
if (-not $existingZone) {
Add-DnsServerPrimaryZone -Name $zone -ReplicationScope Domain -DynamicUpdate None
} elseif (-not $existingZone.IsDsIntegrated -or $existingZone.DynamicUpdate -ne 'None') {
throw 'Existing short-name zone needs review.'
}
$records = @(Get-DnsServerResourceRecord -ZoneName $zone -Name '@' |
Where-Object { $_.RecordType -notin @('SOA','NS') })
if ($records.Count -gt 0) {
if ($records.Count -ne 1 -or $records[0].RecordType -ne 'A' -or
$records[0].RecordData.IPv4Address.IPAddressToString -ne $address) {
throw 'Existing short-name record differs; refusing to overwrite it.'
}
} else {
Add-DnsServerResourceRecordA -ZoneName $zone -Name '@' -IPv4Address $address -TimeToLive ([TimeSpan]::FromMinutes(5))
}
Resolve-DnsName "$zone." -Server 127.0.0.1 -Type A -DnsOnly |
Select-Object Name,IPAddress
+58
View File
@@ -0,0 +1,58 @@
# Keep bare-name DNS answers available to Sala workgroup clients with no suffix.
# Each narrowly scoped zone has one A record; normal FQDN records remain the
# source of truth. No root zone, wildcard, nonsecure updates, or hosts-file edits.
[CmdletBinding()]
param([string]$ManifestPath = 'C:\ProgramData\LCI-Admin\Sala-DNS\manifest.json')
$ErrorActionPreference = 'Stop'
Import-Module DnsServer
if ($env:COMPUTERNAME -ne 'SGU-DC02') { throw 'Run this sync on SGU-DC02.' }
$folder = Split-Path $ManifestPath
$statePath = Join-Path $folder 'short-names-owned.json'
$manifest = Get-Content -LiteralPath $ManifestPath -Raw | ConvertFrom-Json
if ($manifest.Zone -ne 'lci.lasalle.mx') { throw 'Unexpected source zone.' }
$owned = @{}
if (Test-Path -LiteralPath $statePath) {
$state = Get-Content -LiteralPath $statePath -Raw | ConvertFrom-Json
foreach ($property in $state.PSObject.Properties) { $owned[$property.Name] = $property.Value }
}
$results = @()
$failed = $false
foreach ($name in (@('sgu-dc02') + @($manifest.Records.Name) | Sort-Object -Unique)) {
try {
if ($name -notmatch '^(sgu-dc02|si-\d{2})$') { throw 'Name outside approved scope.' }
$source = @(Get-DnsServerResourceRecord -ZoneName $manifest.Zone -Name $name -RRType A)
if ($source.Count -ne 1) { throw 'Expected one source A record.' }
$ip = $source[0].RecordData.IPv4Address.IPAddressToString
if ($ip -notmatch '^192\.168\.(54|55)\.\d{1,3}$') { throw 'Source IP outside managed networks.' }
$zone = Get-DnsServerZone | Where-Object ZoneName -eq $name
if (-not $zone) {
Add-DnsServerPrimaryZone -Name $name -ReplicationScope Domain -DynamicUpdate None
$owned[$name] = $ip
} elseif (-not $owned.ContainsKey($name) -or -not $zone.IsDsIntegrated -or $zone.DynamicUpdate -ne 'None') {
throw 'Existing bare-name zone is not owned by this sync.'
}
$records = @(Get-DnsServerResourceRecord -ZoneName $name -Name '@' | Where-Object RecordType -notin @('SOA','NS'))
if ($records.Count -eq 0) {
Add-DnsServerResourceRecordA -ZoneName $name -Name '@' -IPv4Address $ip -TimeToLive ([TimeSpan]::FromMinutes(5))
} elseif ($records.Count -ne 1 -or $records[0].RecordType -ne 'A' -or
$records[0].RecordData.IPv4Address.IPAddressToString -ne $owned[$name]) {
throw 'Bare-name record differs from the owned record; refusing to overwrite it.'
} elseif ($ip -ne $owned[$name]) {
$updated = $records[0].Clone()
$updated.RecordData.IPv4Address = [Net.IPAddress]::Parse($ip)
$updated.TimeToLive = [TimeSpan]::FromMinutes(5)
Set-DnsServerResourceRecord -ZoneName $name -OldInputObject $records[0] -NewInputObject $updated
}
$owned[$name] = $ip
$results += [pscustomobject]@{Name=$name;IP=$ip;Status='Current';Error=$null}
} catch {
$failed = $true
$results += [pscustomobject]@{Name=$name;IP=$null;Status='Error';Error=$_.Exception.Message}
}
}
$owned | ConvertTo-Json | Set-Content -LiteralPath "$statePath.next" -Encoding UTF8
Move-Item -LiteralPath "$statePath.next" -Destination $statePath -Force
[pscustomobject]@{Time=(Get-Date).ToString('o');Records=$results} | ConvertTo-Json -Depth 5 |
Set-Content -LiteralPath (Join-Path $folder 'short-names-result.json') -Encoding UTF8
$results
if ($failed) { throw 'Some bare-name records could not be synchronized. See short-names-result.json.' }
+3
View File
@@ -66,4 +66,7 @@ Move-Item -LiteralPath "$ManifestPath.next" -Destination $ManifestPath -Force
[pscustomobject]@{ Time = (Get-Date).ToString('o'); Records = $results } |
ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path (Split-Path $ManifestPath) 'last-result.json') -Encoding UTF8
$results
# When installed, also preserve bare-name answers for workgroup clients on Sala.
$shortNameSync = Join-Path $PSScriptRoot 'Sync-SguSalaShortNames.ps1'
if (Test-Path -LiteralPath $shortNameSync) { & $shortNameSync -ManifestPath $ManifestPath }
if ($failed) { throw 'One or more Sala DNS records could not be synchronized. See last-result.json.' }