Cómo configurar el Firewall de Windows Server

Cómo configurar el Firewall de Windows Server

A
Admin
18 min read

Introducción

El firewall de Windows (Windows Defender Firewall) es la primera línea de defensa de su servidor. Controla el tráfico de red entrante y saliente permitiendo o bloqueando conexiones según reglas definidas.

¿Por qué configurar el firewall?

  • Seguridad — Bloquear accesos no autorizados
  • Control — Definir con precisión qué servicios son accesibles
  • Protección — Reducir la superficie de ataque del servidor
  • Conformidad — Cumplir con las buenas prácticas de seguridad

Lo que aprenderá

  • Acceder y navegar en el firewall de Windows
  • Abrir y cerrar puertos
  • Crear reglas personalizadas
  • Configurar a través de la interfaz gráfica y PowerShell
  • Aplicar las buenas prácticas de seguridad


Acceder al Firewall de Windows

Métodos para acceder al firewall de Windows Server:

Método 1: Búsqueda de Windows (Rápido)

1. Presione la tecla de Windows
2. Escriba "Firewall de Windows Defender con funciones avanzadas"
3. Haga clic en el resultado

O simplemente escriba: wf.msc

Método 2: Ejecutar (Win + R)

1. Presione Windows + R
2. Escriba: wf.msc
3. Presione Enter

Método 3: Panel de control

1. Panel de control
2. Sistema y seguridad
3. Firewall de Windows Defender
4. Configuración avanzada (columna izquierda)

Método 4: Administrador del servidor

1. Abra el Administrador del servidor
2. Herramientas (Tools)
3. Firewall de Windows Defender con funciones avanzadas de seguridad

Método 5: PowerShell

# Abrir la interfaz gráfica
wf.msc

# O gestionar directamente desde la línea de comandos
Get-NetFirewallRule

Comprender la Interfaz

La interfaz del firewall de Windows se divide en varias secciones:

┌─────────────────────────────────────────────────────────────────┐
│  Firewall de Windows Defender con funciones avanzadas              │
├──────────────────┬──────────────────────────────────────────────┤
│                  │                                              │
│  ▼ Reglas de     │   [Lista de reglas]                        │
│    tráfico        │                                              │
│    entrante       │   Nombre | Grupo | Perfil | Activado | Acción   │
│                  │   ─────────────────────────────────────────  │
│  ▼ Reglas de     │   Regla 1...                                 │
│    tráfico        │   Regla 2...                                 │
│    saliente       │   Regla 3...                                 │
│                  │                                              │
│  ▼ Reglas de     │                                              │
│    seguridad      │                                              │
│    de conexión  │                                              │
│                  │                                              │
│  ▼ Análisis       │                                              │
│                  │                                              │
└──────────────────┴──────────────────────────────────────────────┘

Secciones Principales

Sección Descripción
Reglas de tráfico entrante Controla las conexiones HACIA su servidor
Reglas de tráfico saliente Controla las conexiones DESDE su servidor
Reglas de seguridad de conexión IPsec y autenticación
Análisis Monitoreo de las reglas activas

Estados de las Reglas

Ícono Significado
✅ Verde Regla activada - Permite el tráfico
✅ Verde con círculo Regla activada - Bloquea el tráfico
⬜ Gris Regla desactivada

Abrir un Puerto (Interfaz Gráfica)

Paso a Paso: Abrir un Puerto TCP

Ejemplo: Abrir el puerto 25565 (Minecraft)

Paso 1: Acceder a las reglas entrantes

1. Abra el firewall (wf.msc)
2. Haga clic en "Reglas de tráfico entrante" en el panel izquierdo
3. Haga clic en "Nueva regla..." en el panel derecho

Paso 2: Tipo de regla

○ Programa
● Puerto          ← Seleccione esta opción
○ Predefinida
○ Personalizada

→ Haga clic en "Siguiente"

Paso 3: Protocolo y puertos

● TCP           ← Para la mayoría de los servicios
○ UDP           ← Para algunos juegos/VoIP

○ Todos los puertos locales
● Puertos locales específicos: 25565

→ Haga clic en "Siguiente"

Paso 4: Acción

● Permitir la conexión      ← Seleccione esta opción
○ Permitir si está segura
○ Bloquear la conexión

→ Haga clic en "Siguiente"

Paso 5: Perfiles

