How To Open Port on Linux

In this guide, we will explain how to open a port on a Linux instance, helping you manage network traffic and configure firewall settings effectively.

Opening a port on Linux is essential for allowing traffic to reach a specific application or service. This guide will walk you through the steps to open a port using tools like UFW and firewall-cmd.

Steps to Open a Port

Using ufw

Open the terminal and check the current Rules:

sudo ufw status

Allow traffic on a specific port:

sudo ufw allow 8080/tcp

Enable the UFW:

sudo ufw enable

Using firewall-cmd

Open the terminal and check the status :

sudo firewall-cmd --state

Add a rule to open a specific port:

sudo firewall-cmd --add-port=8080/tcp --permanent

Reload the firewall to apply changes:

sudo firewall-cmd --reload

Display all the current settings and rules

sudo firewall-cmd --list-all

Verifying the Port Opening

Using ssconfirm the port is open and listening:

sudo ss -tuln | grep 8080

Best Practices:

  • KeepRules Minimal: Only open necessary ports to reduce security risks.

  • Use Specific IP Addresses: Where possible, restrict access to specific IP addresses.

  • Monitor Traffic: Use monitoring tools to keep an eye on traffic to and from open ports.

Last updated