# Alexandre Simao # GPL v3 # SRV-01 ONLY # asrc.local domain # TODO: Delegation echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman" ### Rename this piece of garbage echo "Changing Computer's name" Rename-computer "SRV-01" # End ### Rename interfaces by parsing VM device name echo "Renaming adapters" $adapts = Get-NetAdapter foreach ($adapt in $adapts) { $HVName = (Get-NetAdapterAdvancedProperty -name $adapt.name -DisplayName "Hyper-v Network Adapter Name").DisplayValue Rename-Netadapter -name $adapt.name -NewName $HVName } #End # Pausing to let things settle echo "Sleeping 10s" Sleep 10 ### Général IP configure # echo "IP configuration" #Arc-SRV netsh interface ip set address name="Arc-SRV" static 192.168.8.1 255.255.255.0 192.168.8.254 ### DNS Conf for all InterfaceAlias ### echo "DNS Conf" foreach ($c in Get-NetAdapter) { write-host 'Setting DNS for' $c.interfaceName ; Set-DnsClientServerAddress -InterfaceIndex $c.interfaceindex -ServerAddresses ('192.168.8.1,192.168.128.1') } ### Install the DHCP role (Management tools if you love Metrosexual UI) echo "Installing DHCP role" Install-WindowsFeature DHCP -IncludeManagementTools #END ### Setting connection as Private echo "Setting connection as Private" Set-NetConnectionProfile -NetworkCategory Private ### Create DHCP "security" groups echo "Creating DHCP security groups" netsh dhcp add securitygroups #END ### Restart the DHCP server echo "Restarting DHCP server" Restart-Service dhcpserver # END ###################Template####################### #Add-DhcpServerv4Scope -name "Corpnet" -StartRange 10.0.0.1 -EndRange 10.0.0.254 -SubnetMask 255.255.255.0 -State Active #Add-DhcpServerv4ExclusionRange -ScopeID 10.0.0.0 -StartRange 10.0.0.1 -EndRange 10.0.0.15 #Set-DhcpServerv4OptionValue -OptionID 3 -Value 10.0.0.1 -ScopeID 10.0.0.0 -ComputerName DHCP1.corp.contoso.com #Set-DhcpServerv4OptionValue -DnsDomain corp.contoso.com -DnsServer 10.0.0.2 ################################################## ### Create DHCP Scopes For Arc-CLI Arc-SRV Bou-Lan echo "Create DHCP Scopes For Arc-CLI Arc-SRV Bou-Lan" Add-DhcpServerv4Scope -name "Arc-SRV" -StartRange 192.168.8.1 -EndRange 192.168.8.254 -SubnetMask 255.255.255.0 -State Active Add-DhcpServerv4ExclusionRange -ScopeID 192.168.8.0 -StartRange 192.168.8.1 -EndRange 192.168.8.63 Add-DhcpServerv4ExclusionRange -ScopeID 192.168.8.0 -StartRange 192.168.8.240 -EndRange 192.168.8.254 Add-DhcpServerv4Scope -name "Arc-CLI" -StartRange 192.168.12.1 -EndRange 192.168.12.254 -SubnetMask 255.255.255.0 -State Active Add-DhcpServerv4ExclusionRange -ScopeID 192.168.12.0 -StartRange 192.168.12.1 -EndRange 192.168.12.63 Add-DhcpServerv4ExclusionRange -ScopeID 192.168.12.0 -StartRange 192.168.12.240 -EndRange 192.168.12.254 Add-DhcpServerv4Scope -name "Bou-LAN" -StartRange 192.168.128.1 -EndRange 192.168.128.254 -SubnetMask 255.255.255.0 -State Active Add-DhcpServerv4ExclusionRange -ScopeID 192.168.128.0 -StartRange 192.168.128.1 -EndRange 192.168.128.63 Add-DhcpServerv4ExclusionRange -ScopeID 192.168.128.0 -StartRange 192.168.128.240 -EndRange 192.168.128.254 #END ### Change ZoneAlarm rule to accept incoming ICMP ipv4 probes echo "Allowing ICMPv4 probes" $Params = @{ "Name" = 'vm-monitoring-icmpv4' "Action" = 'Allow' } Set-NetFirewallRule @Params # END ### Add routes for SRV-01 echo "Add routes for RTR-01" route add -p 192.168.12.0/24 192.168.8.254 route add -p 192.168.255.0/24 192.168.8.254 route add -p 192.168.128.0/24 192.168.8.254 route add -p 0.0.0.0/0 192.168.8.254 # END echo "Adding DHCP server options" Set-DhcpServerv4OptionValue -ScopeId 192.168.128.0 -Router 192.168.128.254 Set-DhcpServerv4OptionValue -ScopeId 192.168.12.0 -Router 192.168.12.254 Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -Router 192.168.8.254 Get-DhcpServerv4Scope | Set-DhcpServerv4OptionValue -DnsServer 192.168.128.1,192.168.8.1 ### Installing and configuring DNS role # Install and configure DNS server Install-WindowsFeature -Name DNS -IncludeManagementTools -includeallsubfeature #Create asrc.local zone Add-DnsServerPrimaryZone -ResponsiblePerson bol@loc.ks -DynamicUpdate None -ZoneFile asrc.local.dns -Name asrc.local Set-DnsServerPrimaryZone -ComputerName SRV-01 -Name "asrc.local" -SecureSecondaries "TransferToSecureServers" -SecondaryServers "192.168.128.1" #Rename SOA+NS Main Zone $ns = Get-DnsServerResourceRecord -ZoneName "asrc.local" -RRType NS $nsnew = $ns.Clone() $nsnew.RecordData.NameServer = "srv-01.asrc.local" Set-DnsServerResourceRecord -ZoneName asrc.local -NewInputObject $nsnew -OldInputObject $ns $soa = Get-DnsServerResourceRecord -ZoneName asrc.local -RRType Soa $soanew = $soa.Clone() $soanew.RecordData.PrimaryServer = "srv-01.asrc.local" $soanew.RecordData.ExpireLimit = (New-TimeSpan -Days 4) Set-DnsServerResourceRecord -ZoneName asrc.local -NewInputObject $soanew -OldInputObject $soa #Set zone transfer Set-DnsServerPrimaryZone -ComputerName SRV-01 -Name asrc.local -SecureSecondaries "TransferToSecureServers" -SecondaryServers "192.168.128.1" #Create reverse lookup Zone Add-DnsServerPrimaryZone -NetworkID "192.168.0.0/16" -Zonefile "168.192.in-addr.arpa.dns" #Rename SOA+NS Reverse $ns = Get-DnsServerResourceRecord -ZoneName 168.192.in-addr.arpa -RRType NS $nsnew = $ns.Clone() $nsnew.RecordData.NameServer = "srv-01.asrc.local" Set-DnsServerResourceRecord -ZoneName 168.192.in-addr.arpa -NewInputObject $nsnew -OldInputObject $ns $soa = Get-DnsServerResourceRecord -ZoneName 168.192.in-addr.arpa -RRType Soa $soanew = $soa.Clone() $soanew.RecordData.PrimaryServer = "srv-01.asrc.local" $soanew.RecordData.ExpireLimit = (New-TimeSpan -Days 4) Set-DnsServerResourceRecord -ZoneName asrc.local -NewInputObject $soanew -OldInputObject $soa # Set DNS SRV-03 forwarder Add-DnsServerConditionalForwarderZone -Name "asrc.devs" -MasterServers 192.168.128.1 -PassThru Add-DnsServerConditionalForwarderZone -Name "devs.asrc.devs" -MasterServers 192.168.128.1 -PassThru # Set DNS net forwarder Add-DnsServerForwarder -IPAddress 9.9.9.9 -PassThru # Forward # Add records Add-DnsServerResourceRecordA -Name "srv-01" -ZoneName "asrc.local" -IPv4Address "192.168.8.1" -TimeToLive 01:00:00 -CreatePTR Add-DnsServerResourceRecordA -Name "srv-02" -ZoneName "asrc.local" -IPv4Address "192.168.8.2" -TimeToLive 01:00:00 -CreatePTR Add-DnsServerResourceRecordA -Name "srv-03" -ZoneName "asrc.local" -IPv4Address "192.168.128.1" -TimeToLive 01:00:00 -CreatePTR Add-DnsServerResourceRecord -ZoneName "asrc.local" -NS -Name asrc.local -Nameserver "srv-03.asrc.local." #Add-DnsServerResourceRecord -ZoneName "asrc.local" -A -Name dev.asrc.local -IPv4Address "192.168.128.1" Add-DnsServerZoneTransferPolicy -Name "asrc.local" -Action IGNORE -ServerInterfaceIP "ne,192.168.128.1" -PassThru -ZoneName "asrc.local" #Add-DnsServerZoneDelegation -Name "asrc.local" -ChildZoneName "dev" -NameServer "srv-03.asrc.local." -IPAddress 192.168.128.1 -PassThru -Verbose # Add local DNS for all Hosts echo "Add local DNS for all Hosts" Get-DhcpServerv4Scope | Set-DhcpServerv4OptionValue -DnsServer 192.168.8.1 Get-DhcpServerv4Scope | Set-DhcpServerv4OptionValue -DnsServer 192.168.128.1 Read-Host "Finished?" Restart-Computer