☑ Dominio       ← Red de empresa (Active Directory)
☑ Privado         ← Red de confianza
☑ Público        ← Internet / Red no confiable

→ Marque los tres para un servidor
→ Haga clic en "Siguiente"

Paso 6: Nombre de la regla

Nombre: Servidor Minecraft (TCP 25565)
Descripción: Permite las conexiones al servidor Minecraft

→ Haga clic en "Finalizar"

¡El puerto 25565 TCP está ahora abierto!

Abrir un Puerto UDP

Misma procedimiento, pero seleccione UDP en el paso 3.

Ejemplo: Abrir el puerto 19132 UDP (Minecraft Bedrock)

Paso 3:
○ TCP
● UDP           ← Seleccione UDP

Puertos locales específicos: 19132

Abrir un Rango de Puertos

Para abrir varios puertos consecutivos:

Paso 3:
Puertos locales específicos: 27015-27030

→ Abre todos los puertos de 27015 a 27030

Abrir Varios Puertos No Consecutivos

Paso 3:
Puertos locales específicos: 80, 443, 8080

→ Abre los puertos 80, 443 y 8080

Cerrar un Puerto

Método 1: Desactivar una Regla Existente

1. Abra el firewall (wf.msc)
2. Reglas de tráfico entrante
3. Encuentre la regla correspondiente
4. Clic derecho → "Desactivar la regla"

Método 2: Eliminar una Regla

1. Abra el firewall (wf.msc)
2. Reglas de tráfico entrante
3. Encuentre la regla correspondiente
4. Clic derecho → "Eliminar"
5. Confirme la eliminación

Método 3: Crear una Regla de Bloqueo

Para bloquear explícitamente un puerto:

1. Nueva regla → Puerto
2. TCP o UDP → Número del puerto
3. ● Bloquear la conexión    ← Seleccione esta opción
4. Todos los perfiles
5. Nombre: "Bloquear Puerto XXXX"

⚠️ Nota: Por defecto, Windows bloquea todo lo que no está explícitamente permitido (en modo entrante). Generalmente, eliminar una regla de autorización es suficiente.


Configuración con PowerShell

PowerShell ofrece una gestión más rápida y scriptable del firewall.

Comandos Básicos

Ver el estado del firewall

# Estado general
Get-NetFirewallProfile

# Estado por perfil
Get-NetFirewallProfile -Profile Domain,Public,Private | Format-Table Name, Enabled

Activar / Desactivar el firewall

# Desactivar el firewall (NO RECOMENDADO)
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False

# Activar el firewall
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True

Abrir un Puerto con PowerShell

Sintaxis básica

New-NetFirewallRule -DisplayName "NOMBRE" -Direction Inbound -Protocol TCP -LocalPort PUERTO -Action Allow

Ejemplos concretos

# Abrir el puerto 80 (HTTP)
New-NetFirewallRule -DisplayName "HTTP" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow

# Abrir el puerto 443 (HTTPS)
New-NetFirewallRule -DisplayName "HTTPS" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow

# Abrir el puerto 25565 TCP (Minecraft Java)
New-NetFirewallRule -DisplayName "Minecraft Java" -Direction Inbound -Protocol TCP -LocalPort 25565 -Action Allow

# Abrir el puerto 19132 UDP (Minecraft Bedrock)
New-NetFirewallRule -DisplayName "Minecraft Bedrock" -Direction Inbound -Protocol UDP -LocalPort 19132 -Action Allow

# Abrir un rango de puertos
New-NetFirewallRule -DisplayName "Game Ports" -Direction Inbound -Protocol UDP -LocalPort 27015-27030 -Action Allow

# Abrir varios puertos
New-NetFirewallRule -DisplayName "Web Ports" -Direction Inbound -Protocol TCP -LocalPort 80,443,8080 -Action Allow

Abrir TCP y UDP al mismo tiempo

# Puerto 7777 TCP y UDP (ARK, etc.)
New-NetFirewallRule -DisplayName "ARK Server TCP" -Direction Inbound -Protocol TCP -LocalPort 7777 -Action Allow
New-NetFirewallRule -DisplayName "ARK Server UDP" -Direction Inbound -Protocol UDP -LocalPort 7777 -Action Allow

Cerrar / Eliminar una Regla

# Eliminar por nombre
Remove-NetFirewallRule -DisplayName "Minecraft Java"

# Desactivar una regla (sin eliminar)
Disable-NetFirewallRule -DisplayName "Minecraft Java"

