脚本添加Windows防火墙的入站规则

PowerShell命令New-NetFirewallRule可以很方便的快速添加入站规则到本地的防火墙里,下面是一些常见的例子

通过脚本设置当前机器防火墙,允许端口80的入站规则。

Write-Host -ForegroundColor Cyan "Creating new inbound rule Http"
New-NetFirewallRule -DisplayName "Http" -Direction Inbound -LocalPort 80 -RemotePort Any -Protocol TCP -Enabled True

通过脚本设置当前机器防火墙,允许端口80的出站规则。

Write-Host -ForegroundColor Cyan "Creating new outbound rule Http"
New-NetFirewallRule -DisplayName "Http" -Direction Outbound -LocalPort 80 -RemotePort Any -Protocol TCP -Enabled True

通过脚本设置当前机器防火墙,允许ICMPv4协议入站规则。

Write-Host -ForegroundColor Cyan "Creating new rule Allow Ping"
New-NetFirewallRule -DisplayName "Allow Ping" -Description "Allow ping" -Protocol ICMPv4 -IcmpType 8 -Enabled True -Profile Any -Action Allow

Comments

180 responses to “脚本添加Windows防火墙的入站规则”

Leave a Reply