How to open a port in Windows Firewall on a VPS
To open a port on a Windows VPS, everything happens in the Windows Server firewall itself, Windows Defender Firewall: the OuiHeberg client area has no network firewall for VPS. This guide shows how to check the firewall, open a port with the GUI or in PowerShell, limit Remote Desktop to your address and read the logs. Run the commands in PowerShell as administrator, in an RDP session.
Check the Windows Server firewall status
Windows applies one of its three profiles depending on the network. On a VPS, it is usually the Public profile.
| Profile | When it applies |
|---|---|
| Domain | Machine joined to an Active Directory domain |
| Private | Network marked as trusted |
| Public | Unknown network, which is the case of a VPS facing the Internet |
Show the status of the three profiles and their default action.
Get-NetFirewallProfile | Select Name, Enabled, DefaultInboundAction, DefaultOutboundAction
Each profile should show Enabled set to True. If one is False, turn the firewall back on for all three.
Set-NetFirewallProfile -Profile Domain,Private,Public -Enabled True
The right starting point is to block all inbound traffic except what you allow, and to let outbound traffic through.
Set-NetFirewallProfile -Profile Domain,Private,Public `
-DefaultInboundAction Block `
-DefaultOutboundAction Allow
Windows labels are quoted in English, the language of the delivered system. The firewall console opens with wf.msc. Its home page sums up the three profiles and shows which one is active.

Open a port with the GUI
Press the Windows key, type
wf.mscand press Enter.Right-click Inbound Rules, then click New Rule….
At the Rule Type step, choose Port, then click Next.
Choose TCP or UDP and enter the port in Specific local ports, for example
443.Keep Allow the connection.
Leave the three profiles ticked.
Give the rule a clear name, for example
Allow-HTTPS-443-Inbound, then click Finish.
The rule applies right away, with no restart.

The Rule Type step offers four kinds of rule.
| Type | Use |
|---|---|
| Program | Allow or block an executable (.exe) |
| Port | Open or block a TCP or UDP port |
| Predefined | Turn on a group of rules provided by Windows (Remote Desktop, file sharing…) |
| Custom | Combine port, program and source or destination IP addresses |
An outbound rule is created the same way from Outbound Rules. It is mainly used to stop a program or the server from reaching a given address or port.

