如何在PowerShell中添加出站规则?
美国、香港服务器
如何在PowerShell中添加出站规则?
09-24 来源:
## 1. 放行指定远程端口(TCP,示例:出站 443 HTTPS)
New-NetFirewallRule -DisplayName "Outbound_Allow_HTTPS_443" `
-Direction Outbound `
-Action Allow `
-Protocol TCP `
-RemotePort 443 `
-Enabled True `
-Profile Any
参数说明:
- `-Direction Outbound`:出站规则
- `-RemotePort`:**目标端口(对外访问的端口)**,出站不要写 LocalPort,容易搞反
- `-Profile Any`:域 / 专用 / 公用全部生效;可改为 Domain,Private
## 2. 放行多个端口(80,443,53)
New-NetFirewallRule -DisplayName "Outbound_Allow_Web_DNS" `
-Direction Outbound `
-Action Allow `
-Protocol TCP `
-RemotePort 80,443,53 `
-Enabled True `
-Profile Any
## 3. UDP 端口示例(DNS UDP53)
New-NetFirewallRule -DisplayName "Outbound_Allow_DNS_UDP53" `
-Direction Outbound `
-Action Allow `
-Protocol UDP `
-RemotePort 53 `
-Enabled True `
-Profile Any
## 4. 只允许访问指定远端 IP(白名单 IP 出站)
仅允许服务器出站访问 `114.114.114.114`
New-NetFirewallRule -DisplayName "Outbound_Allow_DNS_114.114.114.114" `
-Direction Outbound `
-Action Allow `
-Protocol UDP `
-RemoteAddress 114.114.114.114 `
-RemotePort 53 `
-Enabled True `
-Profile Any
## 5. 放行 RDP 出站(服务器主动对外 RDP)
New-NetFirewallRule -DisplayName "Outbound_Allow_RDP_3389" `
-Direction Outbound `
-Action Allow `
-Protocol TCP `
-RemotePort 3389 `
-Enabled True `
-Profile Any
# ✅ 查看新建的出站规则,验证是否创建成功
Get-NetFirewallRule -Direction Outbound | Where-Object {$_.DisplayName -match "Outbound"}
# 🗑 删除规则(应急,规则名替换)
Remove-NetFirewallRule -DisplayName "Outbound_Allow_HTTPS_443"
三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快