Blocking a network port in Windows Firewall limits unsolicited traffic and reduces exposure to scans, worms, and opportunistic attacks. Port blocks are commonly used to harden servers, lock down shared workstations, and prevent accidental service publishing on untrusted networks.
Windows Defender Firewall enforces policy using inbound and outbound rules that match protocol, ports, programs, services, and network profiles. A port-based rule is evaluated by the filtering platform before traffic reaches an application, so the block can apply even when the listening service remains running.
Creating or changing rules requires administrative privileges and the selected Domain, Private, and Public profiles control where the block is active. Blocking ports used for remote administration (for example 3389 for RDP or 22 for SSH) can immediately disrupt access, so confirm an alternate management path before applying a block. A port rule filters network traffic but does not stop the local process from listening on the port.
Run wf.msc from the Run dialog to open the same console directly.
Inbound Rules block traffic arriving at the computer; use Outbound Rules to restrict traffic leaving the computer.
TCP covers connection-oriented traffic (for example HTTP), while UDP covers connectionless traffic (for example DNS).
Comma-separated lists (80,443,8080) and ranges (5000-5010) are supported.
Blocking management ports such as 3389 (RDP) can immediately disconnect remote sessions.
Public typically applies on untrusted networks; Domain and Private are common for internal networks.
Including direction, protocol, and port (example: Block inbound TCP 80) keeps rule lists readable.
PS C:\> Test-NetConnection -ComputerName 192.0.2.10 -Port 80 ComputerName : 192.0.2.10 RemoteAddress : 192.0.2.10 RemotePort : 80 InterfaceAlias : Ethernet SourceAddress : 192.0.2.25 PingSucceeded : True TcpTestSucceeded : False
Ensure the target port is listening during the test; Test-NetConnection validates TCP ports, while UDP verification is typically application-specific.