2021-04-21 18:04:39 +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-01 Only
2021-04-21 18:04:39 +02:00
# Script done
2021-04-09 15:51:30 +02:00
2021-04-23 12:54:01 +02:00
2021-04-20 10:49:35 +02:00
echo " Shamefully made by Alexandre Simao. Pardon-me M. Stallman "
2021-04-23 12:54:01 +02:00
### Change the poor machine name
echo " Changing Computer's name "
2021-04-20 10:49:35 +02:00
Rename-computer RTR - 01
2021-04-23 12:54:01 +02:00
# End of renaming
### Rename Adapters by parsing the VM device name
echo " Renaming adapters "
2021-04-21 17:59:14 +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-23 12:54:01 +02:00
#End
### Pausing to let things settle
2021-04-21 17:59:14 +02:00
2021-04-22 17:26:29 +02:00
echo " Sleeping 10s "
Sleep 10
2021-04-23 12:54:01 +02:00
#End
2021-04-22 15:58:53 +02:00
2021-04-23 12:54:01 +02:00
### Général IP configure
2021-04-20 16:08:08 +02:00
2021-04-23 12:54:01 +02:00
echo " IP configuration "
2021-04-21 12:16:54 +02:00
$MaskBits = 24 # This means subnet mask = 255.255.255.0
$IPType = " IPv4 "
2021-04-21 17:59:14 +02:00
#Arc-SRV IP conf
2021-04-23 17:37:49 +02:00
netsh interface ip set address name = " Arc-SRV " static 192.168 . 8 . 254 255.255 . 255 . 0
2021-04-21 17:59:14 +02:00
2021-04-23 12:54:01 +02:00
#Arc-CLI conf
2021-04-21 17:59:14 +02:00
2021-04-23 17:37:49 +02:00
netsh interface ip set address name = " Arc-CLI " static 192.168 . 12 . 8 255.255 . 255 . 0
2021-04-21 17:59:14 +02:00
2021-04-23 12:54:01 +02:00
### WAN conf
2021-04-21 17:59:14 +02:00
2021-05-10 11:45:50 +02:00
netsh interface ip set address name = " WAN " static 192.168 . 255 . 8 255.255 . 255 . 0 192.168 . 255 . 254
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-21 17:59:14 +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-20 16:08:08 +02:00
2021-04-23 12:54:01 +02:00
# End of scriptlet
### Install Routing and necessary linked roles ###
2021-04-09 15:51:30 +02:00
2021-04-23 12:54:01 +02:00
echo " Installing Remote-Access, RSAT, Routing "
2021-04-09 15:51:30 +02:00
Install-WindowsFeature RemoteAccess , RSAT-RemoteAccess -PowerShell , Routing -IncludeManagementTools
2021-04-23 12:54:01 +02:00
# End of scritlet
### Install VPN (necessary?) ###
echo " Installing VPN "
2021-04-21 17:59:14 +02:00
echo " Install-remoteAccess -VpnType Vpn "
Install-remoteAccess -VpnType Vpn
2021-04-09 15:51:30 +02:00
2021-04-23 12:54:01 +02:00
# End of scritlet
2021-04-21 17:59:14 +02:00
2021-04-23 12:54:01 +02:00
### Activate NAT and DHCP Relay ###
echo " Activating 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 = " Arc-SRV " state = enable
netsh routing ip add interface name = " Arc-CLI " state = enable
2021-04-09 15:51:30 +02:00
netsh routing ip add interface name = " WAN " state = enable
netsh routing ip relay add interface " WAN "
2021-04-22 11:05:32 +02:00
netsh rout ip rel set int ARC-SRV min = 0
2021-04-09 15:51:30 +02:00
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
2021-04-23 12:54:01 +02:00
### Activating remote-access role
2021-04-09 15:51:30 +02:00
set-service RemoteAccess -StartupType Automatic
Start-Service RemoteAccess
2021-04-23 12:54:01 +02:00
#END
### Activating DHCP Relay (Useless?)
2021-04-09 15:51:30 +02:00
2021-04-23 12:54:01 +02:00
#netsh -f ./Arc-CLI.conf
#netsh -f ./Arc-SRV.conf
#netsh -f ./WAN.conf
2021-04-09 15:51:30 +02:00
2021-04-23 12:54:01 +02:00
# End of scriptlet
### Set connection as private ###
echo " Set connection as private "
2021-04-20 16:08:08 +02:00
Set-NetConnectionProfile -networkcategory private
2021-04-23 12:54:01 +02:00
### 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 of scritlet
### Add routes
2021-04-09 15:51:30 +02:00
2021-04-23 12:54:01 +02:00
echo " Adding route "
2021-04-09 15:51:30 +02:00
route add -p 192.168 . 128 . 8 / 24 192.168 . 255 . 128
2021-04-19 16:04:47 +02:00
route add -p 0.0 . 0 . 0 / 0 192.168 . 255 . 254
2021-04-21 17:59:14 +02:00
2021-04-23 12:54:01 +02:00
# End of scritlet
2021-04-21 17:59:14 +02:00
Read-Host " Finished??? "
2021-05-10 11:43:22 +02:00
Restart-Computer