You can allow specific Applications access through the Firewall, or you can allow any App access through specific Ports. My preference is to allow Ports, while others prefer to allow Apps.
## fwrules.ps1
(Powershell Script)
This script makes allowances for Ports rather than Apps. The last 3 lines are what set up the (Incoming) Rules for opening ports. The rest of the script are support functions for the last 3 lines.
function getRule {
param(
[string] $name
)
$fw = Get-NetFirewallRule -DisplayName "$name" -ErrorAction:SilentlyContinue
if ($fw) {
return [bool]$true
} else {
return [bool]$false
}
}
function setRule {
param(
[string] $name,
[string] $port,
[string] $protocol,
[string] $profile
)
Set-NetFirewallRule -DisplayName "$name" -Action "Allow" -Direction "Inbound" -Enabled "True" -LocalPort "$port" -Profile "$profile" -Protocol "$protocol" -Verbose
}
function addRule {
param(
[string] $group,
[string] $name,
[string] $port,
[string] $protocol,
[string] $profile
)
$fw = getRule("$name")
if ($fw) {
Write-Host -ForegroundColor:Black -BackgroundColor:Magenta "`r`n*** Rule already exists, Modifying Rule: '$name' ..."
setRule -name:"$name" -port:"$port" -profile:"$profile" -protocol:"$protocol" -Action "Allow" -Direction "Inbound" -Enabled "True"
} else {
Write-Host -ForegroundColor:Black -BackgroundColor:Green "`r`n****** Adding Rule: '$name' ..."
New-NetFirewallRule -Group "$group" -DisplayName "$name" -Action "Allow" -Direction "Inbound" -Enabled "True" -LocalPort "$port" -Profile "$profile" -Protocol "$protocol"
}
}
addRule -profile:"Private" -protocol:"TCP" -port:1433 -group:"Custom Rule - SambaPOS Multi-terminal" -name:"SambaPOS SQL Traffic"
addRule -profile:"Private" -protocol:"UDP" -port:1434 -group:"Custom Rule - SambaPOS Multi-terminal" -name:"SambaPOS SQL Browser Traffic"
addRule -profile:"Private" -protocol:"TCP" -port:9000 -group:"Custom Rule - SambaPOS Multi-terminal" -name:"SambaPOS Messaging Server"
- edit the Powershell script (last 3 lines) to change ports if necessary
- Open a CMD window as Administrator.
- Navigate to the location of the Powershell Script (
fwrules.ps1
). - Execute this line:
powershell -executionpolicy bypass -File fwrules.ps1
This topic has a summary of what needs to be done, as I walked through trouble-shooting connectivity issues: