Windows Defender Firewall is already running on your server, and it does a reasonable job out of the box: unsolicited inbound traffic is blocked unless a rule allows it. The skill lies in opening exactly what your services need, narrowing Remote Desktop to the people who should use it, and doing all of this without locking yourself out. By the end of this guide you will be able to read the current state, create and scope rules with PowerShell, and diagnose traffic that doesn't get through.
If you manage Linux servers too, the ideas are the same as in configuring a firewall on a Linux VPS — only the tools differ.
How Windows Firewall thinks
Profiles. Every network connection belongs to one of three profiles — Domain (joined to an Active Directory domain it can reach), Private (a trusted network) or Public (everything else). A VPS with a public IP is almost always Public. A rule only applies to the profiles it is assigned to, which is a classic source of "the rule is there but nothing happens".
Direction. Inbound rules govern connections others open to your server — visitors, RDP clients. Outbound rules govern connections your server opens — Windows Update, DNS lookups, API calls. Replies to an allowed connection are let through automatically, so you never need a "return" rule.
Precedence. Explicit block rules beat allow rules. If anything matches a block rule, it is dropped, however many allow rules also match.
The default setup — block inbound, allow outbound — is right for most servers. Restricting outbound traffic is possible but requires you to know every connection the server makes; get it wrong and updates quietly stop working.
Check the current state
Get-NetConnectionProfile | Format-Table InterfaceAlias, NetworkCategory
Get-NetFirewallProfile | Format-Table Name, Enabled, DefaultInboundAction, DefaultOutboundAction
NotConfigured for the default actions means Windows defaults apply: inbound blocked, outbound allowed. Enabled : False on any profile is a warning sign — every listening service is then exposed to the internet.
To see which inbound rules are actually active:
Get-NetFirewallRule -Direction Inbound -Enabled True -Action Allow |
Sort-Object DisplayName | Format-Table DisplayName, Profile
The graphical console, Windows Defender Firewall with Advanced Security, opens with wf.msc and shows the same rules.
Before you change anything
Firewall mistakes on a remote server have one painful failure mode: you cut off your own RDP session. Prepare for it.
Open the console for your VPS in a browser tab. It works without the network, so it is your way back in.
Export the current policy so you can restore it:
New-Item -ItemType Directory -Path C:\Backup -Force netsh advfirewall export "C:\Backup\firewall-before.wfw"Change one thing at a time, then open a new RDP connection while the old one stays open. Only close the old session once the new one works.
Warning:
netsh advfirewall importreplaces the entire policy with the file's contents. It is a full restore, not a merge.
Open ports for a service
New-NetFirewallRule creates a rule. A web server needs TCP 80 and 443:
New-NetFirewallRule -DisplayName "Web - HTTP/HTTPS" -Direction Inbound -Protocol TCP -LocalPort 80,443 -Action Allow -Profile Any
Some services need UDP as well, and a TCP rule never opens UDP. A game server listening on both protocols needs two rules:
New-NetFirewallRule -DisplayName "GameServer TCP 27015" -Direction Inbound -Protocol TCP -LocalPort 27015 -Action Allow -Profile Any
New-NetFirewallRule -DisplayName "GameServer UDP 27015" -Direction Inbound -Protocol UDP -LocalPort 27015 -Action Allow -Profile Any
Instead of a port, you can allow a specific program, which is useful when an application picks its port dynamically:
New-NetFirewallRule -DisplayName "MyApp" -Direction Inbound -Program "C:\Program Files\MyApp\myapp.exe" -Action Allow -Profile Any
Rules you no longer need should be switched off or removed, not left lying around:
Disable-NetFirewallRule -DisplayName "GameServer UDP 27015"
Remove-NetFirewallRule -DisplayName "GameServer UDP 27015"
Tip: Use descriptive display names that say what and why, such as SQL – app server only. In a year's time nobody will remember what Rule 7 was for.
Restrict Remote Desktop to your own IP addresses
This is the single most effective firewall change on a Windows server: a connection that is dropped at the firewall never reaches the login screen, so it can't guess passwords.
First find your public IP — the address your office or home connection has on the internet, not your local 192.168.x.x address. Searching "what is my IP" in a browser works. Then:
$rdp = Get-NetFirewallRule -DisplayGroup "Remote Desktop" | Where-Object Direction -eq "Inbound"
$rdp | Format-Table DisplayName, Enabled, Profile
$rdp | Set-NetFirewallRule -RemoteAddress 203.0.113.10, 198.51.100.0/24
$rdp | Get-NetFirewallAddressFilter | Format-Table RemoteAddress
This covers both the TCP and UDP RDP rules. -RemoteAddress accepts single IPs, CIDR ranges like 198.51.100.0/24, ranges like 198.51.100.10-198.51.100.20, and keywords such as LocalSubnet.
Warning:
Set-NetFirewallRule -RemoteAddressreplaces the whole list. If you add a new office later, include every existing address in the same command, or the old ones are removed.
Test with a new RDP session before you close the current one. If your home IP changes often, consider a VPN with a fixed exit address and allow only that.
Allow ping (carefully)
Windows Server ignores ping by default. It's handy for monitoring, so allow it — but only from addresses you trust:
New-NetFirewallRule -DisplayName "ICMPv4 echo - monitoring" -Direction Inbound -Protocol ICMPv4 -IcmpType 8 -RemoteAddress 203.0.113.10 -Action Allow -Profile Any
Log dropped traffic
Logging is off by default. Turn on logging of dropped packets when you need to see what is being blocked:
Set-NetFirewallProfile -Profile Domain,Private,Public -LogBlocked True -LogMaxSizeKilobytes 16384 -LogFileName "%SystemRoot%\System32\LogFiles\Firewall\pfirewall.log"
Get-Content "$env:SystemRoot\System32\LogFiles\Firewall\pfirewall.log" -Tail 20 -Wait
Each line shows the action (DROP or ALLOW), protocol, source and destination address, and ports. A stream of DROP entries on your service's port means the rule is missing, has the wrong protocol, or is scoped too narrowly. -LogAllowed True records accepted traffic too, but the file grows quickly, so only use it while troubleshooting.
Troubleshooting
Locked out of RDP. Log in through the VPS console and widen the rule again ($rdp | Set-NetFirewallRule -RemoteAddress Any), add your new IP, or restore the export with netsh advfirewall import.
Port is open but nothing answers. The firewall may be fine and the service not listening — or listening only on 127.0.0.1. Check from the server, then test from outside:
Get-NetTCPConnection -State Listen -LocalPort 443
Test-NetConnection YOUR_SERVER_IP -Port 443
Rule exists but traffic is dropped. Check the profile (is the rule on Public?), the protocol (TCP vs. UDP), and whether a block rule matches:
Get-NetFirewallRule -Action Block -Enabled True | Format-Table DisplayName, Direction
Firewall and DDoS protection work together
A firewall decides which traffic may reach your services. DDoS filtering deals with how much — floods of packets meant to saturate the line before the firewall even sees them. Neither replaces the other: once a volumetric attack fills your connection, no Windows rule can help, and DDoS filtering does nothing about a single attacker patiently guessing your RDP password. Read what a DDoS attack is for the bigger picture.
In short
Leave the firewall on for all profiles, keep the default block inbound, allow outbound, and open only the ports your services need with clearly named New-NetFirewallRule rules. Scope RDP to your own addresses with -RemoteAddress, remembering that it replaces the list. Export the policy first, keep the console open, and test in a new session. Then continue with protecting Windows Server against unauthorised access or revisit connecting with Remote Desktop.
Firewalls on Hostigan servers
Every Hostigan VPS and dedicated server sits behind always-on upstream DDoS filtering, included on every plan — see how the DDoS protection works. That handles the floods; Windows Firewall on your server remains the place where you decide which ports are open and who may reach them.
Frequently asked questions
Yes. On Windows Server 2022 and 2025 the firewall is on for all profiles, blocking unsolicited inbound traffic and allowing outbound traffic, with exceptions for the roles you install.