/build/static/layout/Breadcrumb_cap_w.png

How to add firewall rules using “Netsh.exe” The Efficient Way

What is firewall?

A firewall is software that checks information coming from the Internet or a network, and then either blocks it or allows it to pass through to your computer, depending on your firewall settings. It blocks potentially harmful software components from reaching your computer.

To communicate any executable with the internet, a rule to be added in the firewall. There are two types of rules based on the orientation of communication

A.       Inbound Rule: Applies when data communication is ‘In to Out’ form

B.       Outbound Rule: Applies when data communication is ‘Out to In’ form

Unlike traditional Vb Scripting method, Command line method for adding the firewall rule is efficient and easy.

 Command Line to add firewall rule:

Netsh.exe advfirewall firewall add rule name="<Rule Name>" program="<FilePath>" protocol=tcp dir=in enable=yes action=allow profile=Private

Parameter Description:

·         Name=<Name of the rule you want >

·         program=<”Path of the executable”>

·         protocol=tcp  or udp

·         dir=Inbound(in) or outbound(out) rule

·         enable=yes or no

·         action=allow or block or custom

·         profile=Private and/or public and/or domain (To add rule in more than one profile use “,” E.g.: profile=private, domain )

Note: Rule can’t be added for both the protocols at one time, to do so use separate command with protocol value replaced. Same applies for “dir” and “action” tags.

 

Command Line to Remove firewall rule:

Netsh.exe advfirewall firewall delete rule "<Rule Name>"

To verify the successful rule addition, type “wf.msc” in Run


Comments

  • so I noticed when you run netsh.exe advfirewall firewall delete rule name="<rule name>", it errors: No rules match the specified criteria.

    does that mean it can delete multiple rules with * and ? specials? - yanger 3 years ago
  • try Netsh.exe advfirewall firewall delete rule "<Rule Name>" - Heet 3 years ago
This post is locked

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