From e34e0cbe72e06ef19aa2d56e9787e65b727ea6c2 Mon Sep 17 00:00:00 2001 From: Winston Smith Date: Wed, 21 Apr 2021 17:59:14 +0200 Subject: [PATCH] Full auto RTR-01, seems functionnal --- Guests/RTR-01.ps1 | 49 +++++++++++++++++++++++++++++++++-------- Guests/SRV-01_DHCP.ps1 | 3 +-- Host/Infra-Standard.ps1 | 9 ++++---- Memo.ps1 | 14 ++++++++++++ 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/Guests/RTR-01.ps1 b/Guests/RTR-01.ps1 index 7818eaa..55a3ef8 100644 --- a/Guests/RTR-01.ps1 +++ b/Guests/RTR-01.ps1 @@ -10,28 +10,55 @@ echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman" Rename-computer RTR-01 -$adapter = Get-NetAdapter | ? {$_.MacAddress -eq "00-15-5D-02-70-00"} -Rename-NetAdapter -Name "Eth*" -NewName "Arc-SRV" +$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 +} + +#Général IP configure -#Arc-SRV -$IP = "192.168.8.1" $MaskBits = 24 # This means subnet mask = 255.255.255.0 -$Gateway = "192.168.8.254" -$Dns = "9.9.9.9" $IPType = "IPv4" +#Arc-SRV IP conf + +$adapter = Get-NetAdapter | ? {$_.Name -eq "Arc-SRV"} +$IP = "192.168.8.254" +$adapter | New-NetIPAddress ` + -AddressFamily $IPType ` + -IPAddress $IP ` + -PrefixLength $MaskBits + + #Arc-CLI + + $adapter = Get-NetAdapter | ? {$_.Name -eq "Arc-CLI"} + $IP = "192.168.12.254" + $adapter | New-NetIPAddress ` + -AddressFamily $IPType ` + -IPAddress $IP ` + -PrefixLength $MaskBits ` + +#WAN + +$adapter = Get-NetAdapter | ? {$_.Name -eq "WAN"} +$IP = "192.168.255.8" $adapter | New-NetIPAddress ` -AddressFamily $IPType ` -IPAddress $IP ` -PrefixLength $MaskBits ` - -DefaultGateway $Gateway + -DefaultGateway "192.168.255.254" +#DNS Conf for all InterfaceAlias +foreach ($c in Get-NetAdapter) { write-host 'Setting DNS for' $c.interfaceName ; Set-DnsClientServerAddress -InterfaceIndex $c.interfaceindex -ServerAddresses ('9.9.9.9') } # Install Routing and necessary linked roles Install-WindowsFeature RemoteAccess, RSAT-RemoteAccess-PowerShell, Routing -IncludeManagementTools -#Install-remoteAccess -VpnType Vpn +#Install VPN +echo "Install-remoteAccess -VpnType Vpn" +Install-remoteAccess -VpnType Vpn Set-NetConnectionProfile -NetworkCategory Private $Params = @{ "Name" = 'vm-monitoring-icmpv4' @@ -39,7 +66,9 @@ $Params = @{ } Set-NetFirewallRule @Params + # Activate NAT and DHCP Relay +echo "Activate NAT and DHCP Relay" netsh routing ip relay install netsh routing ip add interface name="WAN" state=enable @@ -72,7 +101,9 @@ Set-NetFirewallRule @Params # Add routes route add -p 192.168.8.0/24 192.168.8.254 -route add -p 192.168.12.0.24 192.168.12.254 +route add -p 192.168.12.0/24 192.168.12.254 route add -p 192.168.255.0/24 192.168.255.8 route add -p 192.168.128.8/24 192.168.255.128 route add -p 0.0.0.0/0 192.168.255.254 + +Read-Host "Finished???" diff --git a/Guests/SRV-01_DHCP.ps1 b/Guests/SRV-01_DHCP.ps1 index 14f6197..7c7646f 100644 --- a/Guests/SRV-01_DHCP.ps1 +++ b/Guests/SRV-01_DHCP.ps1 @@ -12,8 +12,7 @@ Rename-computer "SRV-1" # Set IP for pre-defined MAC addresses -$adapter = Get-NetAdapter | ? {$_.MacAddress -eq "00-15-5D-02-70-00"} -Rename-NetAdapter -Name "Eth*" -NewName "Arc-SRV" +$adapter = Get-NetAdapter | ? {$_.Name -eq "Arc-SRV"} #Arc-SRV $IP = "192.168.8.1" diff --git a/Host/Infra-Standard.ps1 b/Host/Infra-Standard.ps1 index 7d1da6d..34668a0 100644 --- a/Host/Infra-Standard.ps1 +++ b/Host/Infra-Standard.ps1 @@ -42,16 +42,15 @@ $vms = @{ Generation = '2' MemoryStartupBytes = 1024Mb VHDPath = "d:\VHD\RTR-01.vhdx" - SwitchName = 'Arc-SRV' } New-VM @vms Set-VMMemory RTR-01 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB $vmadapter = Get-VMNetworkAdapter -VMName "RTR-01" -Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[0] -StaticMacAddress 00155D027001 -Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "Arc-CLI" -Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "WAN" - +#Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[0] -Name "Arc-SRV" -DeviceNaming on +Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "Arc-CLI" -Name "Arc-Cli" -DeviceNaming on +Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "WAN" -Name "WAN" -DeviceNaming on +Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "Arc-SRV" -Name "Arc-SRV" -DeviceNaming on # RTR-02 diff --git a/Memo.ps1 b/Memo.ps1 index 9839beb..396b52d 100644 --- a/Memo.ps1 +++ b/Memo.ps1 @@ -2,6 +2,20 @@ Get-VMNetworkAdapter -VMName RTR-01|Format-Table -Property Switchname,Macaddress -HideTableHeaders |Export-Csv D:\scripts\Guests\MACS\test.csv -NoTypeInformation #echo $VMNETADAP | out-file -FilePath D:\scripts\Guests\MACS\temp.txt +#Arc-SRV +$IP = "192.168.8.1" +$MaskBits = 24 # This means subnet mask = 255.255.255.0 +$Gateway = "192.168.8.254" +$Dns = "9.9.9.9" +$IPType = "IPv4" + +$adapter | New-NetIPAddress ` + -AddressFamily $IPType ` + -IPAddress $IP ` + -PrefixLength $MaskBits ` + -DefaultGateway $Gateway + +