Skip to content

Windows Firewall Configuration

This article explains how to configure Windows Defender Firewall (formerly Windows Firewall) on Windows Server. It covers design guidance for Domain/Private/Public profiles, optimization of inbound/outbound policies, log collection and analysis, and practical centralized administration via GPO and scripts.

VariableExampleDescription
<<SERVER_NAME>>SRV-CORE01Target server hostname
<<LOG_PATH>>C:\FirewallLogs\pfirewall.logFirewall log file path
<<OU_NAME>>ServersOU name

Step 1: Understand Profiles and Plan Application

Section titled “Step 1: Understand Profiles and Plan Application”

Windows Defender Firewall provides three profiles:

ProfilePurposeTypical Environment
DomainAD-joined networksCorporate LAN, VPN
PrivateTrusted standalone networkTest environments, isolated networks
PublicUntrusted networkPublic Wi-Fi, lab/VM

Each profile is independently configurable and switches automatically based on network identification.

Verification command:

Terminal window
# Check each profile's state and default policies
Get-NetFirewallProfile | Select-Object Name, Enabled, DefaultInboundAction, DefaultOutboundAction

Step 2: Set Baseline Policies (Default Behavior)

Section titled “Step 2: Set Baseline Policies (Default Behavior)”

By default, Windows Defender Firewall blocks inbound and allows outbound traffic.
Keep this behavior, or introduce explicit outbound control when needed.

Terminal window
# Explicitly set default policies
Set-NetFirewallProfile -Profile Domain,Private,Public `
-DefaultInboundAction Block `
-DefaultOutboundAction Allow `
-NotifyOnListen True

Note: In high-security environments, use -DefaultOutboundAction Block and then allow only necessary outbound traffic (e.g., DNS, NTP, WSUS): a whitelist approach.


Terminal window
# All rules
Get-NetFirewallRule
# Rules containing "RDP" in the display name
Get-NetFirewallRule | Where-Object DisplayName -Like "*RDP*"
# Only enabled rules
Get-NetFirewallRule | Where-Object Enabled -eq "True"
Terminal window
# Allow inbound RDP (TCP/3389) on Domain profile
New-NetFirewallRule -DisplayName "Allow RDP (Domain)" `
-Direction Inbound -Protocol TCP -LocalPort 3389 `
-Action Allow -Profile Domain
# Allow outbound NTP (UDP/123)
New-NetFirewallRule -DisplayName "Allow NTP Outbound" `
-Direction Outbound -Protocol UDP -LocalPort 123 `
-Action Allow -Profile Domain,Private,Public
ItemParameterExampleAccepted Values/Format
Direction-DirectionInbound / OutboundInbound, Outbound
Action-ActionAllow / BlockAllow, Block
Protocol-ProtocolTCP / UDP / ICMPv4 / ICMPv6 / AnyAs listed; ICMP can be refined via -IcmpType
Local port-LocalPort80 / 1024-2048 / 80,443,8080Single, range, CSV list
Remote port-RemotePort53 / 1000-2000 / 53,67,68Single, range, CSV list
Remote address-RemoteAddress192.168.1.1 / 192.168.0.0/24 / AnySingle IP, CIDR, range, CSV list, Any
Local address-LocalAddress10.0.0.1 / 10.0.0.0/16 / AnySingle IP, CIDR, range, CSV list, keywords, Any
Program-ProgramC:\Program Files\App\App.exeFull path to executable
Service-ServiceW32TimeWindows service name
Profile-ProfileDomain,PrivateCombination of Domain, Private, Public
Interface type-InterfaceTypeEthernet / Wireless / RemoteAccessSupported interface types

Example: Allow HTTP Only from a Trusted IP

Section titled “Example: Allow HTTP Only from a Trusted IP”
Terminal window
New-NetFirewallRule -DisplayName "Allow HTTP from Trusted IP" `
-Direction Inbound -Protocol TCP -LocalPort 80 `
-RemoteAddress 192.168.1.100 `
-Action Allow -Profile Domain,Private
Terminal window
New-NetFirewallRule -DisplayName "Allow Outbound for App.exe" `
-Direction Outbound -Program "C:\Program Files\App\App.exe" `
-Action Allow -Profile Domain,Private,Public
Terminal window
New-NetFirewallRule -DisplayName "Allow Service XYZ Inbound" `
-Direction Inbound -Service "W32Time" `
-Action Allow -Profile Domain,Private

