RHEL BasedRocky Linux

How To Install APF on Rocky Linux 9

Install APF on Rocky Linux 9

In this tutorial, we will show you how to install APF on Rocky Linux 9. As Linux enthusiasts, we understand the importance of securing our systems against potential threats. One way to accomplish this is by implementing an effective firewall. In this blog post, we will discuss the installation and configuration of the Advanced Policy Firewall (APF) on Rocky Linux 9. APF is a popular firewall that provides an easy-to-use interface for managing iptables rules. Its robust features include brute-force protection, port scanning detection, and network filtering, making it an excellent choice for securing your system. By the end of this tutorial, you will have a solid understanding of how to install and configure APF on Rocky Linux 9 and will be able to secure your system against potential network threats. So let’s dive in and start securing your system today!

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the APF (Advanced Policy Firewall) on Rocky Linux 9 or RHEL-based.


  • A server running one of the following operating systems: Rocky Linux 9.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for APF.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install APF on Rocky Linux 9

Step 1. The first step is to update your system to the latest version of the package list. To do so, run the following commands:

sudo dnf check-update

Step 2. Installing APF on Rocky Linux 9.

By default, APF is not available on Rocky Linux 9 AppStream repository. Now run the following command below to download the APF package from the official website using the following command:

wget http://www.rfxnetworks.com/downloads/apf-current.tar.gz

Next, extract the downloaded package using the following command:

tar xvfz apf-current.tar.gz
cd apf-1*

Then, run the installation script using the following command:

sudo ./install.sh

Step 3. Configuring APF.

Once APF is installed on your Rocky Linux 9 system, you can configure it according to your specific needs. Here are some common configurations that you may want to consider:

  • Enabling or Disabling Firewall Rules.

APF comes with a number of predefined firewall rules that are enabled by default. You can view these rules by running the following command:

apf -l

To enable or disable a rule, simply edit the configuration file located at /etc/apf/conf.apf. Locate the rule that you want to modify, and change the value of IG_TCP_CPORTS or IG_UDP_CPORTS to 1 to enable the rule or 0 to disable it.

  • Whitelisting or Blacklisting IP Addresses.

You may want to whitelist or blacklist certain IP addresses depending on your network security needs. To whitelist an IP address, simply add it to the allow_hosts.rules file located at /etc/apf/. To blacklist an IP address, add it to the deny_hosts.rules file located at the same location.

  • Changing Firewall Settings.

To change other firewall settings, such as the maximum number of connections allowed or the maximum number of states that can be tracked, edit the /etc/apf/conf.apf file as desired. Make sure to save your changes and restart APF for the changes to take effect:

sudo systemctl restart apf

Congratulations! You have successfully installed APF. Thanks for using this tutorial for installing APF (Advanced Policy Firewall) on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official APF website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!


r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button