Functionnal MAC SRV-01 and RTR-01 in Host

This commit is contained in:
Alex 2021-04-21 12:16:54 +02:00
parent 088117d57a
commit 519343ba51
5 changed files with 141 additions and 100 deletions

View File

@ -10,15 +10,21 @@ echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman"
Rename-computer RTR-01
Rename-NetAdapter -Name "Ethernet" -NewName "Arc-SRV"
netsh interface ip set address "Arc-SRV" static 192.168.8.254 255.255.255.0
$adapter = Get-NetAdapter | ? {$_.MacAddress -eq "00-15-5D-02-70-00"}
Rename-NetAdapter -Name "Ethernet 2" -NewName "Arc-CLI"
netsh interface ip set address "Arc-CLI" static 192.168.12.254 255.255.255.0
#Arc-SRV
$IP = "192.168.8.1"
$MaskBits = 24 # This means subnet mask = 255.255.255.0
$Gateway = "192.168.8.254"
$Dns = "9.9.9.9"
$IPType = "IPv4"
$adapter | New-NetIPAddress `
-AddressFamily $IPType `
-IPAddress $IP `
-PrefixLength $MaskBits `
-DefaultGateway $Gateway
Rename-NetAdapter -Name "Ethernet 3" -NewName "WAN"
netsh interface ip set address "WAN" static 192.168.255.8 255.255.255.0 192.168.255.254
netsh interface ip set dns name="WAN" static 9.9.9.9
# Install Routing and necessary linked roles

View File