Example: Block Outbound on Wi-Fi Interface

Section titled “Example: Block Outbound on Wi-Fi Interface”
Terminal window
New-NetFirewallRule -DisplayName "Block Outbound on Wireless" `
-Direction Outbound -InterfaceType Wireless `
-Action Block -Profile Public
Terminal window
# Disable rule
Disable-NetFirewallRule -DisplayName "Allow RDP (Domain)"
# Enable rule
Enable-NetFirewallRule -DisplayName "Allow RDP (Domain)"
# Change scope (e.g., restrict to Domain and Private)
Set-NetFirewallRule -DisplayName "Allow RDP (Domain)" -Profile Domain,Private
# Remove rule
Remove-NetFirewallRule -DisplayName "Allow RDP (Domain)"
Terminal window
# Export firewall policy
netsh advfirewall export "C:\Backup\FirewallPolicy.wfw"
# Import firewall policy
netsh advfirewall import "C:\Backup\FirewallPolicy.wfw"

Record allowed/blocked events and watch for anomalies.

Terminal window
# Enable both allowed and blocked logging; max size 32 MB
Set-NetFirewallProfile -Profile Domain,Private,Public `
-LogAllowed True -LogBlocked True `
-LogFileName "<<LOG_PATH>>" -LogMaxSizeKilobytes 32767

Tail logs:

Terminal window
Get-Content "<<LOG_PATH>>" -Tail 20 -Wait

Caution: Enabling LogAllowed=True increases log volume. In production, consider enabling allowed-traffic logging only for critical profiles (e.g., Public) and implement rotation/archiving.
The -LogMaxSizeKilobytes limit is 32767 KB; higher values cause an error.


Firewall settings can be edited and automated through GPO using the GroupPolicy module.
Key cmdlets: Set-GPRegistryValue, Get-GPO, New-GPO, New-GPLink, Set-GPInheritance.

Create a GPO and Apply Domain Profile Logging

Section titled “Create a GPO and Apply Domain Profile Logging”
  1. Create or retrieve GPO

    Terminal window
    $gpo = New-GPO -Name "Firewall-Policy-Domain"

    To edit an existing GPO: Get-GPO -Name "<GPO_NAME>".

  2. Apply values via GPO Registry keys

    Terminal window
    # Enable logging for Domain profile
    Set-GPRegistryValue -Name $gpo.DisplayName `
    -Key "HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile" `
    -ValueName "EnableLogging" -Type DWord -Value 1
    # Log path and size
    Set-GPRegistryValue -Name $gpo.DisplayName `
    -Key "HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile\Logging" `
    -ValueName "LogFilePath" -Type String -Value "%systemroot%\system32\logfiles\firewall\pfirewall.log"
    Set-GPRegistryValue -Name $gpo.DisplayName `
    -Key "HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile\Logging" `
    -ValueName "LogFileSize" -Type DWord -Value 32767

These settings take effect when the GPO is linked to an OU via New-GPLink.

Pass the DN of the OU (or the domain DN) to -Target.

Terminal window
Import-Module ActiveDirectory
$gpo = Get-GPO -Name "Firewall-Policy-Domain"
# Find OU by name and get its DN
$ou = Get-ADOrganizationalUnit -LDAPFilter '(name=<<OU_NAME>>)' `
-SearchBase (Get-ADDomain).DistinguishedName -SearchScope Subtree |
Select-Object -First 1
$ouDn = $ou.DistinguishedName
# Link GPO to the OU (enabled; Enforced optional)
New-GPLink -Name $gpo.DisplayName -Target $ouDn -LinkEnabled Yes -Enforced No

Prerequisites: ActiveDirectory and GroupPolicy (RSAT) modules installed on the admin workstation.


Step 6: Periodic Validation and Troubleshooting

Section titled “Step 6: Periodic Validation and Troubleshooting”
Terminal window
# Currently active rules
Get-NetFirewallRule | Where-Object {$_.Enabled -eq "True"} |
Select-Object DisplayName, Direction, Action, Profile
# Port reachability test
Test-NetConnection -ComputerName <<SERVER_NAME>> -Port 3389

Windows Defender Firewall provides robust, built-in network protection on Windows Server. By combining explicit inbound/outbound control, log analysis, and centralized/automated management via GPO and PowerShell, you achieve strong visibility and security aligned with modern hardening and zero-trust practices.