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

135 lines
3.2 KiB
PowerShell

# Made by Alexandre SIMAO
# GPLv3
# Script to install and configure a Fuckdows Server 2016 as a router
# RTR-01 Only
# Script done
echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman"
### Change the poor machine name
echo "Changing Computer's name"
Rename-computer RTR-01
# End of renaming
### Rename Adapters by parsing the VM device name
echo "Renaming adapters"
$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
echo "Sleeping 10s"
Sleep 10
#End
### Général IP configure
echo "IP configuration"
$MaskBits = 24 # This means subnet mask = 255.255.255.0
$IPType = "IPv4"
#Arc-SRV IP conf
netsh interface ip set address name="Arc-SRV" static 192.168.8.254 255.255.255.0
#Arc-CLI conf
netsh interface ip set address name="Arc-CLI" static 192.168.12.8 255.255.255.0
### WAN conf
netsh interface ip set address name="WAN" static 192.168.255.8 255.255.255.0`
192.168.255.254
### DNS Conf for all InterfaceAlias ###
echo "DNS conf"
foreach ($c in Get-NetAdapter) { write-host 'Setting DNS for' $c.interfaceName ; Set-DnsClientServerAddress -InterfaceIndex $c.interfaceindex -ServerAddresses ('9.9.9.9') }
# End of scriptlet
### Install Routing and necessary linked roles ###
echo "Installing Remote-Access, RSAT, Routing"
Install-WindowsFeature RemoteAccess, RSAT-RemoteAccess-PowerShell, Routing -IncludeManagementTools
# End of scritlet
### Install VPN (necessary?) ###
echo "Installing VPN"
echo "Install-remoteAccess -VpnType Vpn"
Install-remoteAccess -VpnType Vpn
# End of scritlet
### Activate NAT and DHCP Relay ###
echo "Activating NAT and DHCP Relay"
netsh routing ip relay install
netsh routing ip add interface name="Arc-SRV" state=enable
netsh routing ip add interface name="Arc-CLI" state=enable
netsh routing ip add interface name="WAN" state=enable
netsh routing ip relay add interface "WAN"
netsh rout ip rel set int ARC-SRV min=0
netsh routing ip relay add interface "Arc-CLI"
netsh rout ip rel set int ARC-SRV min=0
netsh routing ip relay add interface "Arc-SRV"
netsh rout ip rel set int WAN min=0
netsh routing ip relay add dhcpserver 192.168.8.1
### Activating remote-access role
set-service RemoteAccess -StartupType Automatic
Start-Service RemoteAccess
#END
### Activating DHCP Relay (Useless?)
#netsh -f ./Arc-CLI.conf
#netsh -f ./Arc-SRV.conf
#netsh -f ./WAN.conf
# End of scriptlet
### Set connection as private ###
echo "Set connection as private"
Set-NetConnectionProfile -networkcategory private
### Change ZoneAlarm rule to accept incoming ICMP ipv4 probes ###
echo "Allowing ICMPv4 probes"
$Params = @{
"Name" = 'vm-monitoring-icmpv4'
"Action" = 'Allow'
}
Set-NetFirewallRule @Params
# End of scritlet
### Add routes
echo "Adding route"
route add -p 192.168.128.8/24 192.168.255.128
route add -p 0.0.0.0/0 192.168.255.254
# End of scritlet
Read-Host "Finished???"
Restart-Computer