mexx
Goto Top

Suche DNS Command um Host A Einträge zu ändern

Hallo,

in einer reinen Windows Server 2008 R2 Umgebung mit zwei Domaincontrollern auf denen ein DNS Server läuft, besteht die Anforderung einen Host Eintrag im DNS zu ändern. Meine google Suche war bisher erfolglos. Vielleicht ahbt Ihr eine Idee?

Gruß,
mexx

Content-ID: 236433

Url: https://administrator.de/forum/suche-dns-command-um-host-a-eintraege-zu-aendern-236433.html

Ausgedruckt am: 05.02.2025 um 09:02 Uhr

colinardo
colinardo 25.04.2014 aktualisiert um 11:59:58 Uhr
Goto Top
Hallo mexx,
kannst du mit Dnscmd machen.

Grüße Uwe
mexx
mexx 25.04.2014 um 12:03:57 Uhr
Goto Top
Ich finde in den Command keinen Schalter zum Ändern. Löschen und Hinzufügen, aber ein Set finde ich nicht.
colinardo
colinardo 25.04.2014 aktualisiert um 16:38:17 Uhr
Goto Top
Zitat von @mexx:

Ich finde in den Command keinen Schalter zum Ändern. Löschen und Hinzufügen, aber ein Set finde ich nicht.
erst den Eintrag mit:
dnscmd /recorddelete
entfernen und dann wieder mit
dnscmd /recordadd
neu hinzufügen.

http://gallery.technet.microsoft.com/scriptcenter/Update-DNS-records-wi ...

Grüße Uwe
mexx
mexx 25.04.2014 um 12:10:56 Uhr
Goto Top
Nein, den weg möchte ich nicht gehen. Windows 2012 R2 besitzt ein Powershell Modul mit einer Set Cmdlet. Unter 2008 kann es doch nicht notwendig sein, zu löschen und neu zu schreiben. Das ist nicht ändern. Gibt es wirklich keine andere Methode?
colinardo
colinardo 25.04.2014 aktualisiert um 21:14:12 Uhr
Goto Top
Zitat von @mexx:

Nein, den weg möchte ich nicht gehen. Windows 2012 R2 besitzt ein Powershell Modul mit einer Set Cmdlet. Unter 2008 kann es
doch nicht notwendig sein, zu löschen und neu zu schreiben. Das ist nicht ändern. Gibt es wirklich keine andere Methode?
ohne DNSCmd und nur mit Powershell kannst du das über den WMI-Namespace root\MicrosoftDNS mit der Methode Modify machen.

Beispiel um für einen DNS A-Eintrag die IP-Adresse zu ändern:
(gwmi -Namespace 'root\MicrosoftDNS' -Class MicrosoftDNS_AType -Filter "ContainerName='contoso.com' and OwnerName='mytest.contoso.com'").Modify($null,"192.168.15.66")
Beispiel um für einen DNS CNAME-Eintrag das Ziel zu ändern:
(gwmi -Namespace 'root\MicrosoftDNS' -Class MicrosoftDNS_CNAMEType -Filter "ContainerName='contoso.com' and OwnerName='mycname.contoso.com'").Modify($null,"mytarget.contoso.com")
Die verschiedenen DNS-Typen kannst du hier nachschlagen:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682123%28v=vs ...

