Configure Firewall Rules to Allow Incoming Connections

Some deployments require inbound network access on specific TCP ports. If the operating system firewall blocks these ports, clients or services may be unable to connect.

This guide explains how to allow inbound TCP connections using several commonly used firewall solutions.

Windows Defender Firewall

Option 1: Using the Windows Defender Firewall Console

  1. Open Windows Defender Firewall from the Windows Start menu or search bar.


  1. Select Advanced settings to open Windows Defender Firewall with Advanced Security.


  1. Select Inbound Rules.


  1. In the Actions at the right-hand pane, click New Rule....


  1. Select Port and click Next.


  1. Select TCP, specify the required port number, and click Next.


If you are unsure which protocol or port to use, refer to your application's documentation.

  1. Select Allow the connection, then click Next.


  1. Accept the default settings and click Next.


  1. Enter a descriptive name for the rule (e.g., "Open Port”) and click Finish.


Option 2: Using PowerShell

  1. Run PowerShell as Administrator.

  2. Run the following command, replacing the placeholders with the appropriate values:

New-NetFirewallRule ` -DisplayName "<Rule Name>" ` -Direction Inbound ` -Action Allow ` -Protocol TCP ` -LocalPort <Port Number>

Uncomplicated Firewall (UFW)

  1. Verify that UFW is running.

sudo ufw status

Expected output:

Status: active
  1. Allow a TCP port, replacing the placeholders with the appropriate value.

sudo ufw allow <your port>/tcp

Example output:

Rule added Rule added (v6)
  1. Verify the firewall rule.

sudo ufw status

Confirm that the specified port appears in the list of allowed rules.


Firewalld

  1. Verify that firewalld is running:

sudo firewall-cmd --state

Expected output:

running
  1. Allow a TCP port. Add a permanent firewall rule:

sudo firewall-cmd --permanent --add-port=80/tcp
  1. Reload the firewall configuration to apply the change:

sudo firewall-cmd --reload
print("hello")
  1. Verify the firewall rule:

sudo firewall-cmd --list-ports

Confirm that the specified port is included in the list of allowed ports.