@ -9,7 +9,25 @@ echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman"
#Rename this piece of garbage
Rename-computer "SRV-1"
Rename-NetAdapter -Name "Ethernet" -NewName "Arc-SRV"
# Set IP for pre-defined MAC addresses
$adapter = Get-NetAdapter | ? {$_.MacAddress -eq "00-15-5D-02-70-00"}
Rename-NetAdapter -Name "Eth*" -NewName "Arc-SRV"
#Arc-SRV
$IP = "192.168.8.1"
$MaskBits = 24 # This means subnet mask = 255.255.255.0
$Gateway = "192.168.8.254"
$Dns = "9.9.9.9"
$IPType = "IPv4"
$adapter | New-NetIPAddress `
-AddressFamily $IPType `
-IPAddress $IP `
-PrefixLength $MaskBits `
-DefaultGateway $Gateway
# Install the DHCP role (Management tools if you love Metrosexual UI)
Install-WindowsFeature DHCP -IncludeManagementTools
@ -19,8 +37,8 @@ netsh inter ipv4 show inter
Set-NetConnectionProfile -NetworkCategory Private
# Behold the LoserShell "cmdlet" to attribute static IP
New-NetIPAddress -IPAddress 192.168.8.1 -InterfaceAlias "Arc-SRV" ` -DefaultGateway 192.168. -AddressFamily IPv4 -PrefixLength 24
Set-DnsClientServerAddress -InterfaceAlias "Arc-SRV" -ServerAddresses 9.9.9.9
#New-NetIPAddress -IPAddress 192.168.8.1 -InterfaceAlias "Arc-SRV" ` #-DefaultGateway 192.168. -AddressFamily IPv4 -PrefixLength 24
#Set-DnsClientServerAddress -InterfaceAlias "Arc-SRV" -ServerAddresses 9.9.9.9
# Create DHCP "security" groups
netsh dhcp add securitygroups
@ -28,9 +46,6 @@ netsh dhcp add securitygroups
# Restart the DHCP server
Restart-Service dhcpserver
# Remove Server Manager message telling that DHCP need to be fixed
Set-ItemProperty Path registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft` \ServerManager\Roles\12 Name ConfigurationState Value 2
###################Template#######################
#Add-DhcpServerv4Scope -name "Corpnet" -StartRange 10.0.0.1 -EndRange 10.0.0.254 -SubnetMask 255.255.255.0 -State Active
#Add-DhcpServerv4ExclusionRange -ScopeID 10.0.0.0 -StartRange 10.0.0.1 -EndRange 10.0.0.15
@ -39,24 +54,19 @@ Set-ItemProperty Path registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft` \Serve
##################################################
# Create DHCP Scopes For Arc-CLI Arc-SRV Bou-Lan
# Change on options after because this sucker seems to dislike if it's done now
Add-DhcpServerv4Scope -name "Arc-SRV" -StartRange 192.168.8.1 -EndRange 192.168.8.254 -SubnetMask 255.255.255.0 -State Active
Add-DhcpServerv4ExclusionRange -ScopeID 192.168.8.0 -StartRange 192.168.8.1 -EndRange 192.168.8.63
Add-DhcpServerv4ExclusionRange -ScopeID 192.168.8.0 -StartRange 192.168.8.240 -EndRange 192.168.8.254
Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -OptionID 3 -Value 192.168.8.254
Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -DnsServer 9.9.9.9
Add-DhcpServerv4Scope -name "Arc-CLI" -StartRange 192.168.12.1 -EndRange 192.168.12.254 -SubnetMask 255.255.255.0 -State Active
Add-DhcpServerv4ExclusionRange -ScopeID 192.168.12.0 -StartRange 192.168.12.1 -EndRange 192.168.12.63
Add-DhcpServerv4ExclusionRange -ScopeID 192.168.12.0 -StartRange 192.168.12.240 -EndRange 192.168.12.254
Set-DhcpServerv4OptionValue -ScopeId 192.168.12.0 -OptionID 3 -Value 192.168.12.254
Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -DnsServer 9.9.9.9
Add-DhcpServerv4Scope -name "Bou-LAN" -StartRange 192.168.128.1 -EndRange 192.168.128.254 -SubnetMask 255.255.255.0 -State Active
Add-DhcpServerv4ExclusionRange -ScopeID 192.168.128.0 -StartRange 192.168.128.1 -EndRange 192.168.128.63
Add-DhcpServerv4ExclusionRange -ScopeID 192.168.128.0 -StartRange 192.168.128.240 -EndRange 192.168.128.254
Set-DhcpServerv4OptionValue -ScopeId 192.168.128.0 -OptionID 3 -Value 192.168.128.254
Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -DnsServer 9.9.9.9
# Change ZoneAlarm rule to accept incoming ICMP ipv4 probes
@ -73,3 +83,14 @@ route add -p 192.168.12.0/24 192.168.8.254
route add -p 192.168.255.0/24 192.168.8.254
route add -p 192.168.128.0/24 192.168.8.254
route add -p 0.0.0.0/0 192.168.8.254
# Change DHCP server options
Set-DhcpServerv4OptionValue -ScopeId 192.168.128.0 -OptionID 3 -Value 192.168.128.254
Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -DnsServer 9.9.9.9
Set-DhcpServerv4OptionValue -ScopeId 192.168.12.0 -OptionID 3 -Value 192.168.12.254
Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -DnsServer 9.9.9.9
Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -OptionID 3 -Value 192.168.8.254
Set-DhcpServerv4OptionValue -ScopeId 192.168.8.0 -DnsServer 9.9.9.9
Read-Host "Finished"

View File

@ -1,19 +1,21 @@
## Tool to automate VM creation
echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman"
# SRV-01
echo "Shamefully made by Alexandre Simao. Such a waste of time.`
Pardon-me dear M. Stallman"
echo "CC BY-NC-SA 4.0"
# TODO: Export Mac/Name to import it on VMS
$VMName = "SRV-01"
cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\$VMName.vhdx
# Region SRV-01
Mount-VHD d:\VHD\$VMName.vhdx
Copy-Item d:\Unattend\$VMName.xml -Destination e:\Windows\Panther\Unattend.xml
Dismount-VHD d:\VHD\$VMName.vhdx
cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\SRV-01.vhdx
Mount-VHD d:\VHD\SRV-01.vhdx
Copy-Item d:\Unattend\SRV-01.xml -Destination e:\Windows\Panther\Unattend.xml
Dismount-VHD d:\VHD\SRV-01.vhdx
$vms = @{
Name = $VMName
Name = "SRV-01"
Generation = '2'
MemoryStartupBytes = 1024Mb
VHDPath = "d:\VHD\$VMName.vhdx"
@ -22,95 +24,81 @@ $vms = @{
}
New-VM @vms
Set-VMMemory $VMName -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
Set-VMMemory SRV-01 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
$vmadapter = Get-VMNetworkAdapter -VMName "SRV-01"
Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[0] -StaticMacAddress 00155D027000
# Endregion SRV-01
# RTR-01
$VMName = "RTR-01"
cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\$VMName.vhdx
cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\RTR-01.vhdx
Mount-VHD d:\VHD\$VMName.vhdx
Copy-Item d:\Unattend\$VMName.xml -Destination e:\Windows\Panther\Unattend.xml
Dismount-VHD d:\VHD\$VMName.vhdx
Mount-VHD d:\VHD\RTR-01.vhdx
Copy-Item d:\Unattend\RTR-01.xml -Destination e:\Windows\Panther\Unattend.xml
Dismount-VHD d:\VHD\RTR-01.vhdx
$vms = @{
Name = $VMName
Name = "RTR-01"
Generation = '2'
MemoryStartupBytes = 1024Mb
VHDPath = "d:\VHD\RTR-01.vhdx"
SwitchName = 'Arc-SRV'
}
New-VM @vms
Set-VMMemory RTR-01 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
$vmadapter = Get-VMNetworkAdapter -VMName "RTR-01"
Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[0] -StaticMacAddress 00155D027001
Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "Arc-CLI" -StaticMacAddress 00155D027002
Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "WAN" -StaticMacAddress 00155D027003
# RTR-02
cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\RTR-02.vhdx
Mount-VHD d:\VHD\RTR-02.vhdx
Copy-Item d:\Unattend\RTR-02.xml -Destination e:\Windows\Panther\Unattend.xml
Dismount-VHD d:\VHD\RTR-02.vhdx
$vms = @{
Name = "RTR-02"
Generation = '2'
MemoryStartupBytes = 1024Mb
VHDPath = "d:\VHD\$VMName.vhdx"
SwitchName = 'Arc-SRV'
}
New-VM @vms
Set-VMMemory $VMName -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
Add-VMNetworkAdapter -VMName $VMName -SwitchName "Arc-CLI"
Add-VMNetworkAdapter -VMName $VMName -SwitchName "WAN"Attends
# RTR-02
$VMName = "RTR-02"
cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\$VMName.vhdx
Mount-VHD d:\VHD\$VMName.vhdx
Copy-Item d:\Unattend\$VMName.xml -Destination e:\Windows\Panther\Unattend.xml
Dismount-VHD d:\VHD\$VMName.vhdx
$vms = @{
Name = $VMName
Generation = '2'
MemoryStartupBytes = 1024Mb
VHDPath = "d:\VHD\$VMName.vhdx"
SwitchName = 'Bou-LAN'
}
New-VM @vms
Set-VMMemory $VMName -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
Set-VMMemory RTR-03 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
#Add-VMSwitch -Name "WAN" -ResourcePoolName "WAN"
Add-VMNetworkAdapter -VMName $VMName -SwitchName "WAN"
Add-VMNetworkAdapter -VMName RTR-02 -SwitchName "WAN" -StaticMacAddress 00155D027004
Add-VMNetworkAdapter -VMName RTR-02 -SwitchName "Bou-LAN" -StaticMacAddress 00155D027005
# RTR-03
$VMName = "RTR-03"
cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\$VMName.vhdx
Mount-VHD d:\VHD\$VMName.vhdx
Copy-Item d:\Unattend\$VMName.xml -Destination e:\Windows\Panther\Unattend.xml
Dismount-VHD d:\VHD\$VMName.vhdx
cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\RTR-03.vhdx
Mount-VHD d:\VHD\RTR-03.vhdx
Copy-Item d:\Unattend\RTR-03.xml -Destination e:\Windows\Panther\Unattend.xml
Dismount-VHD d:\VHD\RTR-03.vhdx
$vms = @{
Name = $VMName
Name = "RTR-03"
Generation = '2'
MemoryStartupBytes = 1024Mb
VHDPath = "d:\VHD\$VMName.vhdx"
SwitchName = 'WAN'
}
New-VM @vms
Set-VMMemory $VMName -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
Add-VMNetworkAdapter -VMName $VMName -SwitchName "Aston"
$VMName = "SRV-01"
$MACSRV01 = (Get-VMNetworkAdapter -VMName SRV-01).MacAddress
echo "$MACSRV01" | Out-file -FilePath D:\scripts\Guests\MACS\MAC$VMName.txt
$VMName = "RTR-01"
$MACRTR01 = (Get-VMNetworkAdapter -VMName RTR-01).MacAddress
echo "$MACRTR01" | Out-file -FilePath D:\scripts\Guests\MACS\MAC$VMName.txt
$VMName = "RTR-02"
$MACRTR02 = (Get-VMNetworkAdapter -VMName RTR-02).MacAddress
echo "$MACRTR02" | Out-file -FilePath D:\scripts\Guests\MACS\MAC$VMName.txt
$VMName = "RTR-03"
$MACRTR03 = (Get-VMNetworkAdapter -VMName RTR-03).MacAddress
echo "$MACRTR03" | Out-file -FilePath D:\scripts\Guests\MACS\MAC$VMName.txt
Set-VMMemory RTR-03 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
Add-VMNetworkAdapter -VMName RTR-03 -SwitchName "Aston" -StaticMacAddress 00155D027006
Add-VMNetworkAdapter -VMName RTR-03 -SwitchName "WAN" -StaticMacAddress 00155D027007
Start-VM -Name RTR*

29
Memo.ps1 Normal file
View File

@ -0,0 +1,29 @@
#$VMNetAdap = Get-VMNetworkAdapter -VMName RTR-01|ft -Property Switchname,Macaddress -HideTableHeaders
Get-VMNetworkAdapter -VMName RTR-01|Format-Table -Property Switchname,Macaddress -HideTableHeaders |Export-Csv D:\scripts\Guests\MACS\test.csv -NoTypeInformation
#echo $VMNETADAP | out-file -FilePath D:\scripts\Guests\MACS\temp.txt
$IP = "10.10.10.10"
$MaskBits = 24 # This means subnet mask = 255.255.255.0
$Gateway = "10.10.10.1"
$Dns = "10.10.10.100"
$IPType = "IPv4"
# Retrieve the network adapter that you want to configure
$adapter = Get-NetAdapter | ? {$_.Status -eq "up"}
# Remove any existing IP, gateway from our ipv4 adapter
If (($adapter | Get-NetIPConfiguration).IPv4Address.IPAddress) {
$adapter | Remove-NetIPAddress -AddressFamily $IPType -Confirm:$false
}
If (($adapter | Get-NetIPConfiguration).Ipv4DefaultGateway) {
$adapter | Remove-NetRoute -AddressFamily $IPType -Confirm:$false
}
# Configure the IP address and default gateway
$adapter | New-NetIPAddress `
-AddressFamily $IPType `
-IPAddress $IP `
-PrefixLength $MaskBits `
-DefaultGateway $Gateway
# Configure the DNS client server IP addresses
$adapter | Set-DnsClientServerAddress -ServerAddresses $DNS

View File

@ -1,3 +0,0 @@
#$VMNetAdap = Get-VMNetworkAdapter -VMName RTR-01|ft -Property Switchname,Macaddress -HideTableHeaders
Get-VMNetworkAdapter -VMName RTR-01|Format-Table -Property Switchname,Macaddress -HideTableHeaders |Export-Csv D:\scripts\Guests\MACS\test.csv -NoTypeInformation
#echo $VMNETADAP | out-file -FilePath D:\scripts\Guests\MACS\temp.txt