knowledge-base

Open/Close Ports

Now if you need to control ports so you can run several apps on different ports, you got to keep in mind that listening to this port from your VHost isn’t enough. You should open that port from the firewall. Firewall software that is included in CentOS7 is firewalld, and here we got the main commands to get the job done.

Check Status

sudo systemctl status firewalld

Start Service

sudo systemctl start firewalld

List All

To list all configuration already running:

sudo firewall-cmd --list-all

List Open Ports

sudo firewall-cmd --list-ports

List Services Allowed

sudo firewall-cmd --list-services

Open a Port

sudo firewall-cmd --zone=public --add-port=81/tcp --permanent
sudo firewall-cmd --reload

Without “–permanent” flag, port 81 will be closed agian on reboot.

Close a Port

Similarly we can reverse the last one this way:

firewall-cmd --remove-port=81/tcp --permanent

more:

  1. How to open a port in the firewall on CentOS or RHEL
  2. How to List Open Ports in Firewalld
  3. How to get started with Firewalld