Files
fn_registry/powershell/functions/infra/win_firewall_add_rule.md
T
egutierrez 4d6ea9a910 feat: funciones PowerShell infra — firewall y portproxy
Funciones PowerShell para gestión de red en Windows: win_firewall_add_rule,
win_firewall_remove_rule, win_portproxy_add y win_portproxy_remove.
Útiles para configurar acceso de red en entornos WSL2.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 14:24:45 +02:00

2.0 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports tested tests test_file_path file_path
win_firewall_add_rule function ps infra 1.0.0 impure win_firewall_add_rule -Name <string> -Port <int> [-Protocol <string>] Añade una regla de entrada al firewall de Windows para permitir tráfico en un puerto TCP/UDP. Si ya existe una regla con el mismo nombre, la elimina y la recrea. Requiere privilegios de Administrador.
firewall
windows
netsh
network
infra
security
port
wsl2
false error_go_core
false
powershell/functions/infra/win_firewall_add_rule.ps1

Uso

# Desde PowerShell (como Administrador)
.\win_firewall_add_rule.ps1 -Name "CDP-9222" -Port 9222

# Con protocolo explícito
.\win_firewall_add_rule.ps1 -Name "MyApp-UDP-5000" -Port 5000 -Protocol UDP
# Desde WSL2
powershell.exe -ExecutionPolicy Bypass -File win_firewall_add_rule.ps1 -Name "CDP-9222" -Port 9222

Parametros

Parametro Tipo Obligatorio Default Descripcion
-Name string si Nombre de la regla en el firewall
-Port int si Puerto local (1-65535)
-Protocol string no TCP Protocolo: TCP o UDP

Notas

  • Requiere ejecutarse como Administrador en Windows. Si se llama desde WSL2, usar powershell.exe (que corre en Windows) o pwsh.exe.
  • Si ya existe una regla con el mismo nombre, la elimina primero y la recrea (idempotente respecto al nombre).
  • La regla creada es dir=in action=allow — solo aplica para tráfico entrante.
  • Caso de uso principal: permitir que WSL2 alcance Chrome CDP en el host Windows cuando Chrome escucha en 127.0.0.1:9222.
  • Retorna exit code 0 si tuvo éxito, 1 si hubo error (falta de privilegios, puerto inválido, fallo de netsh).