To allow an app through Windows firewall, open the Windows Security app, go to Firewall & network protection, select Allow an app through firewall, choose Change settings, and tick the app or add it with Allow another app. From an elevated PowerShell window, New-NetFirewallRule with the -Program parameter creates the same exception.
Both methods work on Windows 10 and Windows 11. Allow only programs you recognise. Microsoft's own warning on this topic is blunt: never allow an app that you don't recognize to communicate through the firewall.
Allow an app through Windows firewall in Windows Security
These are the steps Microsoft documents for the Windows Security app:
- Open Windows Security and select Firewall & network protection.
- Select Allow an app through firewall.
- Select Change settings. Windows may ask for an administrator password or a confirmation.
- Tick the check box next to the app you want to allow. If it is not in the list, select Allow another app and enter the path to the program's
.exefile. - Select OK.
To stop allowing an app later, open the same list, clear its check box and select OK. You can also paste windowsdefender://network/ into the Run box (Win+R) to jump to the Firewall & network protection page.
The Windows firewall is called Microsoft Defender Firewall in the app, and Windows Firewall or Windows Defender Firewall in older documentation and in the command-line tools. It is the same feature. If it is switched off, rules you add are not enforced, so see How to Turn On Firewall in Windows 11 and 10 first.
Allow an app through the firewall with PowerShell
The command line gives you control the app does not: the traffic direction, the network profile and the remote addresses. Open PowerShell as administrator and run:
New-NetFirewallRule -DisplayName "Allow MyApp" -Direction Inbound -Program "C:\Apps\MyApp\myapp.exe" -Action Allow
The path above is a placeholder. Replace it with the full path of your own program. What each parameter does, according to Microsoft's reference for the cmdlet:
-DisplayNameis the human-readable name you will use later to find, change or remove the rule.-Directionaccepts Inbound or Outbound, and the default is Inbound.-Programis the executable the rule applies to.-Actionaccepts Allow or Block. Allow is the default.-Profileaccepts Any, Domain, Private, Public or NotApplicable, and the default is Any.
Microsoft's command-line guide says a rule created this way is created on the local device and becomes effective immediately.
Limit the rule to a network profile
Windows applies one of three profiles depending on the type of network you are connected to: Domain, Private or Public. Because the default for -Profile is Any, a rule you create without that parameter applies on all of them, including a café's Wi-Fi. If you only need the app at home, restrict it:
New-NetFirewallRule -DisplayName "Allow MyApp (private only)" -Direction Inbound -Program "C:\Apps\MyApp\myapp.exe" -Profile Private -Action Allow
Limit the rule to your local network
Microsoft's example scopes an inbound program rule to the local subnet by using a keyword instead of an IP address. Anything outside your own network is then not covered by the rule:
New-NetFirewallRule -DisplayName "Allow Inbound MyApp" -Direction Inbound -Program "C:\Apps\MyApp\myapp.exe" -RemoteAddress LocalSubnet -Action Allow
This is a good fit for a game server, a file-sharing tool or a development server that only other machines in your house need to reach.
Allow an app through the firewall with netsh
In an elevated Command Prompt, the equivalent of the subnet-scoped rule above is:
netsh advfirewall firewall add rule name="Allow Inbound MyApp" dir=in program="C:\Apps\MyApp\myapp.exe" remoteip=localsubnet action=allow
This follows the syntax in Microsoft's example, which writes program= followed by the path. Rules made with netsh and with PowerShell land in the same firewall rule set, so you can inspect either kind with either tool.
Check that the rule exists
List the rule by its display name and read its state back:
Get-NetFirewallRule -DisplayName "Allow MyApp" | Select-Object DisplayName, Enabled, Direction, Action
Example output:
DisplayName Enabled Direction Action
----------- ------- --------- ------
Allow MyApp True Inbound Allow
Microsoft's guide notes that Get-NetFirewallRule does not show conditions such as addresses and ports, because those live in separate filter objects. To see which rules point at a particular program, query the application filter, which accepts wildcards:
Get-NetFirewallApplicationFilter -Program "*myapp*" | Get-NetFirewallRule
Allow an app or open a port?
Microsoft describes both options as carrying some risk, but calls opening a port the riskier one. A port stays open until you close it, and an open port can give malware a way into your device. An allowed app, by contrast, opens the ports it needs only when it needs them. So prefer a program rule unless the software cannot work without a fixed port. If you do need a port, New-NetFirewallRule accepts -Protocol TCP -LocalPort 8080, as in Microsoft's Telnet example, which pairs a program with a protocol and a port.
Remove or disable the rule when you are done
Microsoft's advice is to keep exceptions to a minimum and remove the ones you no longer need. For a rule made from the command line you have two options. Disable-NetFirewallRule leaves the rule on the system in a disabled state, and Enable-NetFirewallRule turns it back on. Remove-NetFirewallRule deletes it permanently:
Disable-NetFirewallRule -DisplayName "Allow MyApp"
Remove-NetFirewallRule -DisplayName "Allow MyApp"
With netsh, the delete command is:
netsh advfirewall firewall delete rule name="Allow MyApp"
When you use wildcards in a display name, add -WhatIf first to see which rules would be matched. Microsoft's guide recommends this because a wildcard can match rules you did not intend to remove.
Do not turn the firewall off instead
When a program cannot connect, switching the firewall off looks like a quick test, but Microsoft recommends against disabling Windows Firewall. You lose other protections, including IPsec connection security rules, protection from attacks that use network fingerprinting, and Windows Service Hardening. A narrow rule for one program leaves all of that in place.
If the app still cannot connect
- Wrong executable. Some apps use a launcher plus a separate helper or server process. The rule has to name the program that actually listens or connects, and an updated app can move to a new folder, which leaves the old rule pointing at nothing.
- Wrong profile. A rule limited to Private does nothing while you are on a network Windows classifies as Public. Check the network type in the Windows Security app, or widen the
-Profilevalue. - Wrong direction. The firewall's documented defaults for a computer are to block inbound connections that do not match a rule and to allow outbound ones. An app that only makes outgoing connections rarely needs a rule. An app that accepts connections from other devices needs an inbound rule.
- The firewall is off or managed. If an organization manages the device, its policies can override your change. Ask your administrator.
- Another firewall or a router. Third-party security software may run its own firewall, and a router that does not forward the port blocks traffic from the internet regardless of Windows settings. For background on how filtering works, see What Is a Firewall?.
Frequently asked questions
- Is it safer to allow an app or to open a port?
- Microsoft's guidance is that allowing an app is generally safer than opening a port. An allowed app opens the ports it needs only when needed, while an open port stays open until you close it. In both cases, keep exceptions to a minimum and remove the ones you no longer use.
- Why does my allowed app still not connect?
- The rule may not match the program that actually runs. Check that the rule points at the right executable path, that it applies to the network profile you are connected to, and that the firewall is on. Another firewall product, or a managed policy from your organization, can also override or block your change.
- How do I undo an allowed app?
- In the Windows Security app, open Allow an app through firewall, select Change settings, clear the app's check box and select OK. For a rule created with PowerShell, run Remove-NetFirewallRule with the rule's display name. Use Disable-NetFirewallRule if you only want to switch it off and keep it for later.
- Do I need administrator rights to allow an app through the firewall?
- Yes. The Windows Security app asks for an administrator password or confirmation after you select Change settings, and the PowerShell and netsh commands change system-wide settings, so run them from an elevated window.