How to open a port in Windows Firewall
Windows Firewall blocks incoming connections to your server unless a rule allows them. When you run a program that others connect to, such as a game server, a web application, a trading bridge or a database, you have to open its port. Remote Desktop (port 3389) is already allowed on PreVPS Windows servers.
Before you start
- Look up the port number and the protocol (TCP or UDP) in the documentation of the program. Some programs need both.
- Open only the ports you need. For a database (for example SQL Server on 1433 or MySQL on 3306), allow only the IP addresses that must connect: database ports open to the whole internet receive constant attacks.
- The steps below work on Windows Server 2016, 2019, 2022 and 2025, and on Windows 10 and 11.
Method 1: PowerShell (quickest)
Right-click Start, open Windows PowerShell (Admin) or Terminal (Admin) and run the command below. Replace 8080 with your port and the name with one you will recognise later.
New-NetFirewallRule -DisplayName "My app TCP 8080" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow
- For a UDP port, use
-Protocol UDP. For several ports, list them:-LocalPort 27015,27016, or give a range:-LocalPort 7000-7010. - To allow only one IP address (or several, separated by commas), add
-RemoteAddress 203.0.113.10.
The rule applies to all network profiles. To check it, or to delete it later:
Get-NetFirewallRule -DisplayName "My app TCP 8080" | Format-List DisplayName,Enabled,Profile,Action
Remove-NetFirewallRule -DisplayName "My app TCP 8080"
Method 2: Windows Defender Firewall with Advanced Security
- Press Win + R, type
wf.mscand press Enter. - In the left pane, click Inbound Rules, then click New Rule in the right pane.
- Choose Port and click Next.
- Choose TCP or UDP, select Specific local ports, type the port (for example
8080,27015,27016or7000-7010) and click Next. - Choose Allow the connection and click Next.
- Keep Domain, Private and Public ticked and click Next. The network of a server is usually the Public profile, so a rule without Public has no effect.
- Enter a name, for example My app TCP 8080, and click Finish.
To allow only certain IP addresses, double-click the new rule, open the Scope tab, choose These IP addresses under Remote IP address, add the addresses and click OK.
Test the port
- On the server, check that the program is running and listening on the port:
Get-NetTCPConnection -State Listen -LocalPort 8080. If nothing is listed, start the program first. If the local address is127.0.0.1, the program only accepts connections from the server itself: change its listen or bind address in its settings to0.0.0.0or to the IP address of the server. - On your own Windows computer, run
Test-NetConnection 198.51.100.20 -Port 8080in PowerShell, with the IP address of your server. TcpTestSucceeded : True means the port is open. This test only works for TCP ports; test a UDP port with the program itself.
Still closed?
- If you use a firewall for this server in the PreVPS Client Area, allow the same port and protocol there too.
- Check that no other rule blocks the port: in
wf.msc, a Block rule wins over an Allow rule. - Some programs have their own firewall setting or need a second port. Check their documentation.
- Contact us with the port, the protocol and the result of the test above.
Need a Windows server? PreVPS offers dedicated Windows servers with Windows preinstalled, and Windows VPS plans with Windows Server 2025, 2022 or 2019 preinstalled at no extra charge (you bring the licence key).