CoCoineticBack to coinetic.io

How to manage Windows Firewall: rules, backup, reset and audit

Every Windows Server and PC has a capable firewall built in. Managing it well means knowing where its settings live, keeping an overview of hundreds of rules, having a backup before you change anything, and checking now and then that nothing is open that should not be.

In short
  • Where: Windows Defender Firewall with Advanced Security (Start, type "firewall") for full control, PowerShell (Get-NetFirewallRule, Set-NetFirewallProfile) for scripts, Group Policy or Intune for many computers.
  • Overview: Get-NetFirewallRule lists the rules; ports, programs and addresses sit in separate filters.
  • Backup: netsh advfirewall export "C:\backup\firewall.wfw" before every bigger change; import restores it.
  • Reset: netsh advfirewall reset or Restore firewalls to default in Windows Security.
  • Audit: profiles on, inbound blocked by default, no admin ports open to any address, no rules for programs that are gone.
  • Free scripts for all of this: windows-firewall-manager on GitHub.

Allowing an app, opening a port or blocking a program is covered in Blocked by Windows Firewall? See what is blocked and allow it. This guide is about keeping the whole firewall in order.

1. Where to manage the Windows Firewall

2. See all rules in one place

A fresh Windows already has several hundred rules, and every installer adds more. To list the rules that are switched on:

Get-NetFirewallRule -Enabled True | Sort-Object Direction, DisplayName |
  Format-Table DisplayName, Direction, Action, Profile -AutoSize

Ports, programs and addresses are not properties of the rule itself but of its filters. For one rule:

Get-NetFirewallRule -DisplayName "Remote Desktop*" | Get-NetFirewallPortFilter
Get-NetFirewallRule -DisplayName "Remote Desktop*" | Get-NetFirewallAddressFilter

For all rules at once, asking each rule for its filters is slow. It is much faster to read every filter once with Get-NetFirewallPortFilter -All (and -ApplicationFilter, -AddressFilter) and match them to the rules by InstanceID. The free Get-FirewallRuleReport.ps1 does exactly that and writes one row per rule, on screen, as CSV or as an HTML page.

Rule display names and groups are translated into the Windows language. In scripts that must run on any language, use the language-neutral group IDs, for example -Group "@FirewallAPI.dll,-28502" (File and Printer Sharing) or "@FirewallAPI.dll,-28752" (Remote Desktop).

3. Back up and restore all rules

Before any bigger change - a new application, a hardening session, a "quick test" - save the complete firewall: all rules and the profile settings. As administrator:

netsh advfirewall export "C:\backup\firewall-SRV1.wfw"

The same backup is Export Policy… in the Windows Firewall console. To restore it:

netsh advfirewall import "C:\backup\firewall-SRV1.wfw"

Know what an import does: it replaces all local rules and profile settings with those in the file. Rules added since the backup are gone. Rules from Group Policy are not touched. On a Server you reach over Remote Desktop, make sure the backup contains the rule that lets you in.

The .wfw file is binary, so you cannot see what is in it. Backup-FirewallRules.ps1 writes a readable CSV of the rules next to it, and Restore-FirewallRules.ps1 saves the current state before it restores, so a restore can be undone.

4. Reset Windows Firewall to defaults

When the rules are beyond repair, start again from the Windows defaults:

netsh advfirewall reset

A reset removes every rule you or your programs added. Programs that need inbound connections stop working until their rules are back, and on a remote Server you may lock yourself out. Export first (section 3), and do it at the console or with an out-of-band connection.

5. Profiles and default actions

Windows applies one of three profiles per network: Domain, Private or Public. Each has its own on/off switch and its own default for connections no rule matches. To see the settings that are really in force, including Group Policy:

Get-NetFirewallProfile -PolicyStore ActiveStore |
  Format-Table Name, Enabled, DefaultInboundAction, DefaultOutboundAction, LogBlocked

The safe baseline: all three profiles on, inbound Block, and dropped packets logged:

Set-NetFirewallProfile -Profile Domain,Private,Public -Enabled True -DefaultInboundAction Block -LogBlocked True

Which profile a network got: Get-NetConnectionProfile. A home or office network marked Public blocks more than you expect; a hotel network marked Private trusts strangers. More in Network profile Public or Private?.

6. Audit the rules

Rules pile up: ports opened for a test stay open, uninstalled programs leave their rules behind. Check now and then for:

Find-RiskyFirewallRules.ps1 runs these checks and names each rule. A rule is only half the story: whether something can be reached also depends on what is listening, which Get-ListeningPrograms.ps1 shows (program, port, all network cards or only this computer). For the wider check of a Server, see the Windows Server hardening checklist.

7. Manage many computers

8. Managing it by hand means…

9. With Coinetic: a Windows Firewall manager that 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

What is the best Windows Firewall manager?

For full control the built-in Windows Defender Firewall with Advanced Security console and PowerShell cover everything, for free. What they do not do is watch: they show rules, not what happens. Tools like Coinetic add the live view, automatic bans and alerts on top of the same Windows Firewall.

How do I export Windows Firewall rules?

As administrator: netsh advfirewall export "C:\backup\firewall.wfw", or Export Policy… in the Windows Firewall console. For a readable list use Get-NetFirewallRule with Export-Csv, or Get-FirewallRuleReport.ps1.

How do I reset Windows Firewall?

netsh advfirewall reset, Restore Default Policy… in the console, or Restore firewalls to default in Windows Security. Export your rules first - a reset removes every added rule.

Can I copy firewall rules to another computer?

Yes: export them on one computer and import the .wfw file on the other. The import replaces all local rules there, and program paths must match. For many computers, Group Policy or Intune is the better way.

Why does a rule I changed come back?

It probably comes from Group Policy or Intune, which re-apply their rules regularly. Check the rule's source (Get-NetFirewallRule, property PolicyStoreSourceType) and change it in the policy.