What is the method for adding ports to firewalld in Linux?

To add a port in Linux using firewalld, follow these steps:

  1. Make sure the firewalld service is installed and running. You can check the status of firewalld using the following command:
systemctl status firewalld

If the service is not started, you can use the following command to start the firewalld service.

systemctl start firewalld
  1. Open the desired service that requires the addition of a port using the following command, for example, adding port 80 for the HTTP service:
firewall-cmd --zone=public --add-service=http --permanent

Indicate the region where the rule will be added with “–zone=public”, specify the service to add with “–add-service=http” (alternatively, you can use “–add-port=80/tcp”), and use “–permanent” to make the rule permanently effective (still valid after reboot).

  1. Reload the firewalld service to apply the rules.
firewall-cmd --reload
  1. Use the following command to verify if the port has been successfully added:
firewall-cmd --zone=public --list-all

This will list all current rules, including the ports that have been added.

Note: The above command needs to be run with root privileges. If running under a different user, you can use the sudo command to elevate privileges.

bannerAds