Skip to main content

Windows Firewall Best Practices

Windows Firewall Best Practices

Windows Defender Firewall (formerly Windows Firewall with Advanced Security) is a host-based stateful firewall built into all modern Windows operating systems. When properly configured, it provides a critical layer of defense-in-depth for both workstations and servers. This page covers best practices for enterprise environments.

⛔ CRITICAL: Never Disable the Windows Firewall Service

Microsoft explicitly states that the Windows Defender Firewall service (mpssvc) must never be disabled. Stopping or disabling the service — rather than managing firewall profiles — breaks IPsec/connection security rules, disrupts dependent services, and leaves the host completely unprotected at the kernel level, even if a third-party firewall is present.

If you need to allow traffic that is being blocked: create a specific firewall rule to permit it. If troubleshooting, disable the relevant profile temporarily via GPO or Set-NetFirewallProfile -Enabled False — never stop the service itself.


Core Principles

  • Default Deny – All inbound traffic should be blocked by default. Only explicitly required ports and protocols should be permitted.
  • Least Privilege – Rules should be as specific as possible: limit by port, protocol, source IP, and application path where feasible.
  • Profile Awareness – Windows Firewall uses three profiles (Domain, Private, Public). Ensure all three are configured — never assume Domain profile is the only one that matters.
  • Logging – Enable logging on all profiles. Silent failures and misconfigured rules are only discoverable through logs.

Profile Configuration

Profile Use Case Recommended Inbound Policy
Domain Domain-joined machines on corp network Block (with GPO-defined exceptions)
Private Trusted home/lab networks Block
Public Untrusted networks (hotels, coffee shops) Block (most restrictive)

All three profiles should have inbound set to Block and outbound set to Allow (with optional outbound restrictions for high-security systems).


Group Policy Management

Manage Windows Firewall centrally via GPO for consistency and auditability.

Computer Configuration > Windows Settings > Security Settings > Windows Defender Firewall with Advanced Security

Key GPO Settings

  • Firewall state: On (all profiles)
  • Inbound connections: Block (all profiles)
  • Outbound connections: Allow (default), restrict as needed
  • Display a notification: No (prevents end-user confusion/bypasses)
  • Allow local firewall rule merging: Disabled (prevents local overrides on managed systems)
  • Apply local connection security rule merging: Disabled

Important: Setting "Apply local firewall rules" to No in GPO means only GPO-defined rules apply. This is recommended for servers. For workstations, evaluate based on whether local admins need the ability to add exceptions.


All Systems (Baseline)

Rule Port/Protocol Direction Action
Block all inbound (default) Any Inbound Block
Allow ICMP Echo (monitoring) ICMPv4/ICMPv6 Inbound Allow (from monitoring subnet only)
Allow established/related Stateful Inbound Allow

Domain Controllers

Rule Port/Protocol
KerberosTCP/UDP 88
LDAPTCP/UDP 389
LDAPSTCP 636
Global CatalogTCP 3268, 3269
DNSTCP/UDP 53
RPC Endpoint MapperTCP 135
RPC Dynamic PortsTCP 49152–65535 (restrict to DC/management IPs)
SMBTCP 445 (restrict to domain members only)
NetLogonTCP/UDP 464

Member Servers (General)

Rule Port/Protocol Notes
RDPTCP 3389Restrict to jump host / management VLAN only
WinRM (HTTP)TCP 5985Restrict to Ansible/management IPs
WinRM (HTTPS)TCP 5986Preferred over HTTP
SMBTCP 445Restrict to authorized file server clients

Workstations

  • Block SMB (TCP 445) inbound — lateral movement vector
  • Block RDP (TCP 3389) inbound — use jump hosts instead
  • Allow WinRM only from management systems if using remote management
  • Allow monitoring agent traffic from LogicMonitor collectors

PowerShell Management

View all active inbound rules

Get-NetFirewallRule -Direction Inbound -Enabled True | 
  Select-Object DisplayName, Profile, Action, Direction |
  Sort-Object DisplayName

Create a targeted allow rule

New-NetFirewallRule `
  -DisplayName "Allow WinRM HTTPS from Management" `
  -Direction Inbound `
  -Protocol TCP `
  -LocalPort 5986 `
  -RemoteAddress 10.10.0.0/24 `
  -Action Allow `
  -Profile Domain `
  -Enabled True

Block a specific port across all profiles

New-NetFirewallRule `
  -DisplayName "Block SMB Inbound" `
  -Direction Inbound `
  -Protocol TCP `
  -LocalPort 445 `
  -Action Block `
  -Profile Any `
  -Enabled True

Export current rules for auditing

Get-NetFirewallRule | Export-Csv -Path "C:\Audit\FirewallRules_$(Get-Date -Format yyyyMMdd).csv" -NoTypeInformation

Enable firewall logging via PowerShell

Set-NetFirewallProfile -Profile Domain,Private,Public `
  -LogBlocked True `
  -LogAllowed True `
  -LogMaxSizeKilobytes 32767 `
  -LogFileName "%systemroot%\system32\LogFiles\Firewall\pfirewall.log"

Logging & Monitoring

Enable Logging

Enable logging on all profiles via GPO:

Windows Defender Firewall Properties > [Profile Tab] > Logging
  - Log dropped packets: Yes
  - Log successful connections: Yes
  - Size limit: 32,767 KB (max)
  - Log file path: %systemroot%\system32\LogFiles\Firewall\pfirewall.log

Windows Event Log Integration

Key Event IDs to monitor in Security and Microsoft-Windows-Windows Firewall With Advanced Security/Firewall logs:

Event ID Description
2004Firewall rule added
2005Firewall rule modified
2006Firewall rule deleted
2033Firewall rule list cleared
5025Firewall service stopped
5157Connection blocked
5156Connection allowed

Forward these events to your SIEM or LogicMonitor for centralized alerting.


Common Hardening Mistakes to Avoid

Mistake Risk Remediation
Disabling Windows Firewall entirelyNo host-level protectionRe-enable, configure via GPO
Allowing "Any" as source IPExposes services to all hostsRestrict by IP/subnet
Allowing RDP from AnyLateral movement / brute forceRestrict to jump host IPs only
Leaving SMB 445 open on workstationsWannaCry/ransomware propagationBlock inbound 445 on all workstations
Not logging dropped packetsNo visibility into blocked attemptsEnable logging on all profiles
Allowing local rule merging on serversUsers/apps create unauthorized exceptionsDisable local rule merging via GPO

Auditing & Compliance

Verify firewall is enabled on all profiles

Get-NetFirewallProfile | Select-Object Name, Enabled, DefaultInboundAction, DefaultOutboundAction

Expected output for a hardened system:

Name     Enabled  DefaultInboundAction  DefaultOutboundAction
----     -------  --------------------  ---------------------
Domain   True     Block                 Allow
Private  True     Block                 Allow
Public   True     Block                 Allow

List rules allowing inbound Any source (risk review)

Get-NetFirewallRule -Direction Inbound -Action Allow -Enabled True |
  Get-NetFirewallAddressFilter |
  Where-Object { $_.RemoteAddress -eq "Any" }

Review the output and determine if each rule has a legitimate business justification.


  • Windows Defender Firewall with Advanced Security (WFAS) Overview
  • GPO Baseline Templates
  • WinRM & Remote Management Configuration
  • Network Segmentation and VLAN Strategy

Last reviewed: April 2026 | Applies to: Windows Server 2019, 2022, 2025 / Windows 10, 11