Use netsh advfirewall firewall instead of netsh firewall to control Windows Firewall behavior
Article
This article describes how to use the netsh advfirewall firewall context instead of the netsh firewall context to control Windows Firewall behavior.
Original KB number: 947709
Summary
The netsh advfirewall firewall command-line context is available in Windows Server 2012 R2. This context provides the functionality for controlling Windows Firewall behavior that was provided by the netsh firewall firewall context.
This context also provides functionality for more precise control of firewall rules. These rules include the following per-profile settings:
Domain
Private
Public
The netsh firewall command-line context might be deprecated in a future version of the Windows operating system. We recommend that you use the netsh advfirewall firewall context to control firewall behavior.
Important
If you are a member of the Administrators group, and User Account Control is enabled on your computer, run the commands from a command prompt with elevated permissions. To start a command prompt with elevated permissions, find the icon or Start menu entry that you use to start a command prompt session, right-click it, and then click Run as administrator.
Some examples of frequently used commands are provided in the following tables. You can use these examples to help you migrate from the older netsh firewall context to the new netsh advfirewall firewall context.
Additionally, the netsh advfirewall commands that you can use to obtain detailed inline help are provided.
Command example 1: Enable a program
Old command
New command
netsh firewall add allowedprogram C:\MyApp\MyApp.exe "My Application" ENABLE
For more information about how to configure ICMP settings, run the following command:
netsh advfirewall firewall add rule ?
Command example 5: Set logging
Old command
New command
netsh firewall set logging %systemroot%\system32\LogFiles\Firewall\pfirewall.log 4096 ENABLE ENABLE
Run the following commands: netsh advfirewall set currentprofile logging filename %systemroot%\system32\LogFiles\Firewall\pfirewall.log netsh advfirewall set currentprofile logging maxfilesize 4096 netsh advfirewall set currentprofile logging droppedconnections enable netsh advfirewall set currentprofile logging allowedconnections enable
For more information, run the following command:
netsh advfirewall set currentprofile ?
If you want to set logging for a particular profile, use one of the following options instead of the currentprofile option:
Domainprofile
Privateprofile
Publicprofile
Command example 6: Enable Windows firewall
Old command
New command
netsh firewall set opmode ENABLE
netsh advfirewall set currentprofile state on
netsh firewall set opmode mode=ENABLE exceptions=enable
Run the following commands: Netsh advfirewall set currentprofile state on netsh advfirewall set currentprofile firewallpolicy blockinboundalways,allowoutbound
netsh firewall set opmode mode=enable exceptions=disable profile=domain
Run the following commands: Netsh advfirewall set domainprofile state on netsh advfirewall set domainprofile firewallpolicy blockinbound,allowoutbound
netsh firewall set opmode mode=enable profile=ALL
Run the following commands: netsh advfirewall set domainprofile state on netsh advfirewall set privateprofile state on
For more information, run the following command:
netsh advfirewall set currentprofile ?
If you want to set the firewall state for a particular profile, use one of the following options instead of the currentprofile option:
Domainprofile
Privateprofile
Publicprofile
Command example 7: Restore policy defaults
Old command
New command
netsh firewall reset
netsh advfirewall reset
For more information, run the following command:
netsh advfirewall reset ?
Command example 8: Enable specific services
Old command
New command
netsh firewall set service FileAndPrint
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
netsh firewall set service RemoteDesktop enable
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes
netsh firewall set service RemoteDesktop enable profile=ALL
Run the following commands:
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes profile=domain
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes profile=private
As a Windows Server hybrid administrator, you integrate Windows Server environments with Azure services and manage Windows Server in on-premises networks.