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服务器角色已经安装!"}
$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 "现在设置" $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 "设置正向搜索区域。。。"
Start-Sleep 2
dnscmd /zoneadd $zonename /primary /file benet.dns #创建正向查找区域
$reversip="10.168.192" #设置反向查找区域网络ID
$reverszone=$reversip+".in-addr.arpa"
Write-Host "设置反向搜索区域。。。"
Start-Sleep 2
dnscmd /zoneadd $reverszone /primary #创建反向查找区域
Write-Host "添加主机记录"
Start-Sleep 2
dnscmd /recordadd $zonename $Aname A $Aip #设置www主机IP
dnscmd /recordadd $reverszone $Aip.split(".")[3] PTR $Aname"."$zonename #设置www主机反向查询名称
Write-Host "设置别名"
Start-Sleep 2
dnscmd /recordadd $zonename $Cname CNAME $Aname"."$zonename #设置www主机别名为ftp
Write-Host "设置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设置主机别名"
Start-Sleep 2
dnscmd /recordadd $zonename_bj $Cname CNAME $Aname"."$zonename_bj #设置www.bj.benet.com主机别名为ftp
Write-Host "添加名称服务器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设置为名称服务器
Write-Host "对sh.benet.com设置委派为Server01"
Start-Sleep 2
dnscmd /recordadd $zonename sh NS $ns
Write-Host "设置DNS服务转发器为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 #参数Slave表示如果转发器未能完成查询,不进行迭代查询,/noslave 则启用迭代查询
}
InstallDNS
SetIP
DnsConfig
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。