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

110 lines
2.6 KiB
PowerShell
Raw 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-02 Only
2021-04-09 15:51:30 +02:00
2021-04-20 10:49:35 +02:00
echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman"
### Change VM name
echo "Changing computer Name"
2021-04-22 11:05:32 +02:00
Rename-computer RTR-02
#End
2021-04-09 15:51:30 +02:00
### Rename Adapters by parsing the VM device name
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
}
# End
### Pausing to let things settle
2021-04-19 16:04:47 +02:00
2021-04-22 15:58:53 +02:00
echo "Sleeping 30s"
2021-04-22 17:26:29 +02:00
Sleep 10
#End
2021-04-22 15:58:53 +02:00
### Général IP configure
2021-04-19 16:04:47 +02:00
echo "IP configuration"
2021-04-22 11:05:32 +02:00
$MaskBits = 24 # This means subnet mask = 255.255.255.0
$IPType = "IPv4"
2021-04-09 15:51:30 +02:00
2021-04-22 11:05:32 +02:00
#Bou-LAN IP conf
2021-04-09 15:51:30 +02:00
netsh interface ip set address name="Bou-LAN" static 192.168.128.254 255.255.255.0
2021-04-22 11:05:32 +02:00
#WAN
netsh interface ip set address name="WAN" static 192.168.255.128 255.255.255.0`
192.168.255.254
2021-04-22 11:05:32 +02:00
# END
### DNS Conf for all InterfaceAlias
echo "Configuring Dns"
2021-04-22 11:05:32 +02:00
foreach ($c in Get-NetAdapter) { write-host 'Setting DNS for' $c.interfaceName ; Set-DnsClientServerAddress -InterfaceIndex $c.interfaceindex -ServerAddresses ('9.9.9.9') }
#End
2021-04-20 16:08:08 +02:00
### Install Routing and necessary linked roles + autostart
2021-04-09 15:51:30 +02:00
echo "Installing Remote-Access, RSAT, Routing + Auto-start"
2021-04-22 11:05:32 +02:00
Install-WindowsFeature RemoteAccess, RSAT-RemoteAccess-PowerShell, Routing -IncludeManagementTools
set-service RemoteAccess -StartupType Automatic
Start-Service RemoteAccess
2021-04-22 11:05:32 +02:00
#END
### Install VPN (?)
echo "installing VPN role"
2021-04-22 11:05:32 +02:00
Install-remoteAccess -VpnType Vpn
#End
### Set connection as Private
echo "Set connection as private"
2021-04-22 11:05:32 +02:00
Set-NetConnectionProfile -NetworkCategory Private
#END
### Activing ICMPv4 probes
echo "Activating ICMPv4 probes"
2021-04-20 16:08:08 +02:00
$Params = @{
"Name" = 'vm-monitoring-icmpv4'
"Action" = 'Allow'
}
Set-NetFirewallRule @Params
#END
### Activate NAT and DHCP Relay
2021-04-20 16:08:08 +02:00
2021-04-22 11:05:32 +02:00
echo "Activate NAT and DHCP Relay"
2021-04-09 15:51:30 +02:00
netsh routing ip relay install
2021-04-22 11:05:32 +02:00
netsh routing ip add interface name="Bou-LAN" state=enable
2021-04-09 15:51:30 +02:00
netsh routing ip add interface name="WAN" state=enable
2021-04-22 11:05:32 +02:00
2021-04-09 15:51:30 +02:00
netsh routing ip relay add interface "Bou-LAN"
netsh rout ip rel set int BOU-LAN min=0
2021-04-22 11:05:32 +02:00
netsh routing ip relay add interface "WAN"
netsh rout ip rel set int WAN min=0
netsh routing ip relay add dhcpserver 192.168.8.1
2021-04-09 15:51:30 +02:00
#netsh -f ./WAN.conf
#netsh -f ./Bou-LAN.conf
2021-04-09 15:51:30 +02:00
### Add routes
2021-04-09 15:51:30 +02:00
echo "Adding routes"
2021-04-09 15:51:30 +02:00
route add -p 192.168.8.0/24 192.168.255.8
2021-04-22 11:05:32 +02:00
route add -p 192.168.12.0/24 192.168.255.8
2021-04-19 16:04:47 +02:00
route add -p 0.0.0.0/0 192.168.255.254
2021-04-22 11:05:32 +02:00
Read-Host "Finished???"
2021-05-10 11:43:22 +02:00
Restart-Computer