How to Close Ports in Windows 10
In this article
To close a port in Windows 10, you need to either stop the program that's listening on it, block it with Windows Defender Firewall, or disable the service using it. The quickest method is to identify the process using the port and end it, but for a permanent solution, create a firewall rule to block inbound traffic. Below are step-by-step instructions for both approaches.
What You'll Need
- Administrator access to your Windows 10 PC (you'll need to confirm UAC prompts).
- Knowledge of the port number you want to close (e.g., 8080, 3389).
- Optional: A list of programs you want to keep running—closing a port may disrupt them.
Step-by-Step
Method 1: Find and Stop the Process Using the Port
- Press Windows + R, type
cmd, and press Ctrl + Shift + Enter to open Command Prompt as administrator. - Type
netstat -ano | findstr :[port](replace[port]with your port number, e.g.,8080) and press Enter. Note the PID (Process ID) listed in the last column. - Open Task Manager by pressing Ctrl + Shift + Esc. Go to the Details tab, find the PID you noted, and note the program name.
- If you're sure you want to close the port, right-click that process and select End Task. This will stop the program and free the port, but it will reopen if the program restarts.
Method 2: Block a Port with Windows Defender Firewall
- Press Windows + R, type
wf.msc, and press Enter to open Windows Defender Firewall with Advanced Security. - Click Inbound Rules in the left pane.
- Click New Rule... in the right pane.
- Select Port and click Next.
- Choose TCP or UDP (or both by creating two rules) and enter the specific port number. Click Next.
- Select Block the connection and click Next.
- Check all three profiles (Domain, Private, Public) and click Next.
- Give the rule a name (e.g., "Block Port 8080") and click Finish.
- The port is now blocked for inbound traffic. To undo, right-click the rule and select Disable Rule or Delete.
Method 3: Disable the Service That Uses the Port
- Follow Method 1 steps 1-2 to find the PID and the program name.
- Press Windows + R, type
services.msc, and press Enter. - Look for the service associated with the program (you may need to check the program's documentation). Right-click it and select Properties.
- Set Startup type to Disabled and click Stop to stop it immediately. Click OK.
- This prevents the service from starting again, keeping the port closed.
Common Mistakes
- Blocking the wrong protocol: A port can be used by TCP or UDP; if you block only TCP, UDP traffic still passes. Create rules for both if needed.
- Ending a critical system process: Some processes (like svchost.exe) manage multiple services. Ending them can cause system instability. Always check the program name before ending.
- Not running as administrator: Without admin rights, netstat may not show all PIDs, and firewall rules cannot be created.
- Forgetting the firewall rule applies to all profiles: If you only select "Public", the port may still be open on a private network.
Tips
- Use
netstat -ano | findstr LISTENINGto see all listening ports and their PIDs at once. - For a temporary close, ending the process is fastest, but the port will reopen on reboot if the program auto-starts.
- If you're closing a port for security reasons, consider also checking for malware—some trojans open ports without your knowledge.
- Keep a note of which ports you've blocked so you can easily unblock them later.
Troubleshooting
If the port is still open after following the steps:
- Verify the rule is enabled: In Windows Defender Firewall, check that your rule has a green checkmark. If it's grayed out, right-click and select Enable Rule.
- Check if another program is using the same port: Run
netstat -ano | findstr [port]again. If a different PID appears, you may have blocked the wrong program. - If you're testing from another device, ensure the firewall profile is set correctly (Private vs Public) and that the remote device is on the same network type.
- Restart your PC after creating the rule—some services cache port bindings.
If you can't create a firewall rule:
- Make sure you're logged in with an administrator account. If not, right-click the Command Prompt and select "Run as administrator" before launching
wf.msc. - Check if Group Policy is overriding your rules—run
gpupdate /forcein admin Command Prompt and try again.
Frequently Asked Questions
How do I close a port in Windows 10 using Command Prompt?
You can't directly close a port with Command Prompt, but you can find the PID and kill the process using taskkill /PID [pid] /F. For a permanent block, use the firewall method.
What is the difference between blocking a port and closing a port?
Blocking a port (via firewall) prevents external connections, but the program still runs and listens. Closing a port means stopping the program or service entirely, so the port is no longer open.
Can I close all ports at once?
Yes, you can create a firewall rule to block all inbound traffic, but that would also block internet access. Instead, block specific ports as needed.
Will closing a port affect my internet speed?
No, closing a specific port only affects traffic to that port. Your general internet speed remains unaffected.
How do I know which ports are open on my Windows 10?
Run netstat -ano in Command Prompt to see all active connections and listening ports. Look for the "LISTENING" state.
Is it safe to close port 3389 (Remote Desktop)?
If you don't use Remote Desktop, closing it improves security. If you need it, leave it open or restrict it to specific IPs using firewall rules.