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.
- 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-NetFirewallRulelists the rules; ports, programs and addresses sit in separate filters. - Backup:
netsh advfirewall export "C:\backup\firewall.wfw"before every bigger change;importrestores it. - Reset:
netsh advfirewall resetor 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
- Windows Security › Firewall & network protection: switch each profile on or off, Allow an app through firewall, Restore firewalls to default. Good for a quick look, not for rules.
- Windows Defender Firewall with Advanced Security (Start, type "firewall"): every inbound and outbound rule, the profile settings (default actions, logging), Export Policy and Import Policy. This is the full manager that comes with Windows.
- PowerShell (the NetSecurity module, Windows 8 / Server 2012 and later):
Get-,New-,Set-,Enable-,Disable-andRemove-NetFirewallRule,Get-andSet-NetFirewallProfile. Best for repeatable changes and for many computers. - netsh advfirewall: the older command line, also on Windows 7 / Server 2008 R2. Still the simplest way to export, import and reset.
- Group Policy (domains) and Microsoft Intune (Endpoint security › Firewall): central rules for many computers. Rules from a policy show up locally but can only be changed in the policy.
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:
- Windows Security › Firewall & network protection › Restore firewalls to default, or
- the Windows Firewall console › Restore Default Policy…, or as administrator:
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:
- a profile switched off, or inbound set to Allow;
- inbound rules that allow any program, any port, any address;
- admin ports allowed from any address: Remote Desktop (3389), SMB (445), WinRM (5985/5986), SQL Server (1433), SSH (22), VNC (5900) and the like - especially on the Public profile;
- rules for programs that no longer exist;
- logging off, so nobody can see what was blocked.
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
- Group Policy: Computer Configuration › Policies › Windows Settings › Security Settings › Windows Defender Firewall with Advanced Security. Decide there whether local rules still apply (Customize › Apply local firewall rules).
- Intune: Endpoint security › Firewall for profiles and rules on managed devices.
- PowerShell remoting: the same scripts on many Servers at once, e.g.
Invoke-Command -ComputerName SRV1, SRV2 -FilePath .\Find-RiskyFirewallRules.ps1.
8. Managing it by hand means…
- Snapshots only: a report or an audit shows the moment you run it, not what happened last night.
- No rule name in the firewall log, so "what blocked this?" is detective work.
- Rules to maintain: program paths change with updates, and nobody remembers why a rule is there.
- Nobody watching: scanners and password guessers keep trying, and Windows raises no alert.
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.
- See every connection live, with the rule that decided it. Blocked lines always name the rule. (For allowed traffic Windows does not report which allow rule matched, so those lines say (allowed).)
- One click from a log line to a rule. Right-click › Make a rule matching this packet or Edit the matching rule.
- Programs ask once before they connect out: allow, LAN only, only this address, block, or allow for a while.
- Scanners and password guessers are banned automatically, also at night: the Coinetic Protection service runs in the background, also when nobody is logged on.
- A security scan finds weak spots, such as ports open to the internet, and fixes what it can with one click.
- Nothing hidden: Coinetic's rules are normal Windows Firewall rules whose names start with
Coinetic, from Windows 7 / Server 2008 R2 on, in any Windows language. - Your AI security analyst (Pro + AI): right-click any line, ban, port or connection and choose Ask AI. It looks up this computer's Coinetic data itself and answers in plain words.
Download Coinetic, install, done - it starts protecting at once. 30 days free with all features, no payment details. From $20 per computer per year.
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.