CoCoineticBack to coinetic.io

Blocked by Windows Firewall? See what is blocked and allow it

A program can't connect, a port seems closed, a colleague can't reach your share. Before you open anything, find out what is blocked and which rule did it. Then allow exactly that, and nothing more.

In short
  • See what is blocked: switch on Log dropped packets and read %systemroot%\system32\LogFiles\Firewall\pfirewall.log, or audit Security events 5152 / 5157.
  • Allow a program: Allow an app through firewall, or an inbound rule for the program in wf.msc.
  • Open a port: an inbound rule for TCP or UDP and the port number, ideally limited to the addresses that need it.
  • Block a program: an outbound block rule. By default Windows lets every program connect out.

1. Is it really the Windows Firewall?

"Blocked by firewall" can also mean the router, another security program, or a firewall at the other end. Two quick checks:

2. See what Windows Firewall is blocking

The firewall log (pfirewall.log)

Windows can write every dropped packet to a text file. It is off by default. To switch it on: wf.msc › Windows Defender Firewall Properties › the tab of your profile (Domain, Private, Public) › Logging › Customize › Log dropped packets: Yes. Or, as administrator:

netsh advfirewall set allprofiles logging droppedconnections enable

On Windows 8 / Server 2012 and later also:

Set-NetFirewallProfile -Profile Domain,Private,Public -LogBlocked True

The file is %systemroot%\system32\LogFiles\Firewall\pfirewall.log. Each line has the date, time, action (DROP), protocol, source and destination address and port. Its default size limit is 4 MB, so it rolls over quickly on a busy Server; you can raise the limit on the same Logging page.

What the log does not tell you: which rule dropped the packet, and which program it was meant for.

Security events 5152 and 5157

The Windows Filtering Platform, which the firewall is built on, can write blocked connections to the Security log. Enable the failure auditing as administrator. The GUIDs work in every Windows language; the subcategory names are translated:

auditpol /set /subcategory:{0CCE9226-69AE-11D9-BED3-505054503030} /failure:enable
auditpol /set /subcategory:{0CCE9225-69AE-11D9-BED3-505054503030} /failure:enable

The first is Filtering Platform Connection (event 5157, "The Windows Filtering Platform has blocked a connection"), the second Filtering Platform Packet Drop (event 5152, "The Windows Filtering Platform has blocked a packet"). Event 5157 also names the application. Then look in Event Viewer › Windows Logs › Security:

Get-WinEvent -FilterHashtable @{LogName='Security'; Id=5157} -MaxEvents 20 | Format-List TimeCreated, Message

The event contains a Filter Run-Time ID, not the rule name. Matching it to a rule means exporting all filters with netsh wfp show filters (a large XML file in the current folder) and searching it for that ID. It works, but it is slow detective work. Leave success auditing off unless you need it: it logs every allowed connection and fills the log fast.

3. Allow an app through Windows Firewall

From the command line (as administrator):

netsh advfirewall firewall add rule name="My app" dir=in action=allow program="C:\Program Files\MyApp\myapp.exe" enable=yes

New-NetFirewallRule -DisplayName "My app" -Direction Inbound -Program "C:\Program Files\MyApp\myapp.exe" -Action Allow -Profile Domain,Private

4. Open a port in Windows Firewall

wf.msc › Inbound Rules › New Rule… › Port › TCP or UDP › the port number › Allow the connection. Or:

netsh advfirewall firewall add rule name="Open TCP 8080" dir=in action=allow protocol=TCP localport=8080

New-NetFirewallRule -DisplayName "Open TCP 8080 (LAN)" -Direction Inbound -Protocol TCP -LocalPort 8080 -RemoteAddress 192.168.1.0/24 -Action Allow

Keep it tight: a port opened to any address on a computer that is reachable from the internet is open to the whole internet. -RemoteAddress (or Scope in wf.msc) limits who may connect, and -Profile limits on which networks. If the port is meant to be reached from the internet, the router must forward it too.

5. Block a program in Windows Firewall

Windows allows outbound connections by default, so blocking a program needs an outbound block rule:

netsh advfirewall firewall add rule name="Block myapp out" dir=out action=block program="C:\Program Files\MyApp\myapp.exe" enable=yes

New-NetFirewallRule -DisplayName "Block myapp out" -Direction Outbound -Program "C:\Program Files\MyApp\myapp.exe" -Action Block

A block rule wins over an allow rule for the same traffic. Two limits to know: a rule matches one exact path, so a program that updates itself into a new folder escapes it; and the opposite approach, blocking all outbound traffic and allowing programs one by one, is possible (Outbound connections: Block in the profile properties) but breaks things quickly if you have to find every program by hand.

6. Find the rule that blocks it

To list the block rules that are switched on:

Get-NetFirewallRule -Enabled True -Action Block | Format-Table DisplayName, Direction, Profile

Rules can also come from a Group Policy; those are shown in wf.msc but can only be changed in the policy. And if no rule matches at all, the profile's default decides: inbound is blocked unless a rule allows it.

7. Doing this by hand means…

8. With Coinetic: installed in minutes, then it runs by itself

Coinetic works through the Windows Firewall that is already there and shows you what it does.

Protect this Server or PC in 5 minutes

Download Coinetic, install, done - it starts protecting at once. 30 days free with all features, no payment details. From $20 per computer per year.

Start the free 30-day trial →

More guides: all Coinetic guides.

Frequently asked

Where is the Windows Firewall log?

%systemroot%\system32\LogFiles\Firewall\pfirewall.log, usually C:\Windows\System32\LogFiles\Firewall\pfirewall.log. It stays empty until you switch on Log dropped packets (or Log successful connections) for the profile.

Why does my rule not work?

The usual reasons: the rule is for the wrong profile (Private, but the network is Public), the wrong program path, a block rule for the same traffic, or a Group Policy that ignores local rules. Also check that the program is actually listening.

Is it safe to turn off Windows Firewall to test?

Only for a minute, and not on a computer that is reachable from the internet. Better: leave it on and read the log or event 5157, which tell you what was blocked.

How do I see which program was blocked?

pfirewall.log has only addresses and ports. Security event 5157 names the application; Coinetic's live log shows the program, the address and the rule on one line.