...

*Cube-Host – 完整的雲端服務!

Windows VPS:如何配置Windows Server防火墙

Windows VPS: How to configure the Windows Server firewall

检查配置文件并启用防火墙

Windows防火墙包含三种配置文件:域/私有/公共。在VPS环境中,通常启用公共配置文件。安全基础设置:入站:阻止,出站:允许

图形界面:「Windows Defender防火墙与高级安全」→ 根配置文件界面。

windows VPS

PowerShell:

  Get-NetFirewallProfile | Select Name,Enabled,DefaultInboundAction,DefaultOutboundAction
Set-NetFirewallProfile -Profile Domain,Private,Public -Enabled True  

保护RDP(3389/TCP)

RDP是管理Windows VPS的必要通道,但不能对“所有人”开放。操作步骤如下:临时启用默认规则,基于源IP创建自定义限制规则,随后禁用“通用”规则。

GUI(新建规则向导):

1. 入站规则 → 新建规则…端口

windows VPS 1

2. TCP特定本地端口:3389

windows VPS 2

授权连接

windows VPS 3

创建完成后,请转至属性 → 区域,并指定远程IP地址(您的静态IP子网/VPN)。此操作对安全至关重要。

PowerShell:

  # When connecting for the first time: enable the standard group
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"

# Strict rule only from your IP
New-NetFirewallRule -DisplayName "RDP inbound (admin IP only)" `
  -Direction Inbound -Protocol TCP -LocalPort 3389 -Action Allow `
  -RemoteAddress 203.0.113.50 -Profile Any

# After verification, disable “broad” RDP rules.
Disable-NetFirewallRule -DisplayGroup "Remote Desktop"
  

我们只开放真正必要的内容

IIS/HTTPS

  New-NetFirewallRule -DisplayName "HTTP (80)"  -Direction Inbound -Protocol TCP -LocalPort 80  -Action Allow
New-NetFirewallRule -DisplayName "HTTPS (443)" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
  

MS SQL(如使用)

  New-NetFirewallRule -DisplayName "MSSQL (1433)" -Direction Inbound -Protocol TCP -LocalPort 1433 -Action Allow  

(若从受限网络访问,请同时为这些规则定义RemoteAddress)。

启用日志记录(这对故障排除非常有用)。

授权被阻断的连接记录在pfirewall.log中。

GUI:

windows VPS 4

PowerShell:

  Set-NetFirewallProfile -Profile Domain,Private,Public `
  -LogFileName "C:\Windows\System32\LogFiles\Firewall\pfirewall.log" `
  -LogMaxSizeKilobytes 32768 -LogAllowed True -LogBlocked True  

外部快速验证

从客户端PC验证所需端口是否可访问:

  # RDP
Test-NetConnection vps.example.ru -Port 3389
# Веб
Test-NetConnection vps.example.ru -Port 80
Test-NetConnection vps.example.ru -Port 443
# SQL (if necessary)
Test-NetConnection vps.example.ru -Port 1433
  

TcpTestSucceeded: True:规则生效,端口可用。若为False:请与供应商核对规则配置文件、作用域(源IP)及外部访问控制列表(ACL)。

简要故障排查清单

  • RDP设置为“对所有人开放”:添加RemoteAddress并禁用默认通用规则。
  • 配置文件错误:规则定义为“私有”,但服务器位于公共区域。
  • 未启用日志记录:请开启日志功能,否则“隐形”阻塞难以检测。
  • 忽略外部防火墙/Windows VPS供应商SG:请并行检查。