Development

How to Configure Windows Firewall Rules Using Netsh Easy To Follow

Captain Salem 2 min read

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

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.

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

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.

Share
Comments
More from Cloudenv

Cloudenv

Developer Tips, Tricks and Tutorials.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Cloudenv.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.