Netsh, short for Network Shell, is a command-line utility designed to assist IT administrators in configuring and viewing various network-related functions on Windows 11/10. This tool can also be utilized to manage Windows Firewall. If you are seeking simple ways to perform tasks via the command line, then Netsh is a valuable utility to be familiar with and utilize. In this post, we will learn how you can use the Netsh Command to manage Windows Firewall.
Use Netsh Command to manage Windows Firewall
Windows Firewall configuration is available deep into the settings, which makes it uncountable. There are no context menus and a one-step method to get a few things done. It is beneficial when you need to do that often. You can save the command in a BAT file and run it with admin permission to execute it quickly.
There used to be netsh firewall
a command, but that has been replaced or will be deprecated by netsh advfirewall.
The list of options you get the advfirewall are as follows:
- consec – Changes to the `netsh advfirewall consec’ context.
- dump – Displays a configuration script.
- export – Exports the current policy to a file.
- firewall – Changes to the `netsh advfirewall firewall’ context.
- add – Adds a new inbound or outbound firewall rule.
- delete – Deletes all matching firewall rules.
- dump – Displays a configuration script.
- set – Sets new values for properties of an existing rule.
- show – Displays a specified firewall rule.
- help – Displays a list of commands.
- import – Imports a policy file into the current policy store.
- mainmode – Changes to the `netsh advfirewall mainmode’ context.
- monitor – Changes to the `netsh advfirewall monitor’ context.
- reset – Resets the policy to the default out-of-box policy.
- set – Sets the per-profile or global settings.
- show – Displays profile or global properties.
List of Firewall Commands (Examples)
Here is a list of some common commands you can use, such as to enable ports, allow programs, and so on.
Enable a Port
netsh advfirewall firewall add rule name= "Open Port 80" dir=in action=allow protocol=TCP localport=80
Delete enabled programs or ports
netsh advfirewall firewall delete rule name= rule name program="C:\MyApp\MyApp.exe"
netsh advfirewall firewall delete rule name= rule name protocol=udp localport=500
Enable specific services
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes
Enable Windows firewall
netsh advfirewall set currentprofile state on
Restore policy defaults
netsh advfirewall reset
There are many more things that you can do with Netsh utility.
Covering all of them will be out of scope, and hence we recommend reading more details on the official Microsoft Documents.
Read next: How to allow Pings (ICMP Echo requests) through Windows Firewall.
How do I use netsh commands in Windows?
Netsh command in Windows can be used in any of the preinstalled command-line utilities including the Command Prompt and Windows PowerShell. You open either of the apps with administrative privileges and run netsh.
Also Read: Run Sudo Command in Windows.