How to Export and Import a Specific Firewall Rule in Windows 10
In Windows 10, you can configure Windows Firewall to have custom rules for a specific address, port or protocol. You can allow or block an app from accessing the Internet. Once you do this, it is a good idea to backup your Firewall configuration.However, Windows 10 allows only exporting and importing the entire rule set. Here's a trick that we can use to export and import a specific rule only.reset the Windows Firewall configuration, then having the ability to restore the custom configuration is very time saving.
Before you continue, see how to block any app from accessing Internet with one click in Windows 10, Windows 8 and Windows 7.
Backup and Restore Firewall Rules
In Windows 10, there are several ways to create a backup of Firewall rules. You can use Windows Firewall with Advanced Security snap-in to create or restore rules, or you can do it with the built-in console command netsh. Both methods reviewed in the post
Unfortunately, Windows 10 doesn't offer an option to backup and restore individual Firewall rules. However, it is still possible with either PowerShell, or Registry Editor.
To Export and Import a Specific Firewall Rule in Windows 10,
- Open PowerShell as Administrator.
- Change PowerShell Execution policy to Unrestricted.
- Type the following command:
Install-Module -Name Firewall-Manager, and hit the Enter key.
- Answer [Y] to proceed.
- Answer [Y] to install the module from PSGallery.
- Type the following command and hit the Enter key:
- To export a specific firewall rule, type
Export-FirewallRules -Name "<Rule name>" -CSVFile "<Path to the CSV>" file. Specify the rule name you want to export, and provide the path to the CSV file the rule will be saved to. For example,
Export-FirewallRules -Name "IRC Port" -CSVFile c:\data\winaero\irc_port.csv".
- To import a firewall rule, type
Import-FirewallRules <path to csv file>. Provide the full path the CSV file that stores a previously exported rule. For example,
You are done.
Note the Export-FirewallRules and Import-FirewallRules cmdlets support exporting/importing of multiple rules at once, and also can work with JSON files.
To learn more about them, execute
Tip: In PowerShell, you can list existing Firewall rules as follows:
If you are not a fan of PowerShell, you can export and import a firewall rule using the Registry Editor.
Export and Import a Specific Firewall Rule with Registry Editor
First of all, you need to export all available firewall rules to a single file. You can find names for Firewall rules in PowerShell, as mentioned above, or with Windows Firewall with Advanced Security. Press Win + R and type
wf.msc in the Run box to open it.
Click on Inbound Rules/Outbound rules on the left to see the list of rules.
To export all firewall rules using Registry Editor,
- Open the Registry Editor app.
- Go to the following Registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy. See how to go to a Registry key with one click.
- Right-click on the FirewallRules folder on the left and select Export... from the context menu.
- Type in the file name for the *.reg file.
- Click on the Save button.
Now, the Registry file contains the entire set of your Firewall rules. You need to leave there only the rules you want to export, and delete all other lines.
Export Only Specific Rules to Registry File
- Right-click your *.reg file in File Explorer and select Edit from the context menu to open it in Notepad.
- Below the line
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules], you will see all the rules listed.
- Remove all of them except those you want to export. The following screenshot demonstrates how to keep only one rule in the file.
- Save the changes you made (Press Ctrl + S).
This way, you can make the reg file store only the specific rules you want to export. You can search for the rule name with Ctrl + F in Notepad to save your time.
Import Windows Firewall Rules from Registry File
- Locate the *.reg file that contains your Firewall rules in File Explorer.
- Double-click on it to merge it. Confirm the UAC prompt.
- Restart Windows 10 to ensure that the rules are properly applied.
You are done.