Why is Windows Firewall blocking my app?

App can't connect? Windows Firewall might be blocking it. Learn how to diagnose and fix it with netsh and PowerShell.

WindowsbackupnetworkportssecuritypowershellfirewallMedium risk
First, check whether the firewall is on and whether a blocking rule exists for your app.

What this covers

When an app can't reach the network but other things work fine, Windows Firewall is a likely suspect. This guide walks you through checking the firewall state, creating an allow rule for your app's port, and verifying the rule is in place — all from the command line.

Symptom

?A specific app fails to connect to the internet or receive inbound connections. Other apps (like browsers) work normally.

Check if the firewall is on and what rules exist

First, confirm the firewall is actually the culprit. Query the firewall state for all profiles (Domain, Private, Public) and list existing rules. If the firewall is off, the block is coming from elsewhere. If it's on, look for any rule that might be blocking your app. This step tells you whether to proceed with a fix.

Query whether Defender Firewall is enabled per profile (Domain/Private/Public) and list the rules already in place — without touching the GUI.

Command
$ netsh advfirewall show allprofiles state

Create an inbound allow rule for the app's port

If the firewall is on and no allow rule exists, create one for the port your app uses. This opens the port for inbound traffic. Make sure you specify the correct protocol (TCP/UDP) and port number. After the rule is created, the app should be able to receive connections.

Create an inbound allow rule for a TCP/UDP port with one PowerShell cmdlet, and delete it cleanly afterwards.

Command
$ New-NetFirewallRule -DisplayName "Allow HTTP 8080" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow
▾ Undo
Undo
$ Remove-NetFirewallRule -DisplayName "Allow HTTP 8080"

Verify the new rule is saved and back up your firewall policy

Export the current firewall policy to a file. This serves two purposes: it confirms your new rule is included in the active configuration, and it gives you a backup you can restore if something goes wrong. Open the exported file and search for your rule's name to be sure it's there. If it's missing, the rule wasn't applied correctly.

Snapshot every firewall rule, profile and setting into a single .wfw file with netsh advfirewall export, and put it all back with import.

Command
$ netsh advfirewall export "C:\backup\firewall-policy.wfw"
▾ Undo
Undo
$ netsh advfirewall import "C:\backup\firewall-policy.wfw"
!Changing firewall rules can affect system security. Export your current policy before making changes. Resetting the firewall will remove all custom rules.

How to confirm it worked

The app can connect again, or the exported firewall policy file contains the new allow rule you created.

Undo everything

Every command above can be reverted. Run these in order to undo all of it.

Undo everything
$ netsh advfirewall import "C:\backup\firewall-policy.wfw"
Remove-NetFirewallRule -DisplayName "Allow HTTP 8080"

Review before running — some steps may not be independent.

Sources

  • Netsh - Windows CMD
    SS64 · technical · 2026-09-17
    Evidence: SS64 documents the netsh advfirewall contexts: show allprofiles state and firewall show rule name=all for inspecting rules and profile states.
  • New-NetFirewallRule | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    Evidence: Microsoft documents New-NetFirewallRule with parameters -Direction, -Protocol, -LocalPort and -Action to create an inbound allow rule.

Last verified: 2026-09-22

Related guides