2021-04-09 11:02:54 +02:00
# Alexandre Simao
# GPL v3
2021-04-19 17:06:39 +02:00
# SRV-01 ONLY
2021-06-02 14:26:00 +02:00
# asrc.local domain
2021-05-12 16:25:20 +02:00
2021-06-01 10:27:57 +02:00
# TODO: Delegation
2021-04-23 12:54:01 +02:00
2021-04-20 15:25:09 +02:00
echo " Shamefully made by Alexandre Simao. Pardon-me M. Stallman "
2021-04-19 17:06:39 +02:00
2021-04-23 12:54:01 +02:00
### Rename this piece of garbage
echo " Changing Computer's name "
2021-05-11 16:46:18 +02:00
Rename-computer " SRV-01 "
2021-04-23 12:54:01 +02:00
# End
2021-04-21 12:16:54 +02:00
2021-04-23 12:54:01 +02:00
### Rename interfaces by parsing VM device name
2021-04-22 10:46:50 +02:00
2021-04-23 12:54:01 +02:00
echo " Renaming adapters "
2021-04-23 17:37:49 +02:00
$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
}
2021-04-23 12:54:01 +02:00
#End
# Pausing to let things settle
2021-04-22 10:46:50 +02:00
2021-05-10 11:49:17 +02:00
echo " Sleeping 10s "
2021-04-22 17:26:29 +02:00
Sleep 10
2021-04-22 15:58:53 +02:00
2021-04-23 12:54:01 +02:00
### Général IP configure
# echo "IP configuration"
2021-04-21 12:16:54 +02:00
2021-04-22 15:58:53 +02:00
#Arc-SRV
2021-05-10 17:52:41 +02:00
netsh interface ip set address name = " Arc-SRV " static 192.168 . 8 . 1 255.255 . 255 . 0 192.168 . 8 . 254
2021-04-22 15:58:53 +02:00
2021-04-23 12:54:01 +02:00
### DNS Conf for all InterfaceAlias ###
2021-04-22 10:46:50 +02:00
2021-04-23 12:54:01 +02:00
echo " DNS Conf "
2021-06-01 10:27:57 +02:00
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' ) }
2021-04-09 11:02:54 +02:00
2021-04-23 12:54:01 +02:00
### Install the DHCP role (Management tools if you love Metrosexual UI)
echo " Installing DHCP role "
2021-04-09 11:02:54 +02:00
Install-WindowsFeature DHCP -IncludeManagementTools
2021-04-23 12:54:01 +02:00
#END
### Setting connection as Private
echo " Setting connection as Private "
2021-04-20 10:49:35 +02:00
Set-NetConnectionProfile -NetworkCategory Private
2021-04-09 11:02:54 +02:00
2021-04-23 12:54:01 +02:00
### Create DHCP "security" groups
echo " Creating DHCP security groups "
2021-04-09 11:02:54 +02:00
netsh dhcp add securitygroups
2021-04-23 12:54:01 +02:00
#END
### Restart the DHCP server
echo " Restarting DHCP server "
2021-04-09 11:02:54 +02:00
Restart-Service dhcpserver
2021-04-23 12:54:01 +02:00
# END
2021-04-09 11:02:54 +02:00
###################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
##################################################
2021-04-23 12:54:01 +02:00
### Create DHCP Scopes For Arc-CLI Arc-SRV Bou-Lan
echo " Create DHCP Scopes For Arc-CLI Arc-SRV Bou-Lan "
2021-04-09 11:02:54 +02:00
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
2021-04-23 12:54:01 +02:00
#END
2021-04-09 11:34:47 +02:00
2021-05-10 17:24:51 +02:00
### Change ZoneAlarm rule to accept incoming ICMP ipv4 probes
2021-04-09 11:34:47 +02:00
2021-05-10 17:24:51 +02:00
echo " Allowing ICMPv4 probes "
$Params = @ {
" Name " = 'vm-monitoring-icmpv4'
" Action " = 'Allow'
}
2021-04-09 11:34:47 +02:00
2021-05-10 17:24:51 +02:00
Set-NetFirewallRule @Params
# END
2021-04-09 11:48:13 +02:00
2021-06-01 11:40:58 +02:00
### Add routes for SRV-01
2021-04-09 15:28:45 +02:00
2021-04-23 12:54:01 +02:00
echo " Add routes for RTR-01 "
2021-04-09 11:48:13 +02:00
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
2021-04-19 17:06:39 +02:00
route add -p 0.0 . 0 . 0 / 0 192.168 . 8 . 254
2021-04-23 12:54:01 +02:00
# END
2021-04-21 12:16:54 +02:00
2021-04-23 12:54:01 +02:00
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
2021-06-01 10:25:01 +02:00
Get-DhcpServerv4Scope | Set-DhcpServerv4OptionValue -DnsServer 192.168 . 128 . 1 , 192.168 . 8 . 1
2021-06-01 10:55:34 +02:00
2021-05-11 16:46:18 +02:00
### Installing and configuring DNS role
2021-05-11 17:02:57 +02:00
# Install and configure DNS server
2021-05-11 16:46:18 +02:00
Install-WindowsFeature -Name DNS -IncludeManagementTools -includeallsubfeature
2021-06-02 14:26:00 +02:00
#Create asrc.local zone
2021-06-01 11:40:58 +02:00
2021-06-02 14:26:00 +02:00
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 "
2021-06-01 15:30:37 +02:00
2021-06-02 09:44:32 +02:00
#Rename SOA+NS Main Zone
2021-06-02 14:26:00 +02:00
$ns = Get-DnsServerResourceRecord -ZoneName " asrc.local " -RRType NS
2021-06-01 15:30:37 +02:00
$nsnew = $ns . Clone ( )
2021-06-02 14:26:00 +02:00
$nsnew . RecordData . NameServer = " srv-01.asrc.local "
2021-06-01 15:30:37 +02:00
2021-06-02 14:26:00 +02:00
Set-DnsServerResourceRecord -ZoneName asrc . local -NewInputObject $nsnew -OldInputObject $ns
2021-06-01 15:30:37 +02:00
2021-06-02 14:26:00 +02:00
$soa = Get-DnsServerResourceRecord -ZoneName asrc . local -RRType Soa
2021-06-01 15:30:37 +02:00
$soanew = $soa . Clone ( )
2021-06-02 14:26:00 +02:00
$soanew . RecordData . PrimaryServer = " srv-01.asrc.local "
2021-06-01 15:30:37 +02:00
$soanew . RecordData . ExpireLimit = ( New-TimeSpan -Days 4 )
2021-06-02 14:26:00 +02:00
Set-DnsServerResourceRecord -ZoneName asrc . local -NewInputObject $soanew -OldInputObject $soa
2021-06-01 15:30:37 +02:00
2021-06-02 09:44:32 +02:00
#Set zone transfer
2021-06-02 15:29:55 +02:00
Set-DnsServerPrimaryZone -ComputerName SRV - 01 -Name asrc . local -SecureSecondaries " TransferToZoneNameServer " -SecondaryServers " 192.168.128.1 "
2021-06-01 11:40:58 +02:00
2021-06-02 09:44:32 +02:00
#Create reverse lookup Zone
2021-06-02 10:12:04 +02:00
Add-DnsServerPrimaryZone -NetworkID " 192.168.0.0/16 " -Zonefile " 168.192.in-addr.arpa.dns "
2021-06-02 09:44:32 +02:00
#Rename SOA+NS Reverse
$ns = Get-DnsServerResourceRecord -ZoneName 168.192 . in-addr . arpa -RRType NS
$nsnew = $ns . Clone ( )
2021-06-02 14:26:00 +02:00
$nsnew . RecordData . NameServer = " srv-01.asrc.local "
2021-06-02 09:44:32 +02:00
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 ( )
2021-06-02 14:26:00 +02:00
$soanew . RecordData . PrimaryServer = " srv-01.asrc.local "
2021-06-02 09:44:32 +02:00
$soanew . RecordData . ExpireLimit = ( New-TimeSpan -Days 4 )
2021-06-02 14:26:00 +02:00
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
2021-06-02 09:44:32 +02:00
2021-06-02 14:26:00 +02:00
# Set DNS net forwarder
2021-05-11 17:31:11 +02:00
Add-DnsServerForwarder -IPAddress 9.9 . 9 . 9 -PassThru # Forward
2021-06-02 14:26:00 +02:00
# 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
2021-05-11 17:31:11 +02:00
2021-05-12 10:58:01 +02:00
# Add local DNS for all Hosts
echo " Add local DNS for all Hosts "
2021-05-12 09:53:56 +02:00
Get-DhcpServerv4Scope | Set-DhcpServerv4OptionValue -DnsServer 192.168 . 8 . 1
2021-06-01 10:18:07 +02:00
Get-DhcpServerv4Scope | Set-DhcpServerv4OptionValue -DnsServer 192.168 . 128 . 1
2021-04-21 12:16:54 +02:00
2021-04-23 12:54:01 +02:00
Read-Host " Finished? "
2021-05-10 11:43:22 +02:00
Restart-Computer