在 Windows 防火墙中开放端口(VPS)
要让 Windows VPS 上的服务(IIS 网站、游戏服务器、API)可以从互联网访问,除了服务商处可能存在的规则之外,通常还需要在 Windows Defender 防火墙中放行该端口。
开始之前
- 通过远程桌面连接:参见通过 RDP 连接。
- 了解端口号和协议(TCP 或 UDP)。
- 只开放您需要的端口(最小权限原则)。
方法 1:图形向导
- 打开高级安全 Windows Defender 防火墙(
wf.msc)。 - 入站规则 → 新建规则…
- 端口 → TCP(或 UDP)→ 特定本地端口:例如
80、443或8080。 - 允许连接。
- 选择配置文件(域、专用、公用——在 VPS 上通常需要选择公用)。
- 为其起一个清晰的名称,例如
HTTP IIS 80。
方法 2:PowerShell(TCP 80 和 443)
以管理员身份打开 PowerShell:
PowerShellNew-NetFirewallRule -DisplayName "HTTP TCP 80" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow New-NetFirewallRule -DisplayName "HTTPS TCP 443" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
自定义端口示例:
PowerShellNew-NetFirewallRule -DisplayName "MyApp TCP 5000" -Direction Inbound -Protocol TCP -LocalPort 5000 -Action Allow
验证是否有服务在监听
PowerShellGet-NetTCPConnection -State Listen | Where-Object { $_.LocalPort -eq 80 }
或者:
PowerShellnetstat -ano | findstr :80
安全提示
- 开放端口会暴露该服务:请保持更新,使用强密码,并尽可能为网站启用 TLS。
- 如果流量始终无法到达虚拟机,请确认云安全组的设置。
我们的 Windows VPS 提供相同的 8 个地点:Windows VPS 法国、Windows VPS 德国、Windows VPS 荷兰、Windows VPS 英国、Windows VPS 美国、Windows VPS 加拿大、Windows VPS 土耳其和 Windows VPS 香港。同时也提供桌面版本:Windows 10 RDP 和 Windows 11 RDP。
故障排除
- 仍然无法访问:确保应用程序监听的是
0.0.0.0或公网接口,而不仅仅是127.0.0.1。 - RDP 问题:不要删除系统自带的 RDP 规则;如果被锁定在外,请使用服务商的控制台。