Advertisement

Export and Import Specific Firewall Rule in Windows 10

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.

Advertisеment

Having a backup of firewall rules is very useful. If you reinstall Windows 10, you will be able to restore your custom rules quickly. Or, if you need to 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

How to Backup and Restore Firewall Rules in Windows 10

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,

  1. Open PowerShell as Administrator.
  2. Change PowerShell Execution policy to Unrestricted.
  3. Type the following command: Install-Module -Name Firewall-Manager, and hit the Enter key.
  4. Answer [Y] to proceed.Windows 10 Install Firewall Manager PowerShell Module
  5. Answer [Y] to install the module from PSGallery.Windows 10 Install Firewall Manager PowerShell Module 2
  6. Type the following command and hit the Enter key: Import-Module Firewall-Manager.Windows 10 Import Module Firewall Manager
  7. 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".Windows 10 Export Individual Windows Firewall Rule
  8. 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, Import-FirewallRules "C:\data\winaero\irc_port.csv".Windows 10 Import Individual Windows Firewall Rule

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 Get-Help Export-FirewallRules:Windows 10 Export FirewallRules Cmdlet

Tip: In PowerShell, you can list existing Firewall rules as follows: Get-NetFirewallRule |Format-Table|more.

Windows 10 List Firewall Rules PowerShell

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.

Open Windows Firewall With Advanced Security

Click on Inbound Rules/Outbound rules on the left to see the list of rules.

Windows Firewall With Advanced Security

To export all firewall rules using Registry Editor,

  1. Open the Registry Editor app.
  2. 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.
  3. Right-click on the FirewallRules folder on the left and select Export... from the context menu.Windows 10 Firewall Rules In Registry
  4. Type in the file name for the *.reg file.Windows 10 Export Firewall Rules To Reg File
  5. 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

  1. Right-click your *.reg file in File Explorer and select Edit from the context menu to open it in Notepad.
  2. Below the line [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules], you will see all the rules listed.Windows 10 Firewall Rules Containted In Reg File
  3. Remove all of them except those you want to export. The following screenshot demonstrates how to keep only one rule in the file.Windows 10 Export Only One Firewall Rule To Reg File
  4. 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

  1. Locate the *.reg file that contains your Firewall rules in File Explorer.
  2. Double-click on it to merge it. Confirm the UAC prompt.
  3. Restart Windows 10 to ensure that the rules are properly applied.

You are done.

Support us

Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:

If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!

Advertisеment

Author: Sergey Tkachenko

Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

8 thoughts on “Export and Import Specific Firewall Rule in Windows 10”

  1. I realize that my comment has little or nothing to do with the topick, but I need some help. I am not totally illiterate to the computer, but am not familiar with the terminology. My Windows 7/8 spider solitaire was removed during a windows update. I have tried desperately to retrieve it with no luck. Can somebody give me step by step instructions please

  2. On a fresh Windows 10 installation I used WinAeroTweaker to make the OS a bit more user friendly.
    It is a great tool (especially since one can check what the twek do where to attain the desired effects !)
    One bug I have on my system is that when I click on Network / “Export specific Firewall Rules” The program hangs ans stays in a not responding state. I have to kill it.
    It might have something to do with the Execution policies of the Power-Shell “Export-FirewallRules” module.
    I just have to remember never to click on that item ;-)
    Jacob

    1. nope, it is not related to PowerShell.
      It is some loop issue in the app.
      I am working to resolve it.

  3. seems nothing works right with powershell, always have to fiddle with this, wiggle that and takes so much time versus a reg edit.

  4. YOU ARE NOT DONE! If you used powershell, you left it wide open for hackers. You must change the execution policy back to restricted.
    Set-ExecutionPolicy restricted

Leave a Reply

Your email address will not be published.

css.php
Using Telegram? Subscribe to the blog channel!
Hello. Add your message here.