Windows Servers

Windows Firewall with Advanced Security: A Practical Server Guide

By NileVPS Team · Published · 4 min read

اقرأ المقال بالعربي

Every Windows Server includes a capable host-based firewall: Windows Defender Firewall with Advanced Security. It filters traffic per profile, per program, per port and per remote address, supports logging, and can be managed entirely from PowerShell. On a Windows VPS that is reachable from the internet, a well-tuned firewall is one of the most effective security controls you have. This guide covers how the firewall evaluates traffic, how to write precise rules, and how to avoid locking yourself out.

Opening the console

Run wf.msc. The left pane shows Inbound Rules, Outbound Rules, Connection Security Rules (IPsec) and Monitoring. The main page shows the state of each profile.

Profiles

ProfileApplies when
DomainThe adapter can reach a domain controller of the joined domain
PrivateThe network is marked private
PublicAny other network; the strictest default

Most VPS network adapters are classified as Public. Check with:

Get-NetConnectionProfile

Write your rules for the profile that is actually active, or for all profiles when appropriate. A rule enabled only for Domain does nothing on a standalone server.

Default behavior and rule evaluation

By default, inbound connections that do not match an allow rule are blocked, and outbound connections are allowed. When several rules match:

  • An explicit block rule wins over an allow rule.
  • Rules are not processed top to bottom like many network firewalls; the order in the list does not matter.
  • Responses to allowed outbound connections are permitted automatically, because the firewall is stateful.

Because block wins, use block rules carefully. To restrict access, it is usually better to narrow an allow rule than to add a broad block.

Creating rules with PowerShell

Allow HTTP and HTTPS inbound:

New-NetFirewallRule -DisplayName "Web HTTP/HTTPS" -Direction Inbound -Protocol TCP -LocalPort 80,443 -Action Allow -Profile Any

Allow a program instead of a port:

New-NetFirewallRule -DisplayName "My App" -Direction Inbound -Program "C:\Apps\myapp\server.exe" -Action Allow

Allow ping (ICMPv4 echo request):

New-NetFirewallRule -DisplayName "Allow ICMPv4 Ping" -Direction Inbound -Protocol ICMPv4 -IcmpType 8 -Action Allow

List, disable or remove rules:

Get-NetFirewallRule -Enabled True -Direction Inbound | Select-Object DisplayName, Profile, Action
Disable-NetFirewallRule -DisplayName "My App"
Remove-NetFirewallRule -DisplayName "My App"

Restricting RDP to trusted IP addresses

Leaving Remote Desktop open to the whole internet invites constant brute-force attempts. Limit the built-in RDP rules to your own addresses:

Set-NetFirewallRule -DisplayGroup "Remote Desktop" -RemoteAddress 203.0.113.10,198.51.100.0/24
Get-NetFirewallRule -DisplayGroup "Remote Desktop" | Get-NetFirewallAddressFilter

Replace the example addresses with your own static IP or office range. If your home IP changes often, combine this with a VPN or a jump host. Before you tighten RDP, make sure you have another way in: on NileVPS the browser console in the control panel works even when RDP is blocked. Our RDP connection guide covers other hardening steps.

Outbound filtering

Switching the default outbound action to block gives strong control over which programs may connect out, but it requires an allow rule for every service, including Windows Update, DNS, time sync and your applications. Test it on a non-production server first:

Set-NetFirewallProfile -Profile Public -DefaultOutboundAction Block

For most single-purpose servers, inbound restrictions plus updates and least privilege give a good balance.

Logging

Logging is off by default. Enable logging of dropped packets to understand what is being blocked:

Set-NetFirewallProfile -Profile Domain,Private,Public -LogBlocked True -LogMaxSizeKilobytes 16384 -LogFileName "%systemroot%\system32\LogFiles\Firewall\pfirewall.log"

The log is a plain text file listing date, action, protocol, source and destination addresses and ports. Logging allowed connections as well (-LogAllowed True) is useful for short investigations but grows quickly.

Backing up and restoring the configuration

Export the complete policy before major changes:

netsh advfirewall export "C:\Backup\firewall.wfw"
netsh advfirewall import "C:\Backup\firewall.wfw"

If everything goes wrong, netsh advfirewall reset restores the default policy, which removes all your custom rules.

Layering with a cloud firewall

A host firewall and a network-level cloud firewall complement each other. The cloud firewall drops unwanted traffic before it reaches the server, while the Windows Firewall gives per-program control and protects you if the cloud rules are misconfigured. NileVPS includes a cloud firewall with its servers; see the plans on our pricing page.

Hardening checklist

  • Confirm which profile your adapter uses.
  • Remove or disable allow rules for services you do not run.
  • Restrict RDP, WinRM and database ports to known IP addresses.
  • Never expose SQL Server (1433) or SMB (445) to the internet.
  • Enable logging of dropped packets.
  • Export the policy after every significant change.
  • Keep a console access method ready before editing remote access rules.

FAQ

Why does my allow rule not work?

The most common causes are the wrong profile, a block rule that matches the same traffic, or the application listening on a different port than expected. Check Get-NetConnectionProfile, search for matching block rules, and confirm the listening port with netstat -ano.

Should I turn off Windows Firewall if I use a cloud firewall?

No. Keep both. The cloud firewall reduces noise at the network edge, and the host firewall provides a second layer and finer control per program and per profile.

How do I recover if I blocked my own RDP access?

Use an out-of-band console, such as the browser console in your VPS control panel, to log in locally. Then fix or remove the rule with Set-NetFirewallRule or restore your exported policy.

Related guides