# Made by Alexandre SIMAO # GPLv3 # Script to install and configure a Fuckdows Server 2016 as a router # RTR-02 Only echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman" ### Change VM name echo "Changing computer Name" Rename-computer RTR-02 #End ### Rename Adapters by parsing the VM device name $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 30s" Sleep 10 #End ### Général IP configure echo "IP configuration" $MaskBits = 24 # This means subnet mask = 255.255.255.0 $IPType = "IPv4" #Bou-LAN IP conf $adapter = Get-NetAdapter | ? {$_.Name -eq "Bou-LAN"} $IP = "192.168.128.254" $adapter | New-NetIPAddress ` -AddressFamily $IPType ` -IPAddress $IP ` -PrefixLength $MaskBits #WAN $adapter = Get-NetAdapter | ? {$_.Name -eq "WAN"} $IP = "192.168.255.254" $adapter | New-NetIPAddress ` -AddressFamily $IPType ` -IPAddress $IP ` -PrefixLength $MaskBits ` # END ### DNS Conf for all InterfaceAlias echo "Configuring Dns" foreach ($c in Get-NetAdapter) { write-host 'Setting DNS for' $c.interfaceName ; Set-DnsClientServerAddress -InterfaceIndex $c.interfaceindex -ServerAddresses ('9.9.9.9') } #End ### Install Routing and necessary linked roles + autostart echo "Installing Remote-Access, RSAT, Routing + Auto-start" Install-WindowsFeature RemoteAccess, RSAT-RemoteAccess-PowerShell, Routing -IncludeManagementTools set-service RemoteAccess -StartupType Automatic Start-Service RemoteAccess #END ### Install VPN (?) echo "installing VPN role" Install-remoteAccess -VpnType Vpn #End ### Set connection as Private echo "Set connection as private" Set-NetConnectionProfile -NetworkCategory Private #END ### Activing ICMPv4 probes echo "Activating ICMPv4 probes" $Params = @{ "Name" = 'vm-monitoring-icmpv4' "Action" = 'Allow' } Set-NetFirewallRule @Params #END ### Activate NAT and DHCP Relay echo "Activate NAT and DHCP Relay" netsh routing ip relay install netsh routing ip add interface name="Bou-LAN" state=enable netsh routing ip add interface name="WAN" state=enable netsh routing ip relay add interface "Bou-LAN" netsh rout ip rel set int ARC-SRV min=0 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 #netsh -f ./WAN.conf #netsh -f ./Bou-LAN.conf ### Add routes echo "Adding routes" 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 0.0.0.0/0 192.168.255.254 Read-Host "Finished???"