# Reactivar una regla
Enable-NetFirewallRule -DisplayName "Minecraft Java"

Listar las Reglas

# Todas las reglas entrantes
Get-NetFirewallRule -Direction Inbound | Format-Table DisplayName, Enabled, Action

# Reglas activas únicamente
Get-NetFirewallRule -Direction Inbound -Enabled True | Format-Table DisplayName, Action

# Buscar una regla por nombre
Get-NetFirewallRule -DisplayName "*Minecraft*"

# Ver los detalles de una regla
Get-NetFirewallRule -DisplayName "Minecraft Java" | Get-NetFirewallPortFilter

Bloquear un Puerto

# Bloquear el puerto 23 (Telnet)
New-NetFirewallRule -DisplayName "Block Telnet" -Direction Inbound -Protocol TCP -LocalPort 23 -Action Block

Restringir por IP

# Permitir solo una IP específica
New-NetFirewallRule -DisplayName "RDP Restricted" -Direction Inbound -Protocol TCP -LocalPort 3389 -RemoteAddress 86.123.45.67 -Action Allow

# Permitir un rango de IP
New-NetFirewallRule -DisplayName "Office Network" -Direction Inbound -Protocol TCP -LocalPort 3389 -RemoteAddress 192.168.1.0/24 -Action Allow

# Permitir varias IP
New-NetFirewallRule -DisplayName "Admins Only" -Direction Inbound -Protocol TCP -LocalPort 3389 -RemoteAddress 86.123.45.67,91.234.56.78 -Action Allow

Script Completo: Configuración Servidor Web

# Script de configuración de firewall para servidor web
# A ejecutar como Administrador

Write-Host "Configuración del firewall para servidor web..." -ForegroundColor Green

# HTTP
New-NetFirewallRule -DisplayName "HTTP (80)" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow
Write-Host "✓ Puerto 80 (HTTP) abierto" -ForegroundColor Cyan

# HTTPS
New-NetFirewallRule -DisplayName "HTTPS (443)" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
Write-Host "✓ Puerto 443 (HTTPS) abierto" -ForegroundColor Cyan

# FTP (opcional)
New-NetFirewallRule -DisplayName "FTP (21)" -Direction Inbound -Protocol TCP -LocalPort 21 -Action Allow
New-NetFirewallRule -DisplayName "FTP Passive" -Direction Inbound -Protocol TCP -LocalPort 50000-50100 -Action Allow
Write-Host "✓ Puertos FTP abiertos" -ForegroundColor Cyan

# MySQL (local únicamente - seguridad)
New-NetFirewallRule -DisplayName "MySQL Local" -Direction Inbound -Protocol TCP -LocalPort 3306 -RemoteAddress 127.0.0.1 -Action Allow
Write-Host "✓ MySQL (local únicamente)" -ForegroundColor Cyan

Write-Host "`n¡Configuración terminada!" -ForegroundColor Green

Configuración con CMD (netsh)

Para aquellos que prefieren el símbolo del sistema clásico.

Sintaxis Básica

netsh advfirewall firewall add rule name="NOMBRE" dir=in action=allow protocol=TCP localport=PUERTO

Abrir un Puerto

:: Abrir el puerto 80 TCP
netsh advfirewall firewall add rule name="HTTP" dir=in action=allow protocol=TCP localport=80

:: Abrir el puerto 443 TCP
netsh advfirewall firewall add rule name="HTTPS" dir=in action=allow protocol=TCP localport=443

:: Abrir el puerto 25565 TCP (Minecraft)
netsh advfirewall firewall add rule name="Minecraft" dir=in action=allow protocol=TCP localport=25565

:: Abrir el puerto 19132 UDP
netsh advfirewall firewall add rule name="Minecraft Bedrock" dir=in action=allow protocol=UDP localport=19132

:: Abrir un rango de puertos
netsh advfirewall firewall add rule name="Game Ports" dir=in action=allow protocol=UDP localport=27015-27030

Cerrar / Eliminar una Regla

:: Eliminar una regla por nombre
netsh advfirewall firewall delete rule name="Minecraft"

:: Eliminar por puerto
netsh advfirewall firewall delete rule name=all protocol=TCP localport=25565

Listar las Reglas

:: Todas las reglas
netsh advfirewall firewall show rule name=all

:: Reglas entrantes únicamente
netsh advfirewall firewall show rule name=all dir=in

