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.

Mar 28, 2025 - 10:33
Updated: 
109.4k

Network Security in Cybersecurity & Ethical Hacking · Lab / project

Windows Firewall: Configure and Test Inbound and Outbound Rules

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?

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.

ProfileUsed whenTypical stance
DomainJoined to and reaching an Active Directory domainManaged by Group Policy
PrivateTrusted home or office networkSome sharing allowed
PublicCafes, airports, unknown networksMost 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
ResultLikely meaning
Test succeedsRule allows traffic and service is listening
Test fails, DROP in logNo matching allow rule, or a block rule wins
Test fails, nothing in logService 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

Inbound rules control new connections coming into the computer, and outbound rules control connections the computer starts towards other systems.

No. The default profiles allow outbound traffic and block unsolicited inbound traffic unless an allow rule matches.

Run New-NetFirewallRule with Direction Inbound, the protocol, LocalPort and Action Allow in an elevated PowerShell window.

Yes, netsh advfirewall firewall still works, though Microsoft recommends the NetSecurity PowerShell cmdlets for new scripts.

In general the block rule takes precedence, so check for conflicting block rules when an allow rule seems not to work.

From another computer run Test-NetConnection with the target address and port, and check whether TcpTestSucceeded is True.

By default at %SystemRoot%\System32\LogFiles\Firewall\pfirewall.log, once logging of dropped or allowed packets is enabled.

No. Create a narrow allow rule instead. Turning the firewall off exposes every listening service on the computer.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.