Windows Firewall: opening what's needed
How to open a port for your service, restrict access by address, and verify that the rule actually works without losing access to the server.
Updated August 23, 2026
On a VDS with Windows Server, the firewall is the only filter between your services and the internet: the IPv4 address is public, and there is no external shield in front of the machine. So the rule is simple: only what you deliberately opened is exposed to the outside.
What is open now
Get-NetFirewallProfile | Select-Object Name, Enabled, DefaultInboundAction
Get-NetFirewallRule -Enabled True -Direction Inbound |
Where-Object Action -eq Allow |
Get-NetFirewallPortFilter | Select-Object Protocol, LocalPort -Unique
Get-NetTCPConnection -State Listen | Select-Object LocalAddress, LocalPort, OwningProcess
The last command shows which ports are listening at all. A service listening only on 127.0.0.1 is not accessible from the outside regardless of the rules.
Open a port
Web server:
New-NetFirewallRule -DisplayName "HTTP" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow
New-NetFirewallRule -DisplayName "HTTPS" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
Your own service only for trusted addresses:
New-NetFirewallRule -DisplayName "App 8080" -Direction Inbound -Protocol TCP -LocalPort 8080 `
-RemoteAddress 203.0.113.5,198.51.100.0/24 -Action Allow
A rule for a specific program instead of a port is more reliable if the application uses dynamic ports:
New-NetFirewallRule -DisplayName "MyApp" -Direction Inbound -Program "C:\apps\myapp.exe" -Action Allow
Delete and view a rule:
Remove-NetFirewallRule -DisplayName "App 8080"
Get-NetFirewallRule -DisplayName "App 8080" | Format-List
What to keep closed
Never expose to the outside without restricting by addresses:
| Port | Service | Why |
|---|---|---|
| 3389 | RDP | password brute-forcing starts within the first hours, see RDP protection |
| 1433 | MS SQL | the database should not be accessible from the internet, see MS SQL Server |
| 5985, 5986 | WinRM | remote management, only from your own addresses |
| 445 | SMB | a classic target for mass attacks |
If you need to access the database from your computer, do not open 1433; instead, forward the port inside an RDP session or set up a VPN.
Verification
A port listening from inside the machine does not mean it is accessible from the outside. Check from another host:
nc -vz YOUR_ADDRESS 443
curl -I http://YOUR_ADDRESS
If it is closed from the outside but Get-NetTCPConnection shows a listener, the issue is in the rule or the network profile: make sure the rule is created in the profile that is active (usually “Public network”).
Common mistakes
- Disabling the firewall entirely “for debugging”. The machine will be found before you finish. Instead, create a temporary rule with an address restriction.
- Opening a port but forgetting about the application. Many services listen only on localhost by default; the rule has nothing to do with it.
- Locking yourself out of RDP. After that, log in via the “Console” tab in the control panel
/hosting/vds/m/<id>, “Screen” mode, and edit the rule from there. - Creating an allow rule on top of a deny rule. In Windows, a deny always wins over an allow — look for a blocking rule with the same port.
After each change, it is useful to save a snapshot of the configuration:
Get-NetFirewallRule -Enabled True | Export-Csv C:\fw.csv. That way you will understand what changed when a service suddenly stops responding.