Grüße Uwe
colinardo
colinardo 25.04.2014 aktualisiert um 14:31:15 Uhr
Goto Top
habe das ganze mal zu einem CMD-Let zusammengeschrieben, welche bis jetzt A und CNAME Einträge unterstützt:
function Change-DNSRecord{
    param(
        [parameter(mandatory=$false)][string]$DNSServer = $env:COMPUTERNAME,
        [parameter(mandatory=$true)][ValidateSet("A","CNAME")][string]$EntryType,  
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()][string]$Container,
        [parameter(mandatory=$true)][ValidateNotNullOrEmpty()][string]$EntryName
    )

    DynamicParam{
        $attrCollection = new-object System.Collections.ObjectModel.Collection[System.Attribute]
        $paramDic = new-object System.Management.Automation.RuntimeDefinedParameterDictionary

        Switch($EntryType.ToUpper()){
            "A"{  
                $attr = new-object System.Management.Automation.ParameterAttribute
                $valAttr1 = new-Object System.Management.Automation.ValidateNotNullOrEmptyAttribute
                $valAttr2 = New-Object System.Management.Automation.ValidatePatternAttribute("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")  
                $attr.ParameterSetName = "AllParameterSets"  
                $attr.Mandatory = $true
                $attrCollection.Add($attr)
                $attrCollection.Add($valAttr1)
                $attrCollection.Add($valAttr2)
                $dynParam1 = new-object System.Management.Automation.RuntimeDefinedParameter("IPAddress", [String], $attrCollection)  
                $paramDic.Add("IPAddress", $dynParam1)  
                return $paramDic
            }
            "CNAME"{  
                $attr = new-object System.Management.Automation.ParameterAttribute
                $valAttr1 = new-Object System.Management.Automation.ValidateNotNullOrEmptyAttribute
                $attr.ParameterSetName = "AllParameterSets"  
                $attr.Mandatory = $true
                $attrCollection.Add($attr)
                $attrCollection.Add($valAttr1)
                $dynParam1 = new-object System.Management.Automation.RuntimeDefinedParameter("TargetHost", [String], $attrCollection)  
                $paramDic.Add("TargetHost", $dynParam1)  
                return $paramDic
            }

        }
    
    }
    begin{}
    process{
        switch($EntryType.ToUpper()){
            "A"{  

                $entry = gwmi -Namespace 'root\MicrosoftDNS' -Class MicrosoftDNS_AType -Filter "ContainerName='$Container' and OwnerName='$EntryName'" -ComputerName $DNSServer  
                if ($entry -ne $null){
                    $Error.Clear()
                    $entry.Modify($null,$PSBoundParameters.IPAddress) | out-null
                    if ($Error.Count -eq 0){
                        $newEntry = gwmi -Namespace 'root\MicrosoftDNS' -Class MicrosoftDNS_AType -Filter "ContainerName='$Container' and OwnerName='$EntryName'" -ComputerName $DNSServer  
                        return $newEntry
                    }else{
                        return $false
                    }
                }else{
                    write-host "Ein Eintrag mit dem Name '$EntryName' konnte im Container '$Container' nicht gefunden werden!" -ForegroundColor Red  
                    return $false
                }

            }
            "CNAME"{  
       
                $entry = gwmi -Namespace 'root\MicrosoftDNS' -Class MicrosoftDNS_CNAMEType -Filter "ContainerName='$Container' and OwnerName='$EntryName'" -ComputerName $DNSServer  
                if ($entry -ne $null){
                    $Error.Clear()
                    $entry.Modify($null,$PSBoundParameters.TargetHost) | out-null
                   if ($Error.Count -eq 0){
                        $newEntry = gwmi -Namespace 'root\MicrosoftDNS' -Class MicrosoftDNS_CNAMEType -Filter "ContainerName='$Container' and OwnerName='$EntryName'" -ComputerName $DNSServer  
                        return $newEntry
                    }else{
                        return $false
                    }
                }else{
                    write-host "Ein Eintrag mit dem Name '$EntryName' konnte im Container '$Container' nicht gefunden werden!" -ForegroundColor Red  
                    return $false
                }
            }
        }
        
        
    }
    end{}
}
Benutzt wird das für A-Einträge dann so:
Change-DNSRecord -EntryType "CNAME" -Container "contoso.com" -EntryName "hostXYZ.contoso.com" -IPAddress "192.168.77.2"
und für CNAME Einträge so
Change-DNSRecord -EntryType CNAME -Container "contoso.com" -EntryName "hostXYZ.contoso.com" -TargetHost "mytarget.contoso.com"
Optional ist dann noch die Angabe des DNS-Servers mit dem Parameter -DNSServer, ansonsten wird der Server vermutet auf welchem das Script ausgeführt wird.

Viel Spaß.

Grüße Uwe
mexx
mexx 06.05.2014 um 10:36:51 Uhr
Goto Top
Vielen Dank für die Hilfe! face-smile