Windows 防火墙

这个快速参考备忘单提供了使用 Windows 防火墙 常用命令的使用清单

防火墙管理

Powershell 命令行

action参数
封堵远程地址New-NetFirewallRule -DisplayName Rule100 -Direction Inbound -Action Block -RemoteAddress 10.10.10.0/24
封堵本地端口New-NetFirewallRule -DisplayName Rule100 -Direction Inbound -Action Block -Protocol TCP -LocalPort 8080
查看防火墙规则Get-NetFirewallRule -DisplayName Rule100
查看防火墙规则Get-NetFirewallRule -DisplayName Rule100 | Get-NetFirewallAddressFilter
删除防火墙规则Remove-NetFirewallRule -DisplayName Rule100
防火墙运行状态Get-NetFirewallProfile | Select-Object Name,Enabled
开启防火墙Set-NetFirewallProfile -Enabled True
关闭防火墙Set-NetFirewallProfile -Enabled False

CMD 命令行

action参数
封堵远程地址netsh advfirewall firewall add rule name="Rule100" dir=in action=block remoteip=10.10.10.0/24
封堵本地端口netsh advfirewall firewall add rule name="Rule100" dir=in action=block protocol=TCP localport=8080
查看防火墙规则netsh advfirewall firewall show rule name="Rule100"
删除防火墙规则netsh advfirewall firewall delete rule name="Rule100"
防火墙运行状态netsh advfirewall show currentprofile
开启防火墙netsh advfirewall set allprofiles state on
关闭防火墙netsh advfirewall set allprofiles state off
关闭防火墙net stop sharedaccess