LKBEN11755: How to add or open a port in the firewall of rocky linux?


Symptom

You need to open a port in the firewall.

Cause

Needed for some services.

Solution

To adjust the firewall on rocky linux, you use the firewall-cmd command. To open the http port you use the following command:

# temporarily allow connections on port 80 until the next reboot
sudo firewall-cmd --add-service=http

# as an alternative to permanently open port 80 you can use
sudo firewall-cmd --permanent --add-service=80

# to temporarily allow connection on port 8080 e.g. a java server until reboot
# here we added the zone
sudo firewall-cmd --zone=public --add-port=8080/tcp

If you want to verify the ports/services were added correctly, you can use:

sudo firewall-cmd --permanent --list-all

To appy the changes, you will need to reload the firewall service like this:

sudo firewall-cmd --reload

In some rare cases, this might not work. In this case you can completely restart the firewall service:

sudo systemctl restart firewalld.service

Have fun.

Disclaimer:

The information provided in this document is intended for your information only. Lubby makes no claims to the validity of this information. Use of this information is at own risk!

About the Author

Author: Wim Peeters - Keskon GmbH & Co. KG

Wim Peeters is electronics engineer with an additional master in IT and over 30 years of experience, including time spent in support, development, consulting, training and database administration. Wim has worked with SQL Server since version 6.5. He has developed in C/C++, Java and C# on Windows and Linux. He writes knowledge base articles to solve IT problems and publishes them on the Lubby Knowledge Platform.

Latest update: 06/11/2024