:: Buscar una regla
netsh advfirewall firewall show rule name="Minecraft"

Activar / Desactivar el Firewall

:: Desactivar (NO RECOMENDADO)
netsh advfirewall set allprofiles state off

:: Activar
netsh advfirewall set allprofiles state on

:: Activar únicamente el perfil Público
netsh advfirewall set publicprofile state on

Restringir por IP

:: Permitir únicamente una IP
netsh advfirewall firewall add rule name="RDP Restricted" dir=in action=allow protocol=TCP localport=3389 remoteip=86.123.45.67

Reglas para Aplicaciones

Puede permitir una aplicación en lugar de un puerto.

Desde la Interfaz Gráfica

1. Nueva regla
2. ● Programa     ← Seleccione esta opción
3. Navegar → Seleccione el ejecutable
   Ejemplo: C:\Minecraft\server.jar
4. Permitir la conexión
5. Todos los perfiles
6. Nombre de la regla

Desde PowerShell

# Permitir una aplicación
New-NetFirewallRule -DisplayName "Servidor Minecraft" -Direction Inbound -Program "C:\Minecraft\server.jar" -Action Allow

# Permitir Java (para todos los servidores Java)
New-NetFirewallRule -DisplayName "Java" -Direction Inbound -Program "C:\Program Files\Java\jdk-21\bin\java.exe" -Action Allow

Desde CMD

netsh advfirewall firewall add rule name="Servidor Minecraft" dir=in action=allow program="C:\Minecraft\server.jar"

Puertos Comunes a Configurar

Tabla de Referencia Rápida

Servicios Web

Servicio Puerto Protocolo Comando PowerShell
HTTP 80 TCP New-NetFirewallRule -DisplayName "HTTP" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow
HTTPS 443 TCP New-NetFirewallRule -DisplayName "HTTPS" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
HTTP Alt 8080 TCP New-NetFirewallRule -DisplayName "HTTP Alt" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow

Acceso Remoto

Servicio Puerto Protocolo Comando PowerShell
RDP 3389 TCP New-NetFirewallRule -DisplayName "RDP" -Direction Inbound -Protocol TCP -LocalPort 3389 -Action Allow
SSH 22 TCP New-NetFirewallRule -DisplayName "SSH" -Direction Inbound -Protocol TCP -LocalPort 22 -Action Allow
VNC 5900 TCP New-NetFirewallRule -DisplayName "VNC" -Direction Inbound -Protocol TCP -LocalPort 5900 -Action Allow

Transferencia de Archivos

Servicio Puerto Protocolo Comando PowerShell
FTP 21 TCP New-NetFirewallRule -DisplayName "FTP" -Direction Inbound -Protocol TCP -LocalPort 21 -Action Allow
FTP Pasivo 50000-50100 TCP New-NetFirewallRule -DisplayName "FTP Passive" -Direction Inbound -Protocol TCP -LocalPort 50000-50100 -Action Allow
SFTP 22 TCP (Mismo que SSH)
FTPS 990 TCP New-NetFirewallRule -DisplayName "FTPS" -Direction Inbound -Protocol TCP -LocalPort 990 -Action Allow

Bases de Datos

Servicio Puerto Protocolo Comando PowerShell
MySQL 3306 TCP New-NetFirewallRule -DisplayName "MySQL" -Direction Inbound -Protocol TCP -LocalPort 3306 -Action Allow
PostgreSQL 5432 TCP New-NetFirewallRule -DisplayName "PostgreSQL" -Direction Inbound -Protocol TCP -LocalPort 5432 -Action Allow
SQL Server 1433 TCP New-NetFirewallRule -DisplayName "SQL Server" -Direction Inbound -Protocol TCP -LocalPort 1433 -Action Allow
MongoDB 27017 TCP New-NetFirewallRule -DisplayName "MongoDB" -Direction Inbound -Protocol TCP -LocalPort 27017 -Action Allow
Redis 6379 TCP New-NetFirewallRule -DisplayName "Redis" -Direction Inbound -Protocol TCP -LocalPort 6379 -Action Allow

Servidores de Juegos

