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服務(wù)器角色已經(jīng)安裝!"}
$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 "現(xiàn)在設(shè)置" $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" #主機名稱
$Aip="192.168.10.12" #主機IP地址
$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 "設(shè)置正向搜索區(qū)域。。。"
Start-Sleep 2
dnscmd /zoneadd $zonename /primary /file benet.dns #創(chuàng)建正向查找區(qū)域
$reversip="10.168.192" #設(shè)置反向查找區(qū)域網(wǎng)絡(luò)ID
$reverszone=$reversip+".in-addr.arpa"
Write-Host "設(shè)置反向搜索區(qū)域。。。"
Start-Sleep 2
dnscmd /zoneadd $reverszone /primary #創(chuàng)建反向查找區(qū)域
Write-Host "添加主機記錄"
Start-Sleep 2
dnscmd /recordadd $zonename $Aname A $Aip #設(shè)置www主機IP
dnscmd /recordadd $reverszone $Aip.split(".")[3] PTR $Aname"."$zonename #設(shè)置www主機反向查詢名稱
Write-Host "設(shè)置別名"
Start-Sleep 2
dnscmd /recordadd $zonename $Cname CNAME $Aname"."$zonename #設(shè)置www主機別名為ftp
Write-Host "設(shè)置Benet.com子域BJ"
Start-Sleep 2
dnscmd /zoneadd $zonename_bj /primary
Write-Host "在bj.benet.com中添加主機記錄"
Start-Sleep 2
dnscmd /recordadd $zonename_bj $Aname A $Aip_bj #在子域bj.betnet.com中添加www主機記錄
dnscmd /recordadd $reverszone $Aip_bj.split(".")[3] PTR $Aname"."$zonename_bj #在子域bj.benet.com中添加反向查詢
Write-Host "在bj.benet.com設(shè)置主機別名"
Start-Sleep 2
dnscmd /recordadd $zonename_bj $Cname CNAME $Aname"."$zonename_bj #設(shè)置www.bj.benet.com主機別名為ftp
Write-Host "添加名稱服務(wù)器Server01"
Start-Sleep 2
dnscmd /recordadd $zonename $ns.TrimEnd("benet.com") A $nsip #添加server01的主機記錄
dnscmd /recordadd $reverszone $nsip.split(".")[3] PTR $ns #添加server01的反向查詢記錄
dnscmd /recordadd $zonename "@" NS $ns #將server01設(shè)置為名稱服務(wù)器
Write-Host "對sh.benet.com設(shè)置委派為Server01"
Start-Sleep 2
dnscmd /recordadd $zonename sh NS $ns
Write-Host "設(shè)置DNS服務(wù)轉(zhuǎn)發(fā)器為Server02"
Start-Sleep 2
dnscmd /recordadd $zonename $forwarder.TrimEnd("benet.com") A $forwarderip
dnscmd /recordadd $reverszone $forwarderip.split(".")[3] PTR $forwarder
dnscmd /resetforwarders $forwarderip /timeout 5 /slave #參數(shù)Slave表示如果轉(zhuǎn)發(fā)器未能完成查詢,不進(jìn)行迭代查詢,/noslave 則啟用迭代查詢
}
InstallDNS
SetIP
DnsConfig
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。