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:

  1. Launch Windows Security.

  2. Select Firewall & network protection.

  3. Click on Advanced settings.

    Windows firewall advanced settings

  4. Select Inbound Rules for rules that allow incoming traffic.

  5. Select Outbound Rules for rules allowing app traffic to exit.

  6. Click New Rule from the right pane under the “Actions” section.

    Microsoft Defender firewall new Inbound rule

  7. Select the Port option.

    Firewall open inbound port option

  8. Click Next.

  9. Choose the appropriate protocol, either TCP or UDP, based on the application requirement.

  10. Enter the port number in the “Specific local ports” field.

    Open specific firewall port using TCP or UDP protocol

    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).
  11. Click Next.

  12. Select the option “Allow the connection”. Note: You could also choose to block the connection if needed.

    Allow connection settings

  13. Click Next.

  14. Select the network type to which this rule will apply.(Default selections usually suffice.)

    Firewall network profile settings

  15. Click Next.

  16. Provide a descriptive name for this rule, such as “My Inbound Rule for APP-NAME.”

    Firewall open port rule name settings

  17. 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:

  1. Open Start.

  2. Search for Command Prompt (or Terminal), right-click the top result, and select Run as administrator.

  3. 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=12345

    Ensure 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.

  4. 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-2200

    Update 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:

  1. Open Start.

  2. Search for PowerShell (or Terminal), right-click the top result, and select Run as administrator.

  3. Run the following command to create an inbound firewall rule:

    New-NetFirewallRule -DisplayName "YOUR-APP-PORT"-Direction Inbound -Action Allow -Protocol TCP -LocalPort 12345

    Modify the command according to your rule name, direction (Inbound or Outbound), protocol (TCP or UDP), and local port specifications.

  4. 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-4010

    Ensure 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:

  1. Open Windows Security.

  2. Select Firewall & network protection.

  3. Access Advanced settings.

    Windows firewall advanced settings

  4. Click on the relevant Inbound Rules or Outbound Rules from the left pane, based on where the port was opened.

  5. Select the desired rule.

  6. Choose either Disable Rule to close the port while retaining the rule or select Delete Rule to remove the rule entirely.

    Delete firewall rule

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:

  1. Open Start.

  2. Search for Command Prompt (or Terminal), right-click, and select Run as administrator.

  3. 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 name to 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:

  1. Open Start.

  2. Search for PowerShell (or Terminal), right-click, and select Run as administrator.

  3. Input the command below to remove a firewall rule and press Enter:

    Remove-NetFirewallRule -DisplayName "YOUR-DELETE-RULE"

    Adjust the DisplayName to match the rule you wish to remove.

This command will execute the removal of the specified firewall rule, effectively closing the targeted ports.

Source & Images

Leave a Reply

Your email address will not be published. Required fields are marked *