Juego Puerto(s) Protocolo Comando PowerShell
Minecraft Java 25565 TCP New-NetFirewallRule -DisplayName "Minecraft" -Direction Inbound -Protocol TCP -LocalPort 25565 -Action Allow
Minecraft Bedrock 19132 UDP New-NetFirewallRule -DisplayName "Minecraft Bedrock" -Direction Inbound -Protocol UDP -LocalPort 19132 -Action Allow
FiveM (GTA) 30120 TCP/UDP Ver script a continuación
Rust 28015 TCP/UDP Ver script a continuación
ARK 7777-7778 TCP/UDP Ver script a continuación
Valheim 2456-2458 UDP New-NetFirewallRule -DisplayName "Valheim" -Direction Inbound -Protocol UDP -LocalPort 2456-2458 -Action Allow
CS2 27015 TCP/UDP Ver script a continuación
Palworld 8211 UDP New-NetFirewallRule -DisplayName "Palworld" -Direction Inbound -Protocol UDP -LocalPort 8211 -Action Allow
Terraria 7777 TCP New-NetFirewallRule -DisplayName "Terraria" -Direction Inbound -Protocol TCP -LocalPort 7777 -Action Allow

Scripts Listos para Usar

Script: Servidor Minecraft Java

# Minecraft Java Edition
New-NetFirewallRule -DisplayName "Minecraft Java TCP" -Direction Inbound -Protocol TCP -LocalPort 25565 -Action Allow
New-NetFirewallRule -DisplayName "Minecraft Java UDP" -Direction Inbound -Protocol UDP -LocalPort 25565 -Action Allow
New-NetFirewallRule -DisplayName "Minecraft RCON" -Direction Inbound -Protocol TCP -LocalPort 25575 -Action Allow
New-NetFirewallRule -DisplayName "Minecraft Query" -Direction Inbound -Protocol UDP -LocalPort 25565 -Action Allow
Write-Host "Puertos Minecraft abiertos: 25565 (TCP/UDP), 25575 (RCON)" -ForegroundColor Green

Script: Servidor FiveM (GTA RP)

# Servidor FiveM
New-NetFirewallRule -DisplayName "FiveM TCP" -Direction Inbound -Protocol TCP -LocalPort 30120 -Action Allow
New-NetFirewallRule -DisplayName "FiveM UDP" -Direction Inbound -Protocol UDP -LocalPort 30120 -Action Allow
New-NetFirewallRule -DisplayName "FiveM HTTP" -Direction Inbound -Protocol TCP -LocalPort 40120 -Action Allow
Write-Host "Puertos FiveM abiertos: 30120 (TCP/UDP), 40120 (HTTP)" -ForegroundColor Green

Script: Servidor Rust

# Servidor Dedicado Rust
New-NetFirewallRule -DisplayName "Rust Game TCP" -Direction Inbound -Protocol TCP -LocalPort 28015 -Action Allow
New-NetFirewallRule -DisplayName "Rust Game UDP" -Direction Inbound -Protocol UDP -LocalPort 28015 -Action Allow
New-NetFirewallRule -DisplayName "Rust RCON" -Direction Inbound -Protocol TCP -LocalPort 28016 -Action Allow
New-NetFirewallRule -DisplayName "Rust App" -Direction Inbound -Protocol TCP -LocalPort 28082 -Action Allow
Write-Host "Puertos Rust abiertos: 28015, 28016 (RCON), 28082 (App)" -ForegroundColor Green

Script: Servidor ARK

# ARK: Survival Evolved
New-NetFirewallRule -DisplayName "ARK Game UDP" -Direction Inbound -Protocol UDP -LocalPort 7777-7778 -Action Allow
New-NetFirewallRule -DisplayName "ARK Query UDP" -Direction Inbound -Protocol UDP -LocalPort 27015 -Action Allow
New-NetFirewallRule -DisplayName "ARK RCON TCP" -Direction Inbound -Protocol TCP -LocalPort 27020 -Action Allow
Write-Host "Puertos ARK abiertos: 7777-7778, 27015, 27020" -ForegroundColor Green

Script: Servidor CS2 / CSGO

# Counter-Strike 2
New-NetFirewallRule -DisplayName "CS2 Game TCP" -Direction Inbound -Protocol TCP -LocalPort 27015 -Action Allow
New-NetFirewallRule -DisplayName "CS2 Game UDP" -Direction Inbound -Protocol UDP -LocalPort 27015 -Action Allow
New-NetFirewallRule -DisplayName "CS2 RCON" -Direction Inbound -Protocol TCP -LocalPort 27015 -Action Allow
New-NetFirewallRule -DisplayName "CS2 Steam" -Direction Inbound -Protocol UDP -LocalPort 27020 -Action Allow
Write-Host "Puertos CS2 abiertos: 27015 (TCP/UDP), 27020" -ForegroundColor Green

