What Are Firewall Rules?
Windows Firewall rules are instructions that tell the firewall whether to allow or block specific network traffic. Rules can be based on programs, ports, protocols, or IP addresses.
By creating custom rules, you gain granular control over exactly which applications can communicate over the network and on which ports.
Inbound rules control traffic coming INTO your computer. Outbound rules control traffic going OUT from your computer to the network or internet.
Opening Advanced Firewall Settings
The basic Windows Firewall panel has limited options. For creating custom rules, use the advanced interface:
wf.msc and press Enter
This opens "Windows Defender Firewall with Advanced Security" where you can see all inbound and outbound rules.
Creating a Program Rule
To allow or block a specific application:
C:\Program Files\MyApp\app.exe)
Creating a Port-Based Rule
To control traffic on specific ports:
Using PowerShell
You can also create rules via PowerShell (run as Administrator):
# Allow inbound TCP port 8080
New-NetFirewallRule -DisplayName "Allow Port 8080" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow
# Block outbound connections for a program
New-NetFirewallRule -DisplayName "Block MyApp" -Direction Outbound -Program "C:\MyApp\app.exe" -Action Block
# Remove a rule
Remove-NetFirewallRule -DisplayName "Allow Port 8080"
Testing Your Rules
After creating a rule, verify it works:
- Check the rule appears in the rules list and is enabled (green checkmark)
- Test the connection the rule affects (try accessing the port or running the program)
- Use
netstat -anin Command Prompt to see active connections and listening ports - Temporarily disable the rule to confirm it was actually affecting traffic
Blocking outbound traffic for the wrong program can break Windows Update, antivirus updates, or other essential services. Test changes carefully.
Summary
In this tutorial, you learned:
- The difference between inbound and outbound firewall rules
- How to open the Advanced Firewall interface
- Creating rules based on programs and ports
- Managing rules with PowerShell commands
- How to test and verify your firewall rules
Custom firewall rules give you precise control over which programs and ports can communicate on your network.