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
2021-04-23 12:54:01 +02:00
# 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
2021-04-23 12:54:01 +02:00
### Change the poor machine name
echo " Renaming Computer "
2021-04-22 11:05:32 +02:00
Rename-computer RTR - 03
2021-04-23 12:54:01 +02:00
#END
### Rename Adapters by parsing the VM device name
2021-04-09 15:51:30 +02:00
2021-04-23 12:54:01 +02:00
echo " Renaming Computer "
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
2021-04-22 15:58:53 +02:00
Rename-Netadapter -name " $adapt .name " -NewName " $HVName "
2021-04-22 11:05:32 +02:00
}
2021-04-23 12:54:01 +02:00
#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
2021-04-22 15:58:53 +02:00
2021-04-23 12:54:01 +02:00
### Général IP configure
2021-04-09 15:51:30 +02:00
2021-04-23 12:54:01 +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
#WAN IP conf
$adapter = Get-NetAdapter | ? { $_ . Name -eq " WAN " }
$IP = " 192.168.255.254 "
$adapter | New-NetIPAddress `
-AddressFamily $IPType `
-IPAddress $IP `
-PrefixLength $MaskBits
#Aston
$adapter = Get-NetAdapter | ? { $_ . Name -eq " Aston " }
$IP = " 192.168.255.254 "
$adapter | Set-NetIPInterface -Dhcp Enabled
2021-04-20 16:08:08 +02:00
2021-04-23 12:54:01 +02:00
### DNS Conf for all InterfaceAlias
echo " DNS conf "
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' ) }
2021-04-23 12:54:01 +02:00
#End
2021-04-22 11:05:32 +02:00
2021-04-23 12:54:01 +02:00
### Install Routing and necessary linked roles
2021-04-22 11:05:32 +02:00
2021-04-23 12:54:01 +02:00
echo " Installing Routing and necessary linked roles "
2021-04-22 11:05:32 +02:00
Install-WindowsFeature RemoteAccess , RSAT-RemoteAccess -PowerShell , Routing -IncludeManagementTools
2021-04-23 12:54:01 +02:00
### Install VPN (?)
echo " Install Vpn "
2021-04-22 11:05:32 +02:00
Install-remoteAccess -VpnType Vpn
2021-04-23 12:54:01 +02:00
#End
### Change ZoneAlarm rule to accept incoming ICMP ipv4 probes ###
echo " Allowing ICMPv4 probes "
2021-04-09 15:51:30 +02:00
$Params = @ {
" Name " = 'vm-monitoring-icmpv4'
" Action " = 'Allow'
}
Set-NetFirewallRule @Params
2021-04-23 12:54:01 +02:00
#END
2021-04-09 15:51:30 +02:00
2021-04-23 12:54:01 +02:00
### Activating remote-access role
echo " Activating remote-access role "
2021-04-22 11:05:32 +02:00
set-service RemoteAccess -StartupType Automatic
Start-Service RemoteAccess
2021-04-23 12:54:01 +02:00
#End
2021-04-22 11:05:32 +02:00
2021-04-23 12:54:01 +02:00
#netsh -f ./WAN.conf
2021-04-22 11:05:32 +02:00
2021-04-23 12:54:01 +02:00
### Set connection as Private
2021-04-22 11:05:32 +02:00
2021-04-23 12:54:01 +02:00
echo " Setting connection as private "
Set-NetConnectionProfile -networkcategory private
#End
2021-04-20 16:08:08 +02:00
2021-04-09 15:51:30 +02:00
# Add routes
2021-04-23 12:54:01 +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
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
Read-Host " Finished??? "