Skip to content

Commit

Permalink
[Windows] Set the dynamic port range to start at port 49152 and to en…
Browse files Browse the repository at this point in the history
…d at the 65536 (16384 ports) (actions#1442)

* set the dynamic port range

* update pester test

* update context about VS installer

* update dynamicports pester test
  • Loading branch information
al-cheb authored Aug 24, 2020
1 parent ad2409d commit ba17c75
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
3 changes: 2 additions & 1 deletion images/win/Windows2016-Azure.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1"
"{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1",
"{{ template_dir }}/scripts/Installers/Configure-DynamicPort.ps1"
],
"elevated_user": "{{user `install_user`}}",
"elevated_password": "{{user `install_password`}}"
Expand Down
3 changes: 2 additions & 1 deletion images/win/Windows2019-Azure.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1"
"{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1",
"{{ template_dir }}/scripts/Installers/Configure-DynamicPort.ps1"
],
"elevated_user": "{{user `install_user`}}",
"elevated_password": "{{user `install_password`}}"
Expand Down
14 changes: 14 additions & 0 deletions images/win/scripts/Installers/Configure-DynamicPort.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# https://support.microsoft.com/en-us/help/929851/the-default-dynamic-port-range-for-tcp-ip-has-changed-in-windows-vista
# The new default start port is 49152, and the new default end port is 65535.
# Default port configuration was changed during image generation by Visual Studio Enterprise Installer to:
# Protocol tcp Dynamic Port Range
# ---------------------------------
# Start Port : 1024
# Number of Ports : 64511
Write-Host "Set the dynamic port range to start at port 49152 and to end at the 65536 (16384 ports)"
$null = netsh int ipv4 set dynamicport tcp start=49152 num=16384
$null = netsh int ipv4 set dynamicport udp start=49152 num=16384
$null = netsh int ipv6 set dynamicport tcp start=49152 num=16384
$null = netsh int ipv6 set dynamicport udp start=49152 num=16384

Invoke-PesterTests -TestFile "WindowsFeatures" -TestName "DynamicPorts"
20 changes: 19 additions & 1 deletion images/win/scripts/Tests/WindowsFeatures.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,28 @@ Describe "ContainersFeature" {
}

Describe "DiskSpace" {
it "The image has enough disk space"{
It "The image has enough disk space"{
$availableSpaceMB = [math]::Round((Get-PSDrive -Name C).Free / 1MB)
$minimumFreeSpaceMB = 18 * 1024

$availableSpaceMB | Should -BeGreaterThan $minimumFreeSpaceMB
}
}

Describe "DynamicPorts" {
It "Test TCP dynamicport start=49152 num=16384" {
$tcpPorts = Get-NetTCPSetting | Where-Object {$_.SettingName -ne "Automatic"} | Where-Object {
$_.DynamicPortRangeStartPort -ne 49152 -or $_.DynamicPortRangeNumberOfPorts -ne 16384
}

$tcpPorts | Should -BeNullOrEmpty
}

It "Test UDP dynamicport start=49152 num=16384" {
$udpPorts = Get-NetUDPSetting | Where-Object {
$_.DynamicPortRangeStartPort -ne 49152 -or $_.DynamicPortRangeNumberOfPorts -ne 16384
}

$udpPorts | Should -BeNullOrEmpty
}
}

0 comments on commit ba17c75

Please sign in to comment.