Search code examples
firewallwindows-firewallnetsh

Trying to block port Windows Firewall from netsh firewall


I'm trying to create a Windows Firewall rule to block specific port from netsh firewall.

I looking at the following documentation: https://technet.microsoft.com/en-us/library/cc771920(v=ws.10).aspx

What I've been tried:

add portopening protocol=all port=12345 name="Tes1" mode=enable scope=all profile=all

The problem is that in the General Tab->Action i see "Allow the connection", how can i set the action to "Block the connection"?

Thanks.


Solution

  • netsh firewall is deprecated, use netsh advfirewall firewall instead as follow:

    netsh advfirewall firewall add rule name="Block12345" protocol=TCP dir=in localport=12345 action=block
    

    You can read about that in: https://technet.microsoft.com/en-us/library/dd734783(v=ws.10).aspx