Powershell script to configure Firewall

 Here's a PowerShell script that will configure the firewall on a Windows Server:


# Enable firewall rules for incoming traffic New-NetFirewallRule -DisplayName "Allow incoming HTTP traffic" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 80 New-NetFirewallRule -DisplayName "Allow incoming HTTPS traffic" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 443 # Enable firewall rules for outgoing traffic New-NetFirewallRule -DisplayName "Allow outgoing HTTP traffic" -Direction Outbound -Action Allow -Protocol TCP -RemotePort 80 New-NetFirewallRule -DisplayName "Allow outgoing HTTPS traffic" -Direction Outbound -Action Allow -Protocol TCP -RemotePort 443 # Disable firewall rules for incoming traffic on all other ports Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False

This script creates four firewall rules: two for incoming traffic on ports 80 (HTTP) and 443 (HTTPS), and two for outgoing traffic on the same ports. It also disables the firewall for incoming traffic on all other ports.


Note: This is a basic script, and you may need to adjust the firewall rules based on your specific needs.


No comments:

Post a Comment