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 vs Outbound

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:

1
Press Win + R to open the Run dialog
2
Type 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:

1
Click "Inbound Rules" in the left panel, then "New Rule..." in the right panel
2
Select "Program" and click Next
3
Browse to the program's .exe file (e.g., C:\Program Files\MyApp\app.exe)
4
Choose "Allow the connection" or "Block the connection"
5
Select which profiles apply (Domain, Private, Public) and give the rule a name

Creating a Port-Based Rule

To control traffic on specific ports:

1
Click "Inbound Rules" then "New Rule..."
2
Select "Port" and click Next
3
Choose TCP or UDP and enter the port number (e.g., 8080) or range (e.g., 3000-3010)
4
Choose the action (Allow or Block) and finish the wizard

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 -an in Command Prompt to see active connections and listening ports
  • Temporarily disable the rule to confirm it was actually affecting traffic
⚠️
Be careful with outbound blocks

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
🎉
You now have granular control!

Custom firewall rules give you precise control over which programs and ports can communicate on your network.