How to Configure Windows Firewall Rules Using Netsh: Easy To Follow

In this post, we will learn how we can use the netsh command to configure firewall rules in Windows in simple commands.

How to Configure Windows Firewall Rules Using Netsh: Easy To Follow

Windows

Netsh (Network Shell) is a command-line utility in Windows that allows users to configure and monitor various aspects of the operating system's network components. It provides a scripting interface to manage network settings, such as interface configuration, firewall rules, and routing tables.

Netsh can configure network interfaces, change IP addresses and subnet masks, enable or disable specific network protocols, configure network filters and packet capturing, and troubleshoot network-related problems.

How to Access the Network Shell

In Windows, we can access netsh using the Command Prompt or Windows PowerShell.

Open Command Prompt with administrative privileges. Click on the Start menu, type cmd, right-click on Command Prompt, and select "Run as administrator."

In the command prompt, you can open the network shell by running the command:

netsh

This should open the netsh prompt and allow you to configure networks:

netsh>

Netsh Show Firewall Rules

To view the current firewall rules, enter the following command:

netsh advfirewall firewall show rule name=all

Output:

Rule Name:                            Remote Event Log Management (NP-In)
----------------------------------------------------------------------
Enabled:                              No
Direction:                            In
Profiles:                             Domain
Grouping:                             Remote Event Log Management
LocalIP:                              Any
RemoteIP:                             Any
Protocol:                             TCP
LocalPort:                            445
RemotePort:                           Any
Edge traversal:                       No
Action:                               Allow

Rule Name:                            Remote Assistance (TCP-Out)
----------------------------------------------------------------------
Enabled:                              No
Direction:                            Out
Profiles:                             Public
Grouping:                             Remote Assistance
LocalIP:                              Any
RemoteIP:                             Any
Protocol:                             TCP
LocalPort:                            Any
RemotePort:                           Any
Edge traversal:                       No
Action:                               Allow

Rule Name:                            Network Discovery (UPnP-Out)
----------------------------------------------------------------------
Enabled:                              No
Direction:                            Out
Profiles:                             Public
Grouping:                             Network Discovery
LocalIP:                              Any
RemoteIP:                             LocalSubnet
Protocol:                             TCP
LocalPort:                            Any
RemotePort:                           2869
Edge traversal:                       No
Action:                               Allow

Rule Name:                            Wi-Fi Direct Spooler Use (Out)
----------------------------------------------------------------------
Enabled:                              Yes
Direction:                            Out
Profiles:                             Public
Grouping:                             Wi-Fi Direct Network Discovery
LocalIP:                              Any
RemoteIP:                             Any
Protocol:                             Any
Edge traversal:                       No
Action:                               Allow
Ok.

Netsh Create New Inbound Firewall Rule

To create a new inbound firewall rule, enter the following command:

netsh advfirewall firewall add rule name="Name of Rule" dir=in action=allow protocol=TCP localport=PortNumber

Replace "Name of Rule" with the name you want to give the rule, and "PortNumber" with the port number you want to allow.

To deny an inbound connection, run the command:

netsh advfirewall firewall add rule name="RuleName" dir=in action=block protocol=any

Replace "RuleName" with a name you want to give to the rule.

Press Enter.

This command creates a new inbound firewall rule with the name "RuleName" and sets the "action" parameter to "block", which means any incoming traffic matching the specified criteria will be blocked.

Netsh Create New Outbound Firewall Rule

To create a new inbound firewall rule, enter the following command:

netsh advfirewall firewall add rule name="Name of Rule" dir=in action=allow protocol=TCP localport=PortNumber

To block the traffic, run the command:

netsh advfirewall firewall add rule name="Name of Rule" dir=in action=blocks protocol=TCP localport=PortNumber

Netsh Delete Existing Firewall Rule

To delete a firewall rule, enter the following command:

netsh advfirewall firewall delete rule name="Name of Rule"

The command above will remove the firewall rule with the specified name.

NOTE: Please be careful when modifying firewall rules as incorrect settings can cause security issues.

Conclusion

In this tutorial, we learned how we can manage Windows network firewall rules using the Network Shell utility in Windows.

We hope you enjoyed this tutorial. Feel free to leave us a comment below to learn more.

Cool Stuff.

Windows Netsh Command CheatSheet
This cheatsheet contains the common and useful commands for the Windows Network Shell Command.
How to Use Netsh to Configure Network Interfaces on Windows
This tutorial will discuss various netsh commands to configure multiple network properties in a Windows system.

If you enjoy our content, please consider buying us a coffee to support our work:

Table of Contents
Great! Next, complete checkout for full access to GeekBits.
Welcome back! You've successfully signed in.
You've successfully subscribed to GeekBits.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.