Perfiles de Firewall

Windows utiliza tres perfiles de firewall según el tipo de red.

Los Tres Perfiles

Perfil Descripción Uso
Dominio Red con Active Directory Empresa
Privado Red de confianza Casa, oficina
Público Red no confiable Internet, Wi-Fi público

¿Qué Perfil para un Servidor?

Para un VPS o servidor dedicado accesible desde Internet:

→ Utilice el perfil "Público" o "Todos los perfiles"

Configurar una Regla por Perfil

Interfaz Gráfica

Al crear la regla (paso 5):
☐ Dominio
☐ Privado
☑ Público     ← Para un servidor de Internet

PowerShell

# Regla únicamente para el perfil Público
New-NetFirewallRule -DisplayName "Web Server" -Direction Inbound -Protocol TCP -LocalPort 80 -Profile Public -Action Allow

# Regla para todos los perfiles
New-NetFirewallRule -DisplayName "Web Server" -Direction Inbound -Protocol TCP -LocalPort 80 -Profile Any -Action Allow

Ver el Perfil Activo

# Ver qué perfil está activo
Get-NetConnectionProfile

# Resultado ejemplo:
# Name             : Network
# NetworkCategory  : Public    ← Perfil activo

Cambiar el Perfil de una Conexión

# Pasar a perfil Privado
Set-NetConnectionProfile -InterfaceAlias "Ethernet" -NetworkCategory Private

# Pasar a perfil Público
Set-NetConnectionProfile -InterfaceAlias "Ethernet" -NetworkCategory Public

Buenas Prácticas de Seguridad

✅ A Hacer

Práctica Descripción
Principio del menor privilegio No abra más puertos de los estrictamente necesarios
Nombrar claramente las reglas "Servidor Minecraft TCP 25565" en lugar de "Regla1"
Documentar las reglas Mantenga un registro de lo que está abierto y por qué
Restringir por IP si es posible Limite el acceso RDP a su IP fija
Utilizar puertos no estándar Cambie el puerto RDP de 3389 a otro
Auditar regularmente Verifique las reglas activas periódicamente
Mantener el firewall activado Nunca "desactivar para probar" permanentemente

❌ A Evitar

Mala práctica Riesgo
Desactivar el firewall Servidor expuesto a todos los ataques
Abrir todos los puertos Superficie de ataque máxima
Reglas demasiado permisivas Accesos no autorizados
Ignorar las reglas salientes Exfiltración de datos posible
Sin documentación Imposible mantener la seguridad

Configuración Segura Recomendada

# 1. Asegurarse de que el firewall esté activado
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True

# 2. Política por defecto: bloquear entrante, permitir saliente
Set-NetFirewallProfile -Profile Domain,Public,Private -DefaultInboundAction Block
Set-NetFirewallProfile -Profile Domain,Public,Private -DefaultOutboundAction Allow

# 3. Activar los logs
Set-NetFirewallProfile -Profile Domain,Public,Private -LogBlocked True -LogAllowed False -LogFileName %SystemRoot%\System32\LogFiles\Firewall\pfirewall.log

# 4. RDP restringido por IP (reemplazar por su IP)
Remove-NetFirewallRule -DisplayName "Remote Desktop*" -ErrorAction SilentlyContinue
New-NetFirewallRule -DisplayName "RDP Restricted" -Direction Inbound -Protocol TCP -LocalPort 3389 -RemoteAddress SU.IP.PUBLICA -Action Allow

Auditoría de Reglas Activas

# Exportar todas las reglas activas
Get-NetFirewallRule -Enabled True -Direction Inbound | 
    Select-Object DisplayName, Profile, Action | 
    Export-Csv -Path "C:\firewall_rules.csv" -NoTypeInformation

# Mostrar las reglas que permiten todo
Get-NetFirewallRule -Enabled True -Direction Inbound -Action Allow | 
    Where-Object { $_.Profile -eq "Any" } |
    Format-Table DisplayName, Profile

Solución de Problemas

Problema: El puerto parece cerrado a pesar de la regla

Verificaciones:

# 1. Verificar que la regla existe y está activa
Get-NetFirewallRule -DisplayName "*NombreDeLaRegla*" | Format-Table DisplayName, Enabled, Action

