Aston-HyperV-Code/Guests/RTR-03.ps1

114 lines
2.7 KiB
PowerShell
Raw Permalink Normal View History

2021-04-22 11:05:32 +02:00
# Made by Alexandre SIMAO
2021-04-09 15:51:30 +02:00
# GPLv3
# Script to install and configure a Fuckdows Server 2016 as a router
# RTR-03 Only
2021-04-22 11:05:32 +02:00
# Script done
2021-04-09 15:51:30 +02:00
2021-04-22 11:05:32 +02:00
echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman"
2021-04-19 17:06:39 +02:00
### Change the poor machine name
echo "Renaming Computer as RTR-03"
2021-04-22 11:05:32 +02:00
Rename-computer RTR-03
echo "Done!"
#END
### Rename Adapters by parsing the VM device name
2021-04-09 15:51:30 +02:00
echo "Renaming adapter"
2021-04-22 11:05:32 +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-22 11:05:32 +02:00
}
echo "Done!"
#End
### Pausing to let things settle
2021-04-19 16:04:47 +02:00
echo "Sleeping 10s"
2021-04-22 17:26:29 +02:00
Sleep 10
echo "Done!"
2021-04-09 15:51:30 +02:00
2021-04-22 11:05:32 +02:00
#WAN IP conf
echo "IP configuration via netsh"
netsh interface ip set address name="WAN" static 192.168.255.254 255.255.255.0
echo "Done!"
2021-04-22 11:05:32 +02:00
#Aston
2021-04-22 11:05:32 +02:00
echo "Setting Aston interface as DHCP to be sure"
netsh interface ip set address name="Aston" DHCP
echo "Done!"
#END
2021-04-20 16:08:08 +02:00
### DNS Conf for all InterfaceAlias
echo "Setting 192.168.8.1 as default DNS on all interfaces"
foreach ($c in Get-NetAdapter) { write-host 'Setting DNS for' $c.interfaceName ; Set-DnsClientServerAddress -InterfaceIndex $c.interfaceindex -ServerAddresses ('192.168.8.1') }
echo "Done!"
#End
2021-04-22 11:05:32 +02:00
### Install Routing and necessary linked roles
2021-04-22 11:05:32 +02:00
#echo "installing Routing and Nat role+setting autostart"
2021-05-10 12:48:32 +02:00
Install-windowsFeature -Name Routing -IncludemanagementTools
2021-05-10 12:11:07 +02:00
Install-remoteAccess -VpnType Routingonly
set-service RemoteAccess -StartupType Automatic
Start-Service RemoteAccess
echo "Done!"
# Configure NAT
echo "Activating and configuring NAT"
2021-05-10 16:47:54 +02:00
netsh routing ip nat install
netsh routing ip nat add interface name="WAN" mode=Private
netsh routing ip nat add interface name="Aston" mode=FULL
echo "Done!"
### Change ZoneAlarm rule to accept incoming ICMP ipv4 probes ###
echo "changing firewall rule to accept ICMP probes"
2021-05-10 12:31:36 +02:00
Get-NetFirewallRule -name "*ICMP4-ERQ-In*" |Enable-NetFirewallRule
echo "Done!"
2021-05-10 12:31:36 +02:00
#END
### Set connection as Private
2021-04-22 11:05:32 +02:00
echo "Setting connection as private"
2021-05-10 12:31:36 +02:00
Get-NetAdapter | Set-NetConnectionProfile -NetworkCategory Private
echo "Done!"
#End
2021-04-20 16:08:08 +02:00
2021-04-09 15:51:30 +02:00
# Add routes
echo "Adding routes"
2021-04-09 15:51:30 +02:00
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.128.0/24 192.168.255.128
2021-04-22 11:05:32 +02:00
route add -p 0.0.0.0/0 192.168.255.254
echo "Done!"
2021-04-22 11:05:32 +02:00
# Renewing DHCP lease
echo "Renew DHCP Lease to be sure"
ipconfig /renew
# Add BGINFO autostart
Copy-Item "c:\Program Files\BGINFO\bginfo.bat" "C:\Users\Administrateur\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
#reboot
Read-Host "Press enter to reboot"
2021-05-10 11:43:22 +02:00
Restart-Computer