Configure Windows Firewall logging

To configure Windows Firewall to log dropped packets or successful connections, you can use:

  • Configuration Service Provider (CSP), using an MDM solution like Microsoft Intune
  • Group policy (GPO)

The following instructions provide details about how to configure your devices. Select the option that best suits your needs.

  1. Sign into the Microsoft Intune admin center
  2. Go to Endpoint security > Firewall > Create policy > Windows 10, Windows 11, and Windows Server > Windows Firewall > Create
  3. Enter a name and, optionally, a description > Next
  4. Under Configuration settings, for each network location type (Domain, Private, Public), configure:
    • Log file path
    • Enable log dropped packets
    • Enable log success connections
    • Log max file size
  5. Select Next > Next
  6. Assign the policy to a group that contains as members the devices or users that you want to configure > Next > Create

Tip

If you prefer you can also use a Settings catalog policy to configure Windows Firewall logging.

Alternatively, you can configure devices using a custom policy with the Firewall CSP.

Network profile Setting
Domain Setting name: EnableLogDroppedPackets
OMA-URI: ./Vendor/MSFT/Firewall/MdmStore/DomainProfile/EnableLogDroppedPackets
Domain Setting name: LogFilePath
OMA-URI: ./Vendor/MSFT/Firewall/MdmStore/DomainProfile/LogFilePath
Domain Setting name: EnableLogSuccessConnections
OMA-URI: ./Vendor/MSFT/Firewall/MdmStore/DomainProfile/EnableLogSuccessConnections
Domain Setting name: LogMaxFileSize
OMA-URI: ./Vendor/MSFT/Firewall/MdmStore/DomainProfile/LogMaxFileSize
Private Setting name: EnableLogDroppedPackets
OMA-URI: ./Vendor/MSFT/Firewall/MdmStore/PrivateProfile/EnableLogDroppedPackets
Private Setting name: LogFilePath
OMA-URI: ./Vendor/MSFT/Firewall/MdmStore/PrivateProfile/LogFilePath
Private Setting name: EnableLogSuccessConnections
OMA-URI: ./Vendor/MSFT/Firewall/MdmStore/PrivateProfile/EnableLogSuccessConnections
Private Setting name: LogMaxFileSize
OMA-URI: ./Vendor/MSFT/Firewall/MdmStore/PrivateProfile/LogMaxFileSize
Public Setting name: EnableLogDroppedPackets
OMA-URI: ./Vendor/MSFT/Firewall/MdmStore/PublicProfile/EnableLogDroppedPackets
Public Setting name: LogFilePath
OMA-URI: ./Vendor/MSFT/Firewall/MdmStore/PublicProfile/LogFilePath
Public Setting name: EnableLogSuccessConnections
OMA-URI: ./Vendor/MSFT/Firewall/MdmStore/PublicProfile/EnableLogSuccessConnections
Public Setting name: LogMaxFileSize
OMA-URI: ./Vendor/MSFT/Firewall/MdmStore/PublicProfile/LogMaxFileSize

Important

The location you specify must have permissions assigned that permit the Windows Firewall service to write to the log file.

Recommendations

Here are some recommendations for configuring Windows Firewall logging:

  • Change the logging size to at least 20,480 KB (20 MB) to ensure that the log file doesn't fill up too quickly. The maximum log size is 32,767 KB (32 MB)
  • For each profile (Domain, Private, and Public) change the default log file name from %windir%\system32\logfiles\firewall\pfirewall.log to:
    • %windir%\system32\logfiles\firewall\pfirewall_Domain.log
    • %windir%\system32\logfiles\firewall\pfirewall_Private.log
    • %windir%\system32\logfiles\firewall\pfirewall_Public.log
  • Log dropped packets to Yes
  • Log successful connections to Yes

On a single system, you can use the following commands to configure logging:

netsh advfirewall>set allprofiles logging allowedconnections enable
netsh advfirewall>set allprofiles logging droppedconnections enable

Parsing methods

There are several methods to parse the Windows Firewall log files. For example:

Tip

If logs are slow to appear in your SIEM solution, you can decrease the log file size. Just beware that the downsizing results in more resource usage due to the increased log rotation.

Troubleshoot if the log file is not created or modified

Sometimes the Windows Firewall log files aren't created, or the events aren't written to the log files. Some examples when this condition might occur include:

  • Missing permissions for the Windows Defender Firewall Service (mpssvc) on the folder or on the log files
  • You want to store the log files in a different folder and the permissions are missing, or aren't set automatically
  • if firewall logging is configured via policy settings, it can happen that
    • the log folder in the default location %windir%\System32\LogFiles\firewall doesn't exist
    • the log folder in a custom path doesn't exist

In both cases, you must create the folder manually or via script, and add the permissions for mpssvc.

New-Item -ItemType Directory -Path $env:windir\System32\LogFiles\Firewall

Verify if mpssvc has FullControl on the folder and the files. From an elevated PowerShell session, use the following commands, ensuring to use the correct path:

$LogPath = Join-Path -path $env:windir -ChildPath "System32\LogFiles\Firewall"
(Get-ACL -Path $LogPath).Access | Format-Table IdentityReference,FileSystemRights,AccessControlType,IsInherited,InheritanceFlags -AutoSize

The output should show NT SERVICE\mpssvc having FullControl:

IdentityReference      FileSystemRights AccessControlType IsInherited InheritanceFlags
-----------------      ---------------- ----------------- ----------- ----------------
NT AUTHORITY\SYSTEM         FullControl             Allow       False    ObjectInherit
BUILTIN\Administrators      FullControl             Allow       False    ObjectInherit
NT SERVICE\mpssvc           FullControl             Allow       False    ObjectInherit

If not, add FullControl permissions for mpssvc to the folder, subfolders and files. Make sure to use the correct path.

$LogPath = Join-Path -path $env:windir -ChildPath "System32\LogFiles\Firewall"
$NewAcl = Get-Acl -Path $LogPath

$identity = "NT SERVICE\mpssvc"
$fileSystemRights = "FullControl"
$inheritanceFlags = "ContainerInherit,ObjectInherit"
$propagationFlags = "None"
$type = "Allow"

$fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $inheritanceFlags, $propagationFlags, $type
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList

$NewAcl.SetAccessRule($fileSystemAccessRule)
Set-Acl -Path $LogPath -AclObject $NewAcl

Restart the device to restart the Windows Defender Firewall service.