Skip to content

Instantly share code, notes, and snippets.

@Sporax
Created February 13, 2019 18:03
Show Gist options
  • Save Sporax/0f40d5e0aead265a35dbc7d9c407e42f to your computer and use it in GitHub Desktop.
Save Sporax/0f40d5e0aead265a35dbc7d9c407e42f to your computer and use it in GitHub Desktop.
Cheat sheet to set windows firewall using powershell or netsh

Netsh

enable/disable firewall

netsh advfirewall set [privateprofile|publicprofile|domainprofile|currentprofile] state [on|off]

set default firewall action

netsh advfirewall set [privateprofile|publicprofile|domainprofile|currentprofile] firewallpolicy [allowinbound|blockinbound|blockinboundalways|notconfigured],[allowoutbound|blockoutbound|notconfigured]

add rule

netsh advfirewall firewall add rule name="My Application" dir=in action=allow program="C:\MyApp\MyApp.exe" enable=yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet profile=domain

show all rules

netsh advfirewall firewall show rule status=enabled name=all

delete a rule

netsh advfirewall firewall delete rule name=rule name protocol=udp localport=500

Powershell commands

link: Disable-NetFirewallRule Enable-NetFirewallRule Get-NetFirewallProfile Get-NetFirewallRule Get-NetFirewallSetting - Retrieves the global firewall settings of the target computer. New-NetFirewallRule Remove-NetFirewallRule Rename-NetFirewallRule Set-NetFirewallProfile Set-NetFirewallRule Set-NetFirewallSetting Show-NetFirewallRule

comparison

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment