From f2f8fdf7706080e5ac6454f48d58287838dd5a60 Mon Sep 17 00:00:00 2001 From: Winston Smith Date: Thu, 22 Apr 2021 10:46:50 +0200 Subject: [PATCH] Fix: Del on-link routes --- Guests/RTR-01.ps1 | 3 -- Guests/RTR-02_OLD.ps1 | 64 +++++++++++++++++++++++++++++++++++++++++ Guests/SRV-01_DHCP.ps1 | 16 +++++++++-- Host/Infra-Standard.ps1 | 18 +++++------- 4 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 Guests/RTR-02_OLD.ps1 diff --git a/Guests/RTR-01.ps1 b/Guests/RTR-01.ps1 index a7c9daa..a2b78fc 100644 --- a/Guests/RTR-01.ps1 +++ b/Guests/RTR-01.ps1 @@ -101,9 +101,6 @@ 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.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 diff --git a/Guests/RTR-02_OLD.ps1 b/Guests/RTR-02_OLD.ps1 new file mode 100644 index 0000000..3530bae --- /dev/null +++ b/Guests/RTR-02_OLD.ps1 @@ -0,0 +1,64 @@ +# Alexandre SIMAO +# GPLv3 + +# Script to install and configure a Fuckdows Server 2016 as a router +# RTR-02 Only + +echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman" + +# Change the poor machine name +Rename-computer "RTR-02" + +Rename-NetAdapter -Name "Ethernet" -NewName "Bou-LAN" +Rename-NetAdapter -Name "Ethernet 2" -NewName "WAN" + +netsh interface ip set address "WAN" static 192.168.255.8 255.255.255.0 192.168.255.254 +netsh interface ip set address "Bou-LAN" static 192.168.128.254 255.255.255.0 +netsh interface ip set dns name="WAN" static 9.9.9.9. + +# Install Routing and necessary linked roles +Install-WindowsFeature RemoteAccess, RSAT-RemoteAccess-PowerShell, Routing -IncludeManagementTools +set-service RemoteAccess -StartupType Automatic +Start-Service RemoteAccess + +# Display interfaces and active forwarding for all of thm via Regedit +netsh inter show inter + + +Set-NetConnectionProfile -NetworkCategory Private + +$Params = @{ + "Name" = 'vm-monitoring-icmpv4' + "Action" = 'Allow' +} + +Set-NetFirewallRule @Params + +# Activate NAT and DHCP Relay +netsh routing ip relay install + +netsh routing ip add interface name="WAN" state=enable + +netsh routing ip relay add interface "WAN" +netsh rout ip rel set int ARC-CLI min=0 +netsh routing ip relay add interface "Bou-LAN" +netsh rout ip rel set int ARC-SRV min=0 + + +netsh -f ./Bou-LAN.conf + +# Change ZoneAlarm rule to accept incoming ICMP ipv4 probes +$Params = @{ + "Name" = 'vm-monitoring-icmpv4' + "Action" = 'Allow' +} + +Set-NetFirewallRule @Params + +# Add routes + +route add -p 192.168.8.0/24 192.168.255.8 +route add -p 192.168.12.0.24 192.168.255.8 +route add -p 192.168.255.0/24 192.168.255.128 +route add -p 192.168.128.0/24 192.168.128.254 +route add -p 0.0.0.0/0 192.168.255.254 diff --git a/Guests/SRV-01_DHCP.ps1 b/Guests/SRV-01_DHCP.ps1 index 7c7646f..6f4294a 100644 --- a/Guests/SRV-01_DHCP.ps1 +++ b/Guests/SRV-01_DHCP.ps1 @@ -10,6 +10,14 @@ echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman" #Rename this piece of garbage Rename-computer "SRV-1" +# Rename interfaces + +$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 +} + # Set IP for pre-defined MAC addresses $adapter = Get-NetAdapter | ? {$_.Name -eq "Arc-SRV"} @@ -18,7 +26,6 @@ $adapter = Get-NetAdapter | ? {$_.Name -eq "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 ` @@ -27,6 +34,9 @@ $adapter | New-NetIPAddress ` -PrefixLength $MaskBits ` -DefaultGateway $Gateway +# Set DNS + +foreach ($c in Get-NetAdapter) { write-host 'Setting DNS for' $c.interfaceName ; Set-DnsClientServerAddress -InterfaceIndex $c.interfaceindex -ServerAddresses ('9.9.9.9') } # Install the DHCP role (Management tools if you love Metrosexual UI) Install-WindowsFeature DHCP -IncludeManagementTools @@ -86,9 +96,9 @@ route add -p 0.0.0.0/0 192.168.8.254 # Change DHCP server options Set-DhcpServerv4OptionValue -ScopeId 192.168.128.0 -OptionID 3 -Value 192.168.128.254 -Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -DnsServer 9.9.9.9 +Set-DhcpServerv4OptionValue -ScopeId 192.168.128.0 -DnsServer 9.9.9.9 Set-DhcpServerv4OptionValue -ScopeId 192.168.12.0 -OptionID 3 -Value 192.168.12.254 -Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -DnsServer 9.9.9.9 +Set-DhcpServerv4OptionValue -ScopeId 192.168.12.0 -DnsServer 9.9.9.9 Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -OptionID 3 -Value 192.168.8.254 Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -DnsServer 9.9.9.9 diff --git a/Host/Infra-Standard.ps1 b/Host/Infra-Standard.ps1 index d739836..3462989 100644 --- a/Host/Infra-Standard.ps1 +++ b/Host/Infra-Standard.ps1 @@ -7,7 +7,6 @@ echo "CC BY-NC-SA 4.0" # Region SRV-01 - cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\SRV-01.vhdx Mount-VHD d:\VHD\SRV-01.vhdx @@ -20,14 +19,12 @@ $vms = @{ Generation = '2' MemoryStartupBytes = 1024Mb VHDPath = "d:\VHD\$VMName.vhdx" - SwitchName = 'Arc-SRV' - } New-VM @vms Set-VMMemory SRV-01 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB $vmadapter = Get-VMNetworkAdapter -VMName "SRV-01" -Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[0] -StaticMacAddress 00155D027000 +Add-VMNetworkAdapter -VMName "SRV-01" -SwitchName "Arc-SRV" -Name "Arc-SRV" -DeviceNaming on # RTR-01 @@ -67,16 +64,15 @@ $vms = @{ Generation = '2' MemoryStartupBytes = 1024Mb VHDPath = "d:\VHD\$VMName.vhdx" - SwitchName = 'Bou-LAN' } New-VM @vms Set-VMMemory RTR-03 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB -$vmadapter = Get-VMNetworkAdapter -VMName "RTR-01" -Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[0] -StaticMacAddress 00155D027004 -Add-VMNetworkAdapter -VMName RTR-02 -SwitchName "WAN" -StaticMacAddress 00155D027005 +$vmadapter = Get-VMNetworkAdapter -VMName "RTR-02" +Add-VMNetworkAdapter -VMName "RTR-02" -SwitchName "Arc-CLI" -Name "Bou-LAN" -DeviceNaming on +Add-VMNetworkAdapter -VMName "RTR-02" -SwitchName "WAN" -Name "WAN" -DeviceNaming on # RTR-03 @@ -102,9 +98,9 @@ New-VM @vms Set-VMMemory RTR-03 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB -$vmadapter = Get-VMNetworkAdapter -VMName "RTR-01" -Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[0] -StaticMacAddress 00155D027006 -Add-VMNetworkAdapter -VMName RTR-03 -SwitchName "Aston" -StaticMacAddress 00155D027007 +$vmadapter = Get-VMNetworkAdapter -VMName "RTR-03" +Add-VMNetworkAdapter -VMName "RTR-03" -SwitchName "Aston" -Name "Aston" -DeviceNaming on +Add-VMNetworkAdapter -VMName "RTR-03" -SwitchName "WAN" -Name "WAN" -DeviceNaming on Start-VM -Name RTR*