Open a port in PowerShell
PowerShell is faster and can be replayed as is on another server. One line is enough to open a TCP port. Replace 8080 with yours.
New-NetFirewallRule -DisplayName "Allow-Port-8080" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow -Profile Any
For an outbound rule, replace Inbound with Outbound. To block, replace Allow with Block. Here is the same command over several lines, for web ports 80 and 443.
New-NetFirewallRule `
-DisplayName "Allow-HTTP-HTTPS-Inbound" `
-Direction Inbound `
-Protocol TCP `
-LocalPort @(80, 443) `
-Action Allow `
-Profile Any
Limit a port to certain addresses
An admin service or a database should not be open to the whole Internet. The -RemoteAddress parameter restricts the rule to one address or range. Here, SQL Server (port 1433) is limited to a subnet, then WinRM (5985 and 5986) to one admin address.
# SQL Server, from one subnet only
New-NetFirewallRule `
-DisplayName "Allow-SQLServer-LAN" `
-Direction Inbound `
-Protocol TCP `
-LocalPort 1433 `
-RemoteAddress "10.0.0.0/24" `
-Action Allow `
-Profile Any
# WinRM HTTP (5985) and HTTPS (5986), from one address only
New-NetFirewallRule `
-DisplayName "Allow-WinRM-Management" `
-Direction Inbound `
-Protocol TCP `
-LocalPort @(5985, 5986) `
-RemoteAddress "203.0.113.10" `
-Action Allow `
-Profile Any
To link your VPS to each other without going through the Internet, the guide How to connect two VPS over a private network explains how to turn on the private network.
Restrict Remote Desktop to your IP address
Bots scan port 3389 all the time. If your connection has a fixed address, keep Remote Desktop for it alone.
Create a rule that allows port 3389 from your address. Replace
203.0.113.10with yours.New-NetFirewallRule ` -DisplayName "Allow-RDP-MyIP" ` -Direction Inbound ` -Protocol TCP ` -LocalPort 3389 ` -RemoteAddress "203.0.113.10" ` -Action Allow ` -Profile AnyOpen a second RDP session to check that you can still get in. Keep the first one open.
Turn off the original Remote Desktop rules, which accept every address.
Disable-NetFirewallRule -DisplayGroup "Remote Desktop"
Since inbound traffic is blocked by default, only your address gets through now.
Do not create a
Blockrule on port 3389. In Windows, a block rule wins over an allow rule, so it would cut off your address too. If you lose access, open the console from the VPS page in the client area and fix the rule.
If your address changes often, go through a VPN and allow its range. To change the Remote Desktop port, follow Change the RDP port on a Windows Server VPS.
Block a port or an IP address
# Block an inbound port
New-NetFirewallRule `
-DisplayName "Block-Port-8080-Inbound" `
-Direction Inbound `
-Protocol TCP `
-LocalPort 8080 `
-Action Block `
-Profile Any
# Block a source address (inbound)
New-NetFirewallRule `
-DisplayName "Block-IP-Suspect" `
-Direction Inbound `
-RemoteAddress "198.51.100.42" `
-Action Block `
-Profile Any
# Block outbound connections to an address
New-NetFirewallRule `
-DisplayName "Block-Outbound-IP" `
-Direction Outbound `
-RemoteAddress "198.51.100.42" `
-Action Block `
-Profile Any
A block rule takes precedence over every allow rule that targets the same traffic.
Turn on predefined Windows rules
Windows Server comes with ready-made groups of rules. Turn them on by group rather than one by one.
| Group | Use |
|---|---|
| Remote Desktop | Remote Desktop connections |
| File and Printer Sharing | SMB file sharing |
| Windows Management Instrumentation (WMI) | Remote WMI management |
| Windows Remote Management | PowerShell remoting (WinRM) |
| Core Networking | Basic network traffic (DNS, DHCP, ICMP) |
| Network Discovery | Network discovery |
Use netsh or PowerShell, whichever you prefer.
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes
netsh advfirewall firewall set rule group="Windows Remote Management" new enable=Yes
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
Enable-NetFirewallRule -DisplayGroup "Windows Remote Management"
To allow ping, the guide How to allow ping through Windows Firewall on a VPS covers the ICMP rules.
Log blocked traffic
The firewall log shows which connection was refused and reveals port scans. Turn it on for all three profiles.
Set-NetFirewallProfile -Profile Domain,Private,Public `
-LogFileName "%SystemRoot%\System32\LogFiles\Firewall\pfirewall.log" `
-LogMaxSizeKilobytes 4096 `
-LogAllowed True `
-LogBlocked True
The same setting can be made with netsh.
netsh advfirewall set allprofiles logging filename "%SystemRoot%\System32\LogFiles\Firewall\pfirewall.log"
netsh advfirewall set allprofiles logging maxfilesize 4096
netsh advfirewall set allprofiles logging droppedconnections enable
netsh advfirewall set allprofiles logging allowedconnections enable
The log is in C:\Windows\System32\LogFiles\Firewall\pfirewall.log. Here are its useful columns.
| Column | Content |
|---|---|
| date, time | Date and time of the event |
| action | ALLOW or DROP |
| src-ip, dst-ip | Source and destination addresses |
| src-port, dst-port | Source and destination ports |
| path | RECEIVE for inbound, SEND for outbound |
This command shows the last 50 blocked connections.
Get-Content "C:\Windows\System32\LogFiles\Firewall\pfirewall.log" |
Where-Object { $_ -match "DROP" } |
Select-Object -Last 50
Manage and back up rules
List the active rules, sorted by direction.
Get-NetFirewallRule | Where-Object { $_.Enabled -eq "True" } |
Select-Object DisplayName, Direction, Action, Profile |
Sort-Object Direction
The same inventory can show the protocol and port of each rule.
Get-NetFirewallRule | Where-Object { $_.Enabled -eq "True" } |
ForEach-Object {
$rule = $_
$portFilter = $rule | Get-NetFirewallPortFilter
[PSCustomObject]@{
Name = $rule.DisplayName
Direction = $rule.Direction
Action = $rule.Action
Protocol = $portFilter.Protocol
LocalPort = $portFilter.LocalPort
}
} | Format-Table -AutoSize
Turn a rule off rather than deleting it, so you can turn it back on.
# Turn off
Disable-NetFirewallRule -DisplayName "Allow-Port-8080"
# Turn back on
Enable-NetFirewallRule -DisplayName "Allow-Port-8080"
# Delete for good
Remove-NetFirewallRule -DisplayName "Allow-Port-8080"
Export all rules before a major change. Importing restores the exported configuration.
netsh advfirewall export "C:\Backup\firewall-backup.wfw"
netsh advfirewall import "C:\Backup\firewall-backup.wfw"
To keep a monthly record of the active rules, export them to CSV.
Get-NetFirewallRule | Where-Object { $_.Enabled -eq "True" } |
Export-Csv "C:\Audit\firewall-rules-$(Get-Date -Format 'yyyy-MM').csv" -NoTypeInformation
Troubleshoot a refused connection
The rule exists and is enabled, but the connection fails? Check these points in order.
Is the service listening on the port?
# On the server: is a program listening on port 443?
Get-NetTCPConnection -LocalPort 443 -State Listen
Test-NetConnection -ComputerName localhost -Port 443
# From your Windows computer (replace the address with the VPS one)
Test-NetConnection -ComputerName 203.0.113.50 -Port 443 -InformationLevel Detailed
If TcpTestSucceeded is True on the server and False from your computer, the firewall is blocking. If it is False on the server too, the service is not listening and the problem lies with the application.
Is a block rule taking precedence?
A broader Block rule wins over your Allow rule. List the active block rules.
Get-NetFirewallRule -Direction Inbound -Action Block -Enabled True |
Select-Object DisplayName, Profile
Does the rule target the right profile?
A rule created for the Private profile does not apply if the VPS is on the Public profile. Show the active profile and the interface name.
Get-NetConnectionProfile | Select-Object Name, InterfaceAlias, NetworkCategory
The simplest fix is to extend the rule to every profile. Switching the interface to the Private profile also works, but applies all the rules of that profile to it.
# Extend the rule to every profile
Set-NetFirewallRule -DisplayName "Allow-Port-8080" -Profile Any
# Or switch the interface to the Private profile (name read from InterfaceAlias)
Set-NetConnectionProfile -InterfaceAlias "Ethernet" -NetworkCategory Private
What does the log say?
# Blocked connections on port 8080
Get-Content "C:\Windows\System32\LogFiles\Firewall\pfirewall.log" |
Where-Object { $_ -match "DROP" -and $_ -match "8080" }
The path column confirms the direction of the block, inbound or outbound.
Need help?
Open a ticket from Tickets › Open a Ticket, or from the Contact support tile at the bottom of the VPS page. In the Related Service field, pick the VPS so the team saves time. You can also ask your question on the OuiHeberg Discord.
Windows Server 2025 with the license included, Remote Desktop access and management from the client area.
View plans →