How to install and configure APF (Advanced Policy Firewall) on CentOS with cPanel

/ Category: Tutorials / Comments: None

Spread the love

APF (Advanced Policy Firewall) is a policy based iptables firewall application which is pretty easy to configure and use.

The process of installation and configuration on one of our Cloud VPS accounts is quite simple and takes less than 5 minutes to complete.

Log in to your server as root, download the software from: (the newest version at the time of writing this article was: 0.9.7_2) unpack it and install it by executing the following commands:

cd /root/


tar -zxvf

cd apf-9.7-2


Below is the general configuration of APF on servers with CentOS and cPanel. For more detailed information on every feature the firewall has, see the README file supplied with the APF sources.

Edit the APF configuration file:

vi /etc/apf/conf.apf

press ‘i’ to enter Input mode.

These are inbound TCP ports that need to be open in order to run cPanel behind a firewall: 20,21,22,25,26,37,43,53,80,110,113,143,443,465,873,993,995,2077,2078,2082, 2083,2086,2087,2095,2096 and 3306 (open port 3306 only if you want to remotely access to the MySQL database server).

Find the line starting with ‘IG_TCP_CPORTS’ and modify it to:


Find the line starting with ‘IG_UDP_CPORTS’ (inbound UDP ports that must be open) and modify it to:


Also modify the following lines:




where ‘IG_ICMP_TYPES’, ‘EG_TCP_CPORTS’ and ‘EG_UDP_CPORTS’ are inbound ICMP ports, outbound TCP ports and outbound UDP ports that must be open to run cPanel behind a firewall.

Start APF using the following command:

/usr/local/sbin/apf -s

Test the firewall with a port scanner like nmap or using a similar tool and if everything is OK, change DEVEL_MODE=”1″ option in the ‘/etc/apf/conf.apf’ configuration file to 0.

Restart APF for the changes to take effect using:

/usr/local/sbin/apf -r

To autostart APF at boot time execute the following command:

chkconfig --level 2345 apf on

Be the first to write a comment.

Your feedback