如何在PowerShell中添加多个端口例外?
美国、香港服务器
如何在PowerShell中添加多个端口例外?
07-08 来源:
一、场景 1:多个独立端口(80,443,3389)入站放行
powershell
New-NetFirewallRule -DisplayName "Web+远程桌面 TCP 80,443,3389" `
-Direction Inbound -Protocol TCP -LocalPort 80,443,3389 `
-Action Allow -Profile Any
二、场景 2:端口区间(3000-3050)
powershell
New-NetFirewallRule -DisplayName "业务端口区间3000-3050 TCP" `
-Direction Inbound -Protocol TCP -LocalPort 3000-3050 `
-Action Allow -Profile Any
三、场景 3:独立端口 + 区间混合(80,443,5000-5100)
powershell
New-NetFirewallRule -DisplayName "Web+业务区间端口" `
-Direction Inbound -Protocol TCP -LocalPort 80,443,5000-5100 `
-Action Allow -Profile Any
四、场景 4:仅允许指定 IP 访问多端口(安全白名单)
只允许 123.123.123.123 访问 80/443:
powershell
New-NetFirewallRule -DisplayName "80/443仅信任IP访问" `
-Direction Inbound -Protocol TCP -LocalPort 80,443 `
-RemoteAddress "123.123.123.123/32" `
-Action Allow -Profile Any
多 IP 白名单示例:
powershell
-RemoteAddress "123.123.123.123/32,192.168.1.0/24"
五、场景 5:出站多端口放行(程序对外联网)
powershell
New-NetFirewallRule -DisplayName "出站80/443/53 TCP" `
-Direction Outbound -Protocol TCP -LocalPort 80,443,53 `
-Action Allow -Profile Any
三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快