如何在PowerShell中查看已创建的防火墙规则?
美国、香港服务器
如何在PowerShell中查看已创建的防火墙规则?
07-09 来源:
1. 查看所有启用的入站放行规则(精简输出,日常最常用)
powershell
Get-NetFirewallRule -Direction Inbound -Action Allow -Enabled True | Select DisplayName,LocalPort,Protocol,RemoteAddress
字段含义:
DisplayName:防火墙规则名称;
LocalPort:本机开放端口;
Protocol:TCP/UDP;
RemoteAddress:允许访问的客户端 IP。
2. 只查看指定端口(例如筛选 80、443)
powershell
Get‑NetFirewallRule -Direction Inbound -Action Allow | Where‑Object {$_.LocalPort -in "80","443"} | Select DisplayName,LocalPort
3. 查看出站规则
powershell
Get-NetFirewallRule -Direction Outbound -Action Allow -Enabled True | Select DisplayName,LocalPort,Protocol
4. 查看完整详细信息(完整参数)
powershell
# 查看443相关全部规则详情
Get‑NetFirewallRule | Where‑Object {$_.LocalPort -match "443"} | Format‑List *
5. 按名称关键词筛选(比如规则名以允许TCP开头)
powershell
Get‑NetFirewallRule -DisplayName "允许TCP*" -Enabled True
6. 只列出禁用的防火墙规则
powershell
Get‑NetFirewallRule -Enabled False -Direction Inbound
7. 导出防火墙规则到文本文件,方便备份查看
powershell
Get‑NetFirewallRule | Select DisplayName,Direction,LocalPort,Protocol,Action,Enabled | Out‑File C:\firewall_rules.txt
补充实用操作配合前面学过的命令
查到不需要的规则后删除:
powershell
Remove‑NetFirewallRule -DisplayName "你的规则名" -Confirm:$false
临时关闭规则(不删除):
powershell
Disable‑NetFirewallRule -DisplayName "你的规则名"
三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快