Opening Firewall Ports on Windows 11
Windows 11 features the Microsoft Defender Firewall, a crucial built-in security layer that regulates network traffic and safeguards your device against unauthorized connections and malicious applications. It acts as a vigilant gatekeeper, scrutinizing all incoming and outgoing network requests. When an application requests network access, the firewall evaluates its established rules to decide if the connection should be permitted or blocked. If no rule exists for the app, Windows 11 prompts you to manually authorize or deny the connection.
Occasionally, trusted applications, such as SQL Server, might not operate as intended if blocked by the firewall. In such instances, it becomes necessary to establish an inbound or outbound rule to ensure these applications can communicate effectively.
Guideline Overview
This guide will walk you through the process of opening a port to enable an application to communicate through the Windows 11 firewall.
How to Open a Firewall Port on Windows 11
You can set up an inbound or outbound rule using the Windows Defender Firewall through the Advanced Security console, Command Prompt, or PowerShell depending on your needs.
Setting Up a Firewall Rule via Advanced Security
Follow these detailed steps to open ports in the Windows firewall:
-
Launch Windows Security.
-
Select Firewall & network protection.
-
Click on Advanced settings.
-
Select Inbound Rules for rules that allow incoming traffic.
-
Select Outbound Rules for rules allowing app traffic to exit.
-
Click New Rule from the right pane under the “Actions” section.
-
Select the Port option.
-
Click Next.
-
Choose the appropriate protocol, either
TCPorUDP, based on the application requirement. -
Enter the port number in the “Specific local ports” field.
Quick note: For applications requiring multiple open ports, list them separated by commas (e.g., 4500, 4600, 5000).Use a hyphen for a port range (e.g., 3000-3100). -
Click Next.
-
Select the option “Allow the connection”. Note: You could also choose to block the connection if needed.
-
Click Next.
-
Select the network type to which this rule will apply.(Default selections usually suffice.)
-
Click Next.
-
Provide a descriptive name for this rule, such as “My Inbound Rule for APP-NAME.”
-
Click Finish.
Upon completion, inbound connections through the specified port will be permitted for the application.
Creating a Firewall Rule Using Command Prompt
To open a firewall port using Command Prompt, do the following:
-
Open Start.
-
Search for Command Prompt (or Terminal), right-click the top result, and select Run as administrator.
-
Input the following command for an incoming rule and press Enter:
netsh advfirewall firewall add rule name="YOUR-APP-PORT"dir=in action=allow protocol=TCP localport=12345Ensure to modify the rule name, protocol (TCP or UDP), and port number accordingly. Remember, each command must be run for one port at a time.
-
To permit a range of ports, enter this command and press Enter:
netsh advfirewall firewall add rule name="YOUR-PORT-RANGE-NAME"dir=in action=allow protocol=TCP localport=2000-2200Update the rule name, protocol, and specify the port numbers as required.
After executing these commands, the designated ports will be opened on Windows 11.
For establishing multiple in or out rules with various ports, utilize a batch loop command, such as:
for %%P in (80 443 8080) do netsh advfirewall firewall add rule name="Allow TCP %%P"dir=in action=allow protocol=TCP localport=%%P
Remember to adjust the ports, the direction (in or out), and the protocol (TCP or UDP) as needed.
Creating a Firewall Rule Using PowerShell
To configure a firewall port via PowerShell, follow these steps:
-
Open Start.
-
Search for PowerShell (or Terminal), right-click the top result, and select Run as administrator.
-
Run the following command to create an inbound firewall rule:
New-NetFirewallRule -DisplayName "YOUR-APP-PORT"-Direction Inbound -Action Allow -Protocol TCP -LocalPort 12345Modify the command according to your rule name, direction (Inbound or Outbound), protocol (TCP or UDP), and local port specifications.
-
To open a range of ports, input the following command:
New-NetFirewallRule -DisplayName "YOUR-PORT-RANGE-NAME"-Direction Inbound -Action Allow -Protocol TCP -LocalPort 4000-4010Ensure to adjust parameters just like previously instructed.
Executing these commands will integrate the specified inbound or outbound rule into the Microsoft Defender Firewall.
For rules involving multiple ports, consider using a foreach loop, such as:
$ports = @(80, 443, 8080)
foreach ($port in $ports) { New-NetFirewallRule -DisplayName “Allow TCP $port”-Direction Inbound -Action Allow -Protocol TCP -LocalPort $port }
Ensure all parameters are updated correctly.
Closing a Firewall Port on Windows 11
You may also need to close a port by removing a specific rule, achievable via the Advanced Security console, Command Prompt, or PowerShell.
Removing a Firewall Rule via Advanced Security
Follow these instructions to delete a port in the Microsoft Defender Firewall:
-
Open Windows Security.
-
Select Firewall & network protection.
-
Access Advanced settings.
-
Click on the relevant Inbound Rules or Outbound Rules from the left pane, based on where the port was opened.
-
Select the desired rule.
-
Choose either Disable Rule to close the port while retaining the rule or select Delete Rule to remove the rule entirely.
Upon completing these steps, the application or service will be blocked from accessing either the network or the internet as a result of the firewall settings.
Removing a Firewall Rule Using Command Prompt
To delete a firewall rule via Command Prompt, enact the following process:
-
Open Start.
-
Search for Command Prompt (or Terminal), right-click, and select Run as administrator.
-
Type the command below to delete a firewall rule and press Enter:
netsh advfirewall firewall delete rule name="YOUR-DELETE-RULE"Make sure to modify the
nameto correspond with the rule targeting the relevant port.
Upon executing this command, the specified rule will be deleted, thereby closing the corresponding ports.
Removing a Firewall Rule Using PowerShell
To close a firewall port through PowerShell, follow these steps:
-
Open Start.
-
Search for PowerShell (or Terminal), right-click, and select Run as administrator.
-
Input the command below to remove a firewall rule and press Enter:
Remove-NetFirewallRule -DisplayName "YOUR-DELETE-RULE"Adjust the
DisplayNameto match the rule you wish to remove.
This command will execute the removal of the specified firewall rule, effectively closing the targeted ports.
Leave a Reply