# 2. Verificar el puerto asociado
Get-NetFirewallRule -DisplayName "NombreDeLaRegla" | Get-NetFirewallPortFilter

# 3. Verificar que el servicio escucha en el puerto
netstat -an | findstr "25565"

# 4. Probar localmente
Test-NetConnection -ComputerName localhost -Port 25565

Soluciones comunes:

  1. La regla está desactivada → Actívela
  2. Mauvais protocole → Verifique TCP vs UDP
  3. Mauvais profil → Verifique que el perfil correcto esté activo
  4. El servicio no escucha → Inicie la aplicación
  5. Pare-feu del hosting → Verifique el firewall del panel de hosting

Problema: "Acceso denegado" al crear regla

Solución:

Ejecute PowerShell o CMD como Administrador:
1. Clic derecho en PowerShell
2. "Ejecutar como administrador"

Problema: Demasiadas reglas, difícil de gestionar

Solución: Exportar y limpiar

# Exportar todas las reglas
netsh advfirewall export "C:\firewall_backup.wfw"

# Ver las reglas desactivadas (candidatas a eliminación)
Get-NetFirewallRule -Enabled False | Format-Table DisplayName

# Eliminar las reglas desactivadas
Get-NetFirewallRule -Enabled False | Remove-NetFirewallRule

Problema: Restaurar la configuración por defecto

# Reiniciar el firewall (ATENCIÓN: elimina todas las reglas personalizadas)
netsh advfirewall reset

# O a través de la interfaz:
# Firewall de Windows → "Restaurar la configuración por defecto"

Probar si un Puerto está Abierto

Desde otro ordenador:

# PowerShell
Test-NetConnection -ComputerName IP_DEL_SERVIDOR -Port 25565

# Resultado esperado:
# TcpTestSucceeded : True    ← Puerto abierto
# TcpTestSucceeded : False   ← Puerto cerrado

Desde Internet:

Utilice una herramienta en línea como:

Logs del Firewall

Activar los logs:

# Activar la auditoría
Set-NetFirewallProfile -Profile Domain,Public,Private -LogBlocked True -LogMaxSizeKilobytes 4096

# Ubicación de los logs
%SystemRoot%\System32\LogFiles\Firewall\pfirewall.log

Analizar los logs:

# Ver las últimas entradas bloqueadas
Get-Content "C:\Windows\System32\LogFiles\Firewall\pfirewall.log" -Tail 50 | Where-Object { $_ -match "DROP" }

Ayuda-Memoria Rápida

Comandos PowerShell Esenciales

# Abrir un puerto TCP
New-NetFirewallRule -DisplayName "NOMBRE" -Direction Inbound -Protocol TCP -LocalPort PUERTO -Action Allow

# Abrir un puerto UDP
New-NetFirewallRule -DisplayName "NOMBRE" -Direction Inbound -Protocol UDP -LocalPort PUERTO -Action Allow

# Eliminar una regla
Remove-NetFirewallRule -DisplayName "NOMBRE"

# Listar las reglas activas
Get-NetFirewallRule -Enabled True -Direction Inbound | Format-Table DisplayName, Action

# Desactivar una regla
Disable-NetFirewallRule -DisplayName "NOMBRE"

# Activar una regla
Enable-NetFirewallRule -DisplayName "NOMBRE"

Comandos CMD Esenciales

:: Abrir un puerto
netsh advfirewall firewall add rule name="NOMBRE" dir=in action=allow protocol=TCP localport=PUERTO

:: Eliminar una regla
netsh advfirewall firewall delete rule name="NOMBRE"

:: Listar las reglas
netsh advfirewall firewall show rule name=all dir=in

:: Activar el firewall
netsh advfirewall set allprofiles state on

Conclusión

El firewall de Windows Server es una herramienta poderosa para asegurar su servidor. Puntos clave a recordar:

  1. Mantenga el firewall activado — Siempre
  2. No abra más de lo necesario — Principio del menor privilegio
  3. Utilice PowerShell — Más rápido y scriptable
  4. Documente sus reglas — Para facilitar el mantenimiento
  5. Audite regularmente — Verifique las reglas activas

Próximos pasos recomendados:

  • Asegurar el acceso RDP (cambiar el puerto, restringir por IP)
  • Configurar los logs del firewall
  • Crear un script de configuración para sus servidores
  • Establecer una política de revisión periódica