三二互联专业提供速度最快最稳定的美国服务器、香港服务器。中美直连,亚洲优化![ 代理登陆 ] [ 付款方式 ] [ 找回密码 ][ 电子协议责任书 ]
硬件资源保障

采用高配品牌服务器

主流强悍CPU配置

确保服务高速稳定运行

中美直连线路

中美直连亚洲优化

采用中国CN2骨干网络

保证速度飞快稳定高效

如何在PowerShell中创建新的出站防火墙规则?

美国、香港服务器

如何在PowerShell中创建新的出站防火墙规则?

08-07   来源:

 基础模板通用结构

powershell
New-NetFirewallRule `
-DisplayName "自定义规则名称" `
-Direction Outbound `
-Action Allow `       # Allow允许 / Block阻止
-Protocol TCP `       # TCP/UDP/Any
-LocalPort Any `      # 本机出站端口一般Any
-RemotePort "目标端口" `
-RemoteAddress "目标IP" `
-Enabled True `
-Profile Any
常用示例(直接复制修改使用)
示例 1:阻止服务器访问指定外网 IP(全部端口拦截)
powershell
New-NetFirewallRule `
-DisplayName "出站阻止访问 1.2.3.4" `
-Direction Outbound `
-Action Block `
-Protocol Any `
-RemoteAddress "1.2.3.4" `
-Enabled True `
-Profile Any
示例 2:阻止服务器对外访问外部 80/443 端口
powershell
New-NetFirewallRule `
-DisplayName "出站阻止访问外网80、443" `
-Direction Outbound `
-Action Block `
-Protocol TCP `
-RemotePort "80,443" `
-Enabled True `
-Profile Any
示例 3:仅允许服务器访问指定外部 IP 的 3306 端口(数据库)
powershell
New-NetFirewallRule `
-DisplayName "出站仅允许连接10.0.0.5:3306" `
-Direction Outbound `
-Action Allow `
-Protocol TCP `
-RemoteAddress "10.0.0.5" `
-RemotePort 3306 `
-Enabled True `
-Profile Any
示例 4:放行服务器对外 DNS(UDP 53)
powershell
New-NetFirewallRule `
-DisplayName "出站放行DNS UDP53" `
-Direction Outbound `
-Action Allow `
-Protocol UDP `
-RemotePort 53 `
-Enabled True `
-Profile Any
示例 5:阻止服务器访问一段 IP 网段
powershell
New-NetFirewallRule `
-DisplayName "出站阻止网段 192.168.1.0/24" `
-Direction Outbound `
-Direction Outbound `
-Action Block `
-Protocol Any `
-RemoteAddress "192.168.1.0/24" `
-Enabled True `
-Profile Any
参数区分重点(非常容易搞混)
表格
参数 出站规则含义
-LocalPort 服务器本机端口,绝大多数出站场景填 Any
-RemotePort 目标机器的端口(重点!)
-RemoteAddress 要访问的外部 IP / 网段
-Direction Outbound 服务器主动向外访问
-Direction Inbound 外部主动连服务器
创建完成校验命令
powershell
# 查看这条出站规则详情
Get-NetFirewallRule -DisplayName "自定义规则名称" | Format-List *
快速筛选所有出站规则
powershell
Get-NetFirewallRule -Direction Outbound | Select DisplayName,Action,Enabled

三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快

上一篇:如何在PowerShell中创建新的防火墙规则? 下一篇:如何在PowerShell中修改防火墙规则?

美国GIA服务器三二互联版权所有 WWW.250.cc 2008-2015 All Rights Reserved
三二互联 - 专业的美国C3服务器、香港vps、抗DOOS流量清洗、云备份系统、网站加速系统、美国GIA服务器和香港云服务器产品提供商
三二互联24小时在线工单系统为您提供全面、专业、周到的技术支持与服务
咨询热线:400-679-9994(免长话费)