How to open a firewall port on Windows 11

If you must open the port through the Microsoft Defender Firewall, in this guide, I'll explain how to complete this configuration on Windows 11.

Windows 11 open firewall port
Windows 11 open firewall port / Image: Mauro Huculak
  • To open a Windows firewall port, open the “Windows Defender Firewall with Advanced Security” console.
  • Then click on “Inbound Rules” or “Outbound Rules,” click on “New Rule,” and select the “Port” option.
  • Continue selecting the protocol and the port number to open on Windows 11, allow the connection, choose the network profile to apply the rules, and save the changes.
  • You can also open one or multiple ports using commands with PowerShell and Command Prompt.

On Windows 11, the Microsoft Defender Firewall is a built-in security feature that helps protect your device by controlling network traffic, blocking unauthorized access from the outside, and preventing suspicious apps from connecting to the internet.

The firewall works as a gatekeeper, monitoring all incoming and outgoing network requests. When an app or service tries to access the network, Microsoft Defender Firewall (also referred to as the “Windows Firewall”) checks its rules database to determine whether to allow or block the connection. If no rule exists, Windows 11 will prompt you to grant or deny access manually.

In some cases, trusted apps (such as SQL Server) may not function correctly because the firewall is blocking them. When that happens, you must create a custom inbound or outbound rule to allow network access and restore functionality.

In this guide, I’ll teach you the steps to open a port to allow an app to communicate outside the network using the Windows 11 firewall.

Important: Before creating a firewall rule, check the app’s official support page to identify the required port numbers and protocol types (TCP or UDP). You can also quickly verify if a blocked port is the issue by temporarily disabling the firewall. If the app works while the firewall is off, it confirms that you need to create a custom rule to allow the connection. Re-enable the firewall immediately afterward.

Open a firewall port on Windows 11

Using the default firewall, you can create an inbound or an outbound rule, depending on the app requirements, using the Advanced Security console, Command Prompt, or PowerShell.

Create a firewall rule from Advanced Security

To open one or more ports in the Windows firewall, follow these steps:

  1. Open Windows Security.

  2. Click on Firewall & network protection.

  3. Click the Advanced settings option.

    Windows firewall advanced settings

  4. (Option 1) Select Inbound Rules from the left navigation pane to create a rule to allow incoming traffic into the device.

  5. (Option 2) Select Outbound Rules from the left navigation pane to create a rule to allow the traffic from the app to leave the device.

  6. Click the New Rule option in 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 the Next button.

  9. Select the appropriate protocol (TCP or UDP) depending on the application.

  10. Type the port number in the “Specific local ports” setting.

    Open specific firewall port using TCP or UDP protocol

    Quick note: If the app requires multiple ports open, you can type as many as you need as long as you separate each one with a comma (4500,4600,5000). If you need to specify a port range, you can use a hyphen (-). For example, 3000-3100.
  11. Click the Next button.

  12. Select the “Allow the connection” option. (Using the same step, note that you can block the connection.)

    Allow connection settings

  13. Click the Next button.

  14. Select the network type to apply the rule. (Usually, you want to leave this option with the default selections.)

    Firewall network profile settings

  15. Click the Next button.

  16. Type a descriptive name for the rule. For example, “My Inbound Rule for APP-NAME.”

    Firewall open port rule name settings

  17. Click the Finish button.

After you complete the steps, inbound connections will be allowed for the app through the port you open in the firewall.

Create a firewall rule using Command Prompt

To open a firewall port through Command Prompt, follow these steps:

  1. Open Start.

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

  3. Type this command to create an incoming firewall rule with Command Prompt and press Enter:

    netsh advfirewall firewall add rule name="YOUR-APP-PORT" dir=in action=allow protocol=TCP localport=12345

    netsh open firewall port in Command Prompt

    In the command, update the name setting for the name of the rule you want to use. In protocol, use TCP or UDP, and specify the port number in the localport setting.

    Quick tip: netsh doesn’t support a comma-separated list of ports like localport=80,443,8080. Instead, you must run one command per port.
  4. Type this command to open a range of ports with Command Prompt and press Enter:

    netsh advfirewall firewall add rule name="YOUR-PORT-RANGE-NAME" dir=in action=allow protocol=TCP localport=2000-2200

    In the command, update the name setting for the name of the rule you want to use. In protocol, use TCP or UDP, and specify the port number in the localport setting.

Once you complete the steps, the specified network ports using Command Prompt will open on Windows 11.

If you must create an in or out rule with multiple ports (out of range), you can use a batch loop command. For example, for %%P in (80 443 8080) do netsh advfirewall firewall add rule name="Allow TCP %%P" dir=in action=allow protocol=TCP localport=%%P

In the command, you have to update the ports, direction (in or out), and protocol (TCP or UDP).

Create a firewall rule using PowerShell

To open a firewall port using a PowerShell command, follow these steps:

  1. Open Start.

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

  3. Type this command to create an incoming firewall rule with PowerShell and press Enter:

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

    PowerShell create firewall rule on Windows 11

    In the command, you have to update the name, direction (Inbound or Outbound), protocol (TCP or UDP), and local port settings in the same way as required using Command Prompt.

  4. Type this command to open a range of ports with PowerShell and press Enter:

    New-NetFirewallRule -DisplayName "YOUR-PORT-RANGE-NAME" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 4000-4010

    In the command, update the name, direction (Inbound or Outbound), protocol (TCP or UDP), and specify the port range.

After you complete the steps, the PowerShell command will create the inbound or outbound rule in the Microsoft Defender Firewall.

If you must create an in or out rule with multiple ports (out of range), you can use a foreach loop command. For example:

$ports = @(80, 443, 8080)
foreach ($port in $ports) {
    New-NetFirewallRule -DisplayName "Allow TCP $port" -Direction Inbound -Action Allow -Protocol TCP -LocalPort $port
}

In the command, you have to update the ports, direction (in or out), and protocol (TCP or UDP).

Close a firewall port on Windows 11

You can also close a port by deleting a specific rule using the Advanced Security console, Command Prompt, or PowerShell.

Close a firewall rule from Advanced Security

To delete a port in the Microsoft Defender Firewall, follow these steps:

  1. Open Windows Security.

  2. Click on Firewall & network protection.

  3. Click the Advanced settings option.

    Windows firewall advanced settings

  4. Click on Inbound Rules or Outbound Rules from the left navigation pane, depending on where you open the firewall port.

  5. Select the rule you want.

  6. Click the Disable Rule to close the port while keeping the rule under the “Actions” section. Or click the Delete Rule option to close the port and remove the rule from the firewall.

    Delete firewall rule

After you complete the steps, the app or service will no longer have access to the network or internet because the Windows firewall will block it.

Close a firewall rule using Command Prompt

To open a firewall port through Command Prompt, follow these steps:

  1. Open Start.

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

  3. Type this command to delete a firewall rule with Command Prompt and press Enter:

    netsh advfirewall firewall delete rule name="YOUR-DELETE-RULE"

    netsh delete firewall port in Command Prompt

    In the command, update the name setting with the name of the rule that includes the port to close.

Once you complete the steps, the Command Prompt command will delete the rule, closing the specified ports.

Close a firewall rule using PowerShell

To open a firewall port using a PowerShell command, follow these steps:

  1. Open Start.

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

  3. Type this command to delete a firewall rule with PowerShell and press Enter:

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

    PowerShell delete remove firewall rule

    In the command, update the DisplayName setting with the name of the rule that contains the port to close.

After you complete the steps, the PowerShell command will delete the rule with the ports you want to close.

About the author

Mauro Huculak is a Windows How-To Expert and founder of Pureinfotech in 2010. With over 22 years as a technology writer and IT Specialist, Mauro specializes in Windows, software, and cross-platform systems such as Linux, Android, and macOS.

Certifications: Microsoft Certified Solutions Associate (MCSA), Cisco Certified Network Professional (CCNP), VMware Certified Professional (VCP), and CompTIA A+ and Network+.

Mauro is a recognized Microsoft MVP and has also been a long-time contributor to Windows Central.

You can follow him on YouTube, Threads, BlueSky, X (Twitter), LinkedIn and About.me. Email him at [email protected].