Skip to content

How to Configure Windows Firewall Rules on Windows Server

Configure Windows Defender Firewall rules on Windows Server with the GUI and PowerShell New-NetFirewallRule: profiles, inbound/outbound rules, scoping, and testing.

MGMCSA Guru Team November 3, 2026 8 min read
Photographic illustration for How to Configure Windows Firewall Rules on Windows Server: enterprise server room with directory and network admin console

Windows Defender Firewall is on by default on Windows Server, and it’s one of the few security controls that costs nothing and works out of the box. The mistake people make isn’t ignoring it — it’s turning it off the first time something doesn’t connect, instead of adding the right rule. A host firewall is what stops a compromised machine on your LAN from freely reaching RDP and SMB on every other server, so it’s worth configuring properly.

This guide covers both ways to manage firewall rules: the GUI (wf.msc) for one-off changes and visibility, and PowerShell’s New-NetFirewallRule and friends for anything you want to repeat or script. We’ll cover profiles, inbound and outbound rules, scoping rules to specific sources, and testing — plus the gotchas that lock people out of their own servers.

A quick warning up front: it’s entirely possible to firewall yourself out of a remote server. Read the locked-out section before you start changing rules on a box you only reach over RDP or WinRM.

How Windows Defender Firewall is structured

Three concepts cover most of what you need.

Profiles. The firewall applies one of three profiles per network connection:

Firewall profiles

Domain Active when the server can authenticate to its AD domain. Usual profile on a domain-joined server.
Private For trusted private networks that aren't a domain.
Public For untrusted networks. Most restrictive by default.

Default actions. Out of the box, inbound connections that don’t match an allow rule are blocked, and outbound connections are allowed. So most of your work is adding inbound allow rules for the services the server hosts.

Rules. Each rule has a direction (inbound/outbound), an action (allow/block), a protocol and port (or a program/service), and a scope (which addresses, profiles, and interfaces it applies to).

# See the current state and default actions for each profile
Get-NetFirewallProfile | Select-Object Name, Enabled, DefaultInboundAction, DefaultOutboundAction

Creating rules in the GUI

For a quick, visible change, the Windows Defender Firewall with Advanced Security console is fine.

  1. Run wf.msc (Start > type “Windows Defender Firewall with Advanced Security”).
  2. Select Inbound Rules > New Rule in the Actions pane.
  3. Choose a rule type — usually Port (for a TCP/UDP port) or Program (for an executable).
  4. Specify the protocol and port, e.g. TCP 443.
  5. Choose Allow the connection (or allow only if secure, for IPsec).
  6. Pick which profiles it applies to (Domain/Private/Public).
  7. Name it something you’ll recognize later, like “Allow HTTPS inbound”.

The GUI is good for inspecting existing rules and understanding what’s already there. For anything you’ll do more than once, PowerShell is faster and repeatable.

Creating rules with PowerShell

The NetSecurity module is the modern way to manage the firewall. New-NetFirewallRule is the core cmdlet.

Open a basic inbound port:

# Allow inbound HTTPS (TCP 443)
New-NetFirewallRule -DisplayName "Allow HTTPS Inbound" `
  -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow

Scope it to a profile and a source subnet, which is far better than allowing the whole world:

# Allow RDP only from the admin subnet, Domain profile only
New-NetFirewallRule -DisplayName "Allow RDP from Admin Subnet" `
  -Direction Inbound -Protocol TCP -LocalPort 3389 -Action Allow `
  -Profile Domain -RemoteAddress 10.0.50.0/24

Allow a specific program rather than a fixed port (useful for apps that pick dynamic ports):

# Allow a specific application to receive inbound traffic
New-NetFirewallRule -DisplayName "Allow App Server" `
  -Direction Inbound -Program "C:\Apps\MyService\service.exe" -Action Allow

Block something explicitly (block rules win over allow rules when both match):

# Block outbound SMB to the internet as a safety measure
New-NetFirewallRule -DisplayName "Block Outbound SMB to Internet" `
  -Direction Outbound -Protocol TCP -RemotePort 445 -Action Block `
  -RemoteAddress Internet

Common New-NetFirewallRule parameters

-DisplayName Human-readable name shown in the console
-Direction Inbound or Outbound
-Action Allow, Block, or Allow (Bypass for IPsec)
-Protocol TCP, UDP, ICMPv4, etc.
-LocalPort / -RemotePort Port the server listens on / remote port
-RemoteAddress Source/destination scope: IP, CIDR, range, LocalSubnet, Internet
-Profile Domain, Private, Public, Any (comma-separated)
-Program / -Service Scope to an executable or a Windows service

Managing existing rules

You rarely just create rules. You also adjust, disable, and inspect them.

# Find rules by name pattern
Get-NetFirewallRule -DisplayName "*RDP*" | Select-Object DisplayName, Enabled, Direction, Action

# Tighten an existing rule's source scope (e.g. the built-in Remote Desktop group)
Set-NetFirewallRule -DisplayGroup "Remote Desktop" -RemoteAddress 10.0.50.0/24

# Disable a rule without deleting it
Disable-NetFirewallRule -DisplayName "Allow HTTPS Inbound"

# Re-enable it later
Enable-NetFirewallRule -DisplayName "Allow HTTPS Inbound"

# Remove a rule entirely
Remove-NetFirewallRule -DisplayName "Allow App Server"

To see the port and address filters attached to a rule (the details aren’t on the rule object itself, they’re on associated filter objects):

# Inspect the port filter for a rule
Get-NetFirewallRule -DisplayName "Allow RDP from Admin Subnet" |
  Get-NetFirewallPortFilter

# Inspect the address scope for a rule
Get-NetFirewallRule -DisplayName "Allow RDP from Admin Subnet" |
  Get-NetFirewallAddressFilter

Don’t lock yourself out

This is the part that catches people. If you manage a server only over RDP or WinRM and you change firewall rules carelessly, you can cut your own connection and have no way back in short of console access.

A few habits that prevent it:

  • Never create a broad inbound block rule, or change the default inbound action to block-all, without first confirming your management port (RDP 3389 or WinRM 5985/5986) has an explicit allow rule scoped to your source.
  • When tightening RDP with -RemoteAddress, make sure your own admin host or subnet is included in the allowed range.
  • Test changes on a non-critical server, or one you can reach via console (iLO/iDRAC/Hyper-V/VM console), first.

Profile-level settings

Sometimes you want to change behavior for a whole profile rather than per rule.

# Make sure the firewall is enabled on all profiles
Set-NetFirewallProfile -Profile Domain,Private,Public -Enabled True

# Enable logging of dropped packets for the Domain profile (useful for troubleshooting)
Set-NetFirewallProfile -Profile Domain `
  -LogBlocked True -LogFileName "%SystemRoot%\System32\LogFiles\Firewall\pfirewall.log"

In a domain, you’ll often manage firewall rules centrally with Group Policy instead of per server, so every server of a given role gets the same baseline. Local rules and GPO rules merge by default, but you can configure policy so GPO rules take precedence. If GPO firewall settings aren’t taking effect, the usual culprits are the same as any policy problem — see why Group Policy isn’t applying and how to fix it.

Testing your rules

Don’t assume a rule works because it exists. Verify from the client side.

# From a client: test whether a TCP port is reachable on the server
Test-NetConnection -ComputerName fileserver01 -Port 445

# On the server: confirm something is actually listening on the port
Get-NetTCPConnection -State Listen -LocalPort 443

Test-NetConnection tells you whether the port is open and reachable end to end. If it fails, check in order: the service is running and listening, the inbound allow rule exists and is enabled, the rule’s profile matches the active profile, and the -RemoteAddress scope includes the client.

Firewall rule checklist

  • Firewall enabled on Domain, Private, and Public profiles
  • Inbound allow rules exist for each service the server hosts
  • Management ports (RDP/WinRM) scoped to admin subnets, not Any
  • Rules named and grouped so they're easy to find and manage
  • Verified reachability with Test-NetConnection from a real client
  • GPO vs local rule merge behavior decided for managed servers

Wrapping up

Configuring Windows Defender Firewall on Windows Server comes down to a simple loop: leave it enabled, add specific inbound allow rules for the services you run, scope sensitive ports to known sources, and test from the client. New-NetFirewallRule makes all of that repeatable, which is what you want once you’re managing more than a handful of servers.

The two rules that save you the most pain: never disable the firewall to “fix” a connection, and never tighten rules on a remote-only server without first confirming your own management path stays open. Get those right and the firewall becomes a quiet, useful layer instead of something you fight.

Frequently asked questions

What is the difference between inbound and outbound firewall rules?

Inbound rules control traffic coming to the server (clients reaching a service like RDP or a web app). Outbound rules control traffic the server initiates to other hosts. By default Windows Defender Firewall blocks unsolicited inbound traffic and allows outbound, so most rule work is on the inbound side unless you choose to restrict outbound too.

Should I disable Windows Firewall on a server?

No. Disabling it removes a layer that limits lateral movement between machines on the same network, which a perimeter firewall can't see. Leave it enabled on all profiles and create specific allow rules for the services you run. If something doesn't work, add a scoped rule rather than turning the firewall off.

What are firewall profiles (Domain, Private, Public)?

Profiles let the firewall apply different rules depending on the network the adapter is connected to. Domain applies when the server can reach a domain controller, Private for trusted private networks, and Public for untrusted ones. On a domain-joined server the Domain profile is usually active; rules can target specific profiles.

How do I open a port with PowerShell on Windows Server?

Use New-NetFirewallRule with -Direction Inbound, -Action Allow, the protocol, and the local port. For example: New-NetFirewallRule -DisplayName 'Allow HTTPS' -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow. Add -RemoteAddress to limit which sources can connect for tighter security.

How do I restrict a firewall rule to specific source IPs?

Use the -RemoteAddress parameter on New-NetFirewallRule or Set-NetFirewallRule. Pass a single IP, a subnet in CIDR notation like 10.0.50.0/24, a range, or a keyword such as LocalSubnet. Scoping management ports like RDP and WinRM to known admin subnets is one of the highest-value firewall steps you can take.

Does Group Policy override local firewall rules?

Group Policy firewall rules and local rules can both apply, and by default they're merged. You can change rule merging behavior per profile in policy so that GPO rules take precedence and local rules are ignored, which is common in managed environments to keep configuration consistent. Plan whether local rules should be allowed before relying on them.

Sources & further reading

Official vendor documentation referenced while writing this guide.

MG

MCSA Guru Team

IT & Systems Administration

We are working IT pros and system administrators who spend our days in Windows Server, Microsoft 365, and the wider Microsoft stack. MCSA Guru is where we write down the fixes and walkthroughs we wish we had found the first time.

MCSA Guru provides independent, educational IT guidance. Microsoft, Windows, Windows Server, Microsoft 365, Exchange, and Microsoft Teams are trademarks of Microsoft Corporation; Docker is a trademark of Docker, Inc. MCSA Guru is not affiliated with or endorsed by Microsoft or Docker. Always test changes in a safe environment before applying them in production.

Related guides

Fixing something right now?

Jump straight into the guide library or search for the exact error or task you are dealing with.