Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Powershell script-DNS

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Function InstallDNS

{

Servermanagercmd-Q c:\ role.xml | Out-Null

$xml= [XML] (Get-Content c:\ role.xml)

$dnsrole=$xml.servermanagerconfigurationquery.role | where {$_ .id-eq "dns"}

If ($dnsrole.Installed-eq $false)

{

Servermanagercmd-I $dnsrole.id

}

Else {Write-Host "DNS server role has been installed!"}

$dns=Get-Service dns

If ($dns.status-ne "Running")

{

Start-Service dns

}

}

Function SetIP

{

$nic=gwmi Win32_NetworkAdapterConfiguration-Filter "IPEnabled=$true"

If ($nic.DHCPEnabled)

{

Write-Host "set now" $nic.Description

$ip= "192.168.10.10"

$mask= "255.255.255.0"

$dns= "127.0.0.1"

$nic.EnableStatic ($ip,$mask)

$nic.SetDNSServerSearchOrder ($dns)

}

}

Function DnsConfig

{

$zonename= "benet.com"

$Aname= "www" # Host name

$Aip= "192.168.10.12" # Host IP address

$Aip_bj= "192.168.10.32"

$Cname= "ftp"

$zonename_bj= "bj.benet.com"

$ns= "server01.benet.com"

$nsip= "192.168.10.20"

$forwarder= "server02.benet.com"

$forwarderip= "192.168.10.30"

Write-Host "sets the forward search area."

Start-Sleep 2

Dnscmd / zoneadd $zonename / primary / file benet.dns # create a forward lookup zone

$reversip= "10.168.192" # set the reverse lookup area network ID

$reverszone=$reversip+ ".in-addr.arpa"

Write-Host "sets the reverse search area."

Start-Sleep 2

Dnscmd / zoneadd $reverszone / primary # create a reverse lookup zone

Write-Host "add Host record"

Start-Sleep 2

Dnscmd / recordadd $zonename $Aname A $Aip # set up www host IP

Dnscmd / recordadd $reverszone $Aip.split (".") [3] PTR $Aname "." $zonename # sets the reverse query name of the www host

Write-Host "set aliases"

Start-Sleep 2

Dnscmd / recordadd $zonename $Cname CNAME $Aname "." $zonename # sets the www host alias to ftp

Write-Host "set Benet.com subdomain BJ"

Start-Sleep 2

Dnscmd / zoneadd $zonename_bj / primary

Write-Host "add host record in bj.benet.com"

Start-Sleep 2

Dnscmd / recordadd $zonename_bj $Aname A $Aip_bj # add www host record to subdomain bj.betnet.com

Dnscmd / recordadd $reverszone $Aip_bj.split (".") [3] PTR $Aname "." $zonename_bj # adds a reverse query to the subdomain bj.benet.com

Write-Host "set host aliases in bj.benet.com"

Start-Sleep 2

Dnscmd / recordadd $zonename_bj $Cname CNAME $Aname "." $zonename_bj # sets the www.bj.benet.com host alias to ftp

Write-Host "add name server Server01"

Start-Sleep 2

Dnscmd / recordadd $zonename $ns.TrimEnd ("benet.com") A $nsip # add server01's host record

Dnscmd / recordadd $reverszone $nsip.split (".") [3] PTR $ns # add reverse query record for server01

Dnscmd / recordadd $zonename "@" NS $ns # sets server01 as the name server

Write-Host "delegate sh.benet.com settings to Server01"

Start-Sleep 2

Dnscmd / recordadd $zonename sh NS $ns

Write-Host "set DNS service forwarder to Server02"

Start-Sleep 2

Dnscmd / recordadd $zonename $forwarder.TrimEnd ("benet.com") A $forwarderip

Dnscmd / recordadd $reverszone $forwarderip.split (".") [3] PTR $forwarder

The dnscmd / resetforwarders $forwarderip / timeout 5 / slave # parameter Slave means that if the transponder fails to complete the query, no iterative query is performed, and / noslave enables the iterative query

}

InstallDNS

SetIP

DnsConfig

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report