Windows Firewall: Configure and Test Inbound and Outbound Rules
Windows Defender Firewall filters traffic per network profile (Domain, Private, Public). By default it blocks unsolicited inbound connections and allows outbound ones. To open a port, create an inbound allow rule with New-NetFirewallRule in an elevated PowerShell window or with netsh advfirewall firewall add rule. To stop an application reaching the internet, create an outbound block rule for its program path.
Topic: Network Security in Cybersecurity & Ethical Hacking · Lab / project
Quick answer: Windows Defender Firewall filters traffic per network profile (Domain, Private, Public). By default it blocks unsolicited inbound connections and allows outbound ones. To open a port, create an inbound allow rule with New-NetFirewallRule in an elevated PowerShell window or with netsh advfirewall firewall add rule. To stop an application reaching the internet, create an outbound block rule for its program path. Test from another machine with Test-NetConnection, confirm blocked attempts in the firewall log, and remove test rules when done. Scope every rule to the right profile, port and remote addresses.
Key takeaways
- Rules apply per profile, so pick Domain, Private or Public deliberately.
- Inbound is blocked by default; outbound is allowed by default.
- Block rules generally win over allow rules.
- Test from a second machine, not only locally.
- Name rules clearly and remove test rules afterwards.
Table of Contents
- How Does Windows Firewall Decide What to Allow?
- How Do You Check the Current Profiles and Defaults?
- How Do You Create an Inbound Allow Rule?
- How Do You Block an Application Outbound?
- How Do You Test Rules in Real Time?
- How Do You Review, Disable and Remove Rules?
- What Good Practices Keep Rules Safe?
- References
How Does Windows Firewall Decide What to Allow?
The Windows Firewall documentation describes a host-based, stateful firewall. Replies to connections you started are allowed automatically. New traffic is matched against rules for the active profile; if nothing matches, the profile default applies. For general firewall concepts, see what a firewall is and how it works.
| Profile | Used when | Typical stance |
|---|---|---|
| Domain | Joined to and reaching an Active Directory domain | Managed by Group Policy |
| Private | Trusted home or office network | Some sharing allowed |
| Public | Cafes, airports, unknown networks | Most restrictive |
How Do You Check the Current Profiles and Defaults?
Get-NetFirewallProfile | Format-Table Name, Enabled, DefaultInboundAction, DefaultOutboundAction
Get-NetConnectionProfile
The second command shows which profile each network adapter is using.
How Do You Create an Inbound Allow Rule?
Example: allow a lab web server on TCP 8080 only from the local subnet on the Private profile. Using New-NetFirewallRule:
New-NetFirewallRule -DisplayName "Lab Web 8080" -Direction Inbound -Protocol TCP -LocalPort 8080 -RemoteAddress LocalSubnet -Profile Private -Action Allow
The same rule with netsh advfirewall:
netsh advfirewall firewall add rule name="Lab Web 8080" dir=in action=allow protocol=TCP localport=8080 remoteip=localsubnet profile=private
How Do You Block an Application Outbound?
New-NetFirewallRule -DisplayName "Block Notepad Out" -Direction Outbound -Program "%SystemRoot%\System32\notepad.exe" -Action Block
Outbound block rules help contain unwanted tools or limit data leaving a sensitive host. Use the full program path; a wrong path silently matches nothing.
How Do You Test Rules in Real Time?
From a second machine on the same subnet, run Test-NetConnection:
Test-NetConnection -ComputerName 192.168.56.10 -Port 8080
TcpTestSucceeded True means the rule and the service both work. Then turn on logging of dropped packets with Set-NetFirewallProfile and watch the log:
Set-NetFirewallProfile -Profile Domain,Private,Public -LogBlocked True
Get-Content "$env:SystemRoot\System32\LogFiles\Firewall\pfirewall.log" -Wait -Tail 20
| Result | Likely meaning |
|---|---|
| Test succeeds | Rule allows traffic and service is listening |
| Test fails, DROP in log | No matching allow rule, or a block rule wins |
| Test fails, nothing in log | Service not listening or network path issue |
How Do You Review, Disable and Remove Rules?
Get-NetFirewallRule -DisplayName "Lab Web 8080" | Get-NetFirewallPortFilter
Disable-NetFirewallRule -DisplayName "Lab Web 8080"
Remove-NetFirewallRule -DisplayName "Lab Web 8080"
netsh advfirewall firewall delete rule name="Lab Web 8080"
What Good Practices Keep Rules Safe?
- Allow the narrowest port, program and remote address range possible, following NIST SP 800-41.
- Never turn the firewall off to fix a connection problem.
- Manage business machines centrally with Group Policy or Intune and compare against CIS benchmarks.
- Keep firewall logs; CERT-In directions require organisations in India to retain ICT logs for 180 days.
For the Linux side, read our guide to iptables and firewalld. WebAsha covers host firewalls in its network security training.
References
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0