Você pode configurar o Firewall do Windows pela linha de comando usando netsh advfirewall no CMD ou Set-NetFirewallRule no PowerShell. Essas ferramentas permitem criar, modificar, ativar ou desativar regras de firewall com precisão e automação.
O Firewall do Windows pode ser gerenciado por dois métodos principais:
- CMD com
netsh advfirewall - PowerShell com
Set-NetFirewallRuleeNew-NetFirewallRule
🧭 1. Usando CMD (netsh advfirewall)
✅ Verificar o status do firewall
netsh advfirewall show allprofiles
🔒 Ativar ou desativar o firewall
netsh advfirewall set allprofiles state on
netsh advfirewall set allprofiles state off
➕ Criar regra para permitir porta específica
netsh advfirewall firewall add rule name="Permitir Porta 8080" dir=in action=allow protocol=TCP localport=8080
❌ Bloquear um aplicativo
netsh advfirewall firewall add rule name="Bloquear App" dir=out action=block program="C:\Caminho\App.exe"
⚙️ 2. Usando PowerShell
✅ Listar regras existentes
Get-NetFirewallRule
➕ Criar nova regra
New-NetFirewallRule -DisplayName "Permitir HTTP" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow
❌ Bloquear aplicativo
New-NetFirewallRule -DisplayName "Bloquear Chrome" -Direction Outbound -Program "C:\Program Files\Google\Chrome\Application\chrome.exe" -Action Block
🔄 Ativar/desativar regra específica
Disable-NetFirewallRule -DisplayName "Permitir HTTP"
Enable-NetFirewallRule -DisplayName "Permitir HTTP"
🧠 Boas Práticas
- Use nomes descritivos para facilitar manutenção.
- Teste regras em ambientes controlados antes de aplicar em produção.
- Combine com scripts de auditoria para verificar integridade das regras.
- Use o Agendador de Tarefas para aplicar regras automaticamente em horários específicos.
📚 Fontes Relevantes
- Microsoft Learn – Gerir a Firewall do Windows com a Linha de Comandos
- Procedimento.com.br – Configurar o Firewall com CMD e PowerShell
- TechExpert – Bloquear IP via linha de comando
