How to Add a Port in Firewall Configuration on CentOS 7

November 16, 2022 ・0 comments

In this article we will see how to add a port in firewall configuration on centos 7.

We will be using the firewalld package for firewall configuration. 

Firewall is a network security tool that provides network level security based on a set of rules. It has controls on incoming and outgoing traffic.

Follow the article How To Install Firewalld on CentOS 7 if the package is not already installed.

Overview of Steps:

  1. Install the firewalld package
  1. Check the service status
  1. Adding the required ports
  1. Reloading the Service
  1. Validate the Configuration

Detailed Steps:

Step 1. Install the firewalld package
[root@localhost ~]# yum install firewalld
Step 2. Check the Service Status: Run the following command to check firewall running status:
[root@localhost ~]# firewall-cmd --stat
[root@localhost ~]#
Step 3. Adding Port: Run the following command to allow port in firewall:
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=80/tcp
[root@localhost ~]#
Change the port and protocol (tcp/udp) as desired.
Step 4. Reloading the Service: Run the following command for soft reloading firewall service to reflect the changes:
[root@localhost ~]# firewall-cmd --reload
[root@localhost ~]#
Step 5. Validate the Configuration: Run the following command to verify the configuration:
[root@localhost ~]# firewall-cmd --list-ports | grep 80
[root@localhost ~]#
Done!!! Port 80 is successfully allowed from Linux Firewall.
Note: Same process will be repeated whenever you want to add new ports to the firewall.

Post a Comment

If you can't commemt, try using Chrome instead.