Linux

How to open port on firewalld service

To open a port on a system using `firewalld`, which is commonly found on CentOS, Fedora, and other RHEL-based Linux distributions, you need administrative privileges. Below are the steps to open a port on your firewall using `firewalld`:

1. Check the Status of firewalld:  
   First, ensure that `firewalld` is running. You can check its status with the following command:

sudo firewall-cmd --state

2. List Active Zones:  
   `firewalld` organizes rules into zones. List the active zones with:

sudo firewall-cmd --get-active-zones

3. Open a Port:  
   To open a port, you need to specify the zone and the port number along with the protocol (TCP or UDP). If you don't specify a zone, the default zone is used. For example, to open TCP port 8080, you would use:

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

4. Reload firewalld:  
   After making changes, you need to reload `firewalld` to apply them:

sudo firewall-cmd --reload

5. Verify the Changes:  
   Finally, confirm that the port is open by listing the rules in the zone:

sudo firewall-cmd --zone=public --list-ports

Remember to replace `8080/tcp` with your desired port number and protocol, and `public` with the appropriate zone if necessary. Also, using `--permanent` makes the rule persist across reboots. If you want to apply the rule immediately but not permanently, omit `--permanent` from the command.