Windows Server Firewall allows you to control network traffic by creating rules for specific ports, protocols, and IP addresses. Blocking a port can help prevent unauthorized connections, restrict access to unused services, or stop unwanted network traffic.
To block a port in Windows Defender Firewall, you need to create a new inbound or outbound rule, specify the port and protocol, and select Block the connection as the action. The process is almost identical across older and newer versions of Windows Server.
In this guide, we’ll cover both methods of blocking ports on Windows, including using the Windows GUI and running commands in Windows PowerShell. We will also cover how you can disable and remove blocked ports on your Windows VPS.
If you are using Windows VPS you blocking unused ports and services can help you make you server much more secure. If you don’t have a Windows VPS yet, you can get a Windows VPS from VPSmakers and configure the firewall on a real online server.

Get Windows VPS server hosting with full Administrator access, SSD/NVMe storage and fast setup for Windows Server applications and business workloads.
Buy Windows VPSNote:
All steps and methods in this guide have been tested and verified by the VPSMakers technical team on Windows 10 and Windows Server 2019 running on a Windows VPS. Whether you’re using a client or server edition of Windows, locally or on a VPS Server, you can follow these steps to block access to specific ports.
Before blocking a port on a Windows VPS Server
Before blocking a port, it’s good to identify which process or service is using it. Blocking an active port without checking its purpose can interrupt running applications, services, or network connections.
If you find a process using the port that you no longer need, you can terminate it to free up the port and block the desired port. learn this action, you can follow our guide for it:

When working with Windows, multiple applications or services may attempt to use the same network port. However, a specific IP address and port combination cannot generally be shared by multiple…
Read the full articleOr, if you want to prevent direct access through its current port, you may consider using port forwarding to redirect incoming connections to another port. To do this, you can follow this guide:

Port forwarding on Windows involves two steps: creating a new firewall rule for the port and configuring port forwarding using CMD.
Read the full articleBlock a Port Using Windows Defender Firewall (GUI)
You can block a specific port in Windows using Windows Defender Firewall with Advanced Security. It allows you to create the required rules to control traffic.
Open Windows Defender Firewall With Advanced Security
After logging in to Windows, press Win + R to open Run and enter wf.msc, and press Enter to launch Windows Defender Firewall with Advanced Security, or you can also search for it in the Start menu.

Block Inbound Connections
Once you’ve opened Windows Defender, you’ll find a menu on the left side; select either Inbound Rules or Outbound Rules depending on your needs.
- Inbound Rule: Controls incoming network traffic from other devices to your Windows computer or server.
- Outbound Rule: Controls outgoing network traffic from your Windows computer to other devices.
In this example, we’ll use an inbound rule to block incoming connections on a specific port.
On the left sidebar, select Inbound Rules, then on the right side of the page, click on “New Rule …” to create a rule.

Select Rule Type
On the first page of the New Inbound Rule Wizard, select the type of rule you want to create. Windows Firewall provides four options: Program, Port, Predefined, and Custom. Each option lets you control network traffic based on different criteria. Since our goal is to block a specific port, select Port and click Next.

- Program: Rule to allow or block traffic for a specific app or executable file.
- Port: Rule to control traffic based on a specific UDP or TCP port.
- Predefined: Rule based on predefined Windows services and features.
- Custom: Allows you to create a rule with more specific conditions, such as program, port, IP address, and protocol.
Select Protocol and Port to Block
In this step, select the protocol and port you want to block. You can choose either TCP or UDP, depending on the type of traffic you want to filter. Windows Firewall does not allow you to select both protocols in a single port rule. If you want to block the same port for both protocols, you’ll need to create two separate rules: one for TCP and another for UDP.

In the Specific local ports field listed below the Protocol and Ports page, enter the ports you want to block. Then click Next. You can add multiple ports by separating them with ,.
Specify the Firewall Rule Action in Windows
On the action page, select “Block the Connection” to drop every connection matching your selected port and protocol.

Specify Network Profile to apply rule to
On the Profile page, a screen will appear asking which types of networks you wish to apply the rule to. Here, it’s better to keep all checked and click the Next button, but if you want, you can uncheck the ones you don’t want.

- Domain: Applies the rule when your computer is connected to a network managed by an organization, such as a company domain.
- Private: Applies the rule when connected to a trusted private network, such as your home or office network.
- Public: Applies the rule when connected to an untrusted public network, such as Wi-Fi in a café, airport, or hotel.
Specify Name and Description for Rule
Name your new rule and optionally include a brief description in the next field, so you can remember what it is for. Finally, click Finish to save your new rule.

As a result, the new rule is activated now, and your preferred port is disabled.
Note:
Creating a rule to block outgoing traffic follows the same process. The only difference is that instead of creating the rule under Inbound Rules, you should select Outbound Rules and follow the same steps.
Block a Port Using PowerShell
You can also block ports in Windows using PowerShell without opening the Windows Defender Firewall graphical interface. PowerShell allows you to create and manage firewall rules with a few commands using the new-NetFirewallRule command.
First, open PowerShell as Administrator by searching for PowerShell in the Start menu, right-clicking it, and selecting Run as administrator.
Create a Firewall Rule to Block a Port with PowerShell
Use the New-NetFirewallRule command to create a new firewall rule. You need to specify the rule name, direction, protocol, local port, and action.
The following command blocks incoming TCP connections on port 8080 . You can replace the values with your own ones and run the command.
New-NetFirewallRule -DisplayName "Block TCP Port 8080" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action BlockYou can customize the command with your desired values using the parameter descriptions in the table below.
| Parameter | Description | Available values / Example |
|---|---|---|
-DisplayName | Sets a name to identify the firewall rule. | “Block TCP Port 8080” |
-Direction | Specifies the direction of network traffic to filter. | Inbound or Outbound |
-Protocol | Specifies the network protocol to filter. | TCP, UDP, or a protocol number |
-LocalPort | Specifies the local port number to match. | 8080, 80, 443, or a port range such as 8000-8010 |
-RemotePort | Specifies the remote port number to match. Mainly useful for outbound rules. | 8080, 443, or a port range |
-Action | Defines what Windows Firewall does with matching traffic. | Block or Allow |
Note:
If you want to block both TCP and UDP traffic on the same port, you need to create a separate firewall rule for each protocol.
Verify the Firewall Rule
After creating the rule, you can check whether it was added successfully using the Get-NetFirewallRule command:
Get-NetFirewallRule -DisplayName "Block TCP Port 8080"Name : {16a54c80-3058-4981-8155-7ac3a2cd3ac7}
DisplayName : Block TCP Port 8080
Description :
DisplayGroup :
Group :
Enabled : True
Profile : Any
Platform : {}
Direction : Inbound
Action : Block
EdgeTraversalPolicy : Block
LooseSourceMapping : False
LocalOnlyMapping : False
Owner :
PrimaryStatus : OK
Status : The rule was parsed successfully from the store. (65536)
EnforcementStatus : NotApplicable
PolicyStoreSource : PersistentStore
PolicyStoreSourceType : Local
RemoteDynamicKeywordAddresses :
PolicyAppId :How to Unblock a Port in Windows Server Firewall
If you no longer need to block a port, you can disable or remove the firewall rule you previously created. You can do it using PowerShell and Windows Defender Firewall.
Disable or Remove a Firewall Rule Using Windows Defender Firewall
To unblock a port using the graphical interface, open Windows Defender Firewall with Advanced Security and locate the rule you created under Inbound Rules or Outbound Rules, depending on its direction.
Right-click the rule and select Disable Rule to temporarily disable it or Delete to permanently remove it from the firewall configuration.
Disabling a rule keeps it available so you can enable it again later, while deleting it removes the rule entirely.
Disable or Remove a Firewall Rule Using PowerShell
You can also disable or remove an existing firewall rule using PowerShell without opening the graphical interface.
To temporarily disable the rule, use the Disable-NetFirewallRule cmdlet:
Disable-NetFirewallRule -DisplayName "Block TCP Port 8080"To permanently remove the rule, use the Remove-NetFirewallRule cmdlet. Replace “Block TCP Port 8080” with the display name of the firewall rule you want to manage.
Remove-NetFirewallRule -DisplayName "Block TCP Port 8080"Note:
Disabling a firewall rule allows matching traffic again if no other firewall rules block it. Removing a rule has the same effect but permanently deletes that rule from your firewall configuration.
To learn about opening a port in Windows in detail, you can follow this guide:

Conclusion
Blocking a port in Windows is straightforward using Windows Defender Firewall. You can create inbound or outbound rules through the graphical interface or use PowerShell commands to control network traffic.
Whether you want to restrict incoming connections, block outgoing traffic, or prevent access to a specific port, Windows Firewall gives you the flexibility to manage these connections based on your needs.
In this guide, we’ve discussed both graphical and command-line methods; choosing between them totally depends on your preference, but for server administration and automation, using PowerShell can be better and a time saver.

