kieranbarnes Independent PHP, WordPress & CubeCart Programmer

Advanced Policy Firewall (for cPanel)

Posted on August 2, 2010

More retro software that has been with us for years - APF - Advanced Policy Firewall. A brilliantly robust and fool proof Linux script that acts as a wrapper for iptables.

Here's how I configure it for all the WHM/cPanel boxes I commission, although you can configure it for non-cPanel servers, just adjust your ports accordingly.

  1. wget http://www.rfxn.com/downloads/apf-current.tar.gz
  2. tar zxpfv apf-current.tar.gz
  3. cd apf-9.7-1/
  4. sh install.sh
  5. nano /etc/apf/conf.apf

These are the main settings I change in the configuration file.

  1. # !!! Do not leave set to (1) !!!
  2. # When set to enabled; 5 minute cronjob is set to stop the firewall. Set
  3. # this off (0) when firewall is determined to be operating as desired.
  4. DEVEL_MODE="0"
  5.  
  6. # Common ingress (inbound) TCP ports for cPanel & WHM
  7. IG_TCP_CPORTS=" 20,21,22,25,26,53,80,110,143,443,465,993,995,2077,2078,2082,
  8. 2083,2086,2087,2095,2096,3306,6666"
  9.  
  10. # Common ingress (inbound) UDP ports for cPanel & WHM
  11. IG_UDP_CPORTS="21,53,465,873,2077,2078"
  12.  
  13. # Common ICMP (inbound) types
  14. # 'internals/icmp.types' for type definition; 'all' is wildcard for any
  15. IG_ICMP_TYPES="3,5,11,0,30,8"
  16.  
  17. # Outbound (egress) filtering - Always a good idea.
  18. EGF="1"
  19.  
  20. # Common egress (outbound) TCP ports for cPanel & WHM
  21. EG_TCP_CPORTS="21,25,26,37,43,53,80,113,465,873,3306"
  22.  
  23. # Common egress (outbound) UDP ports for cPanel & WHM
  24. EG_UDP_CPORTS="20,21,53,465,873"
  25.  
  26. # Common ICMP (outbound) types
  27. # 'internals/icmp.types' for type definition; 'all' is wildcard for any
  28. EG_ICMP_TYPES="all"

One final setting I had to change was the BLK_RESNET option

  1. Block all ipv4 address space marked reserved for future use (unassigned),
  2. # such networks have no business talking on the Internet. However they may at
  3. # some point become live address space. The USE_RD option further in this file
  4. # allows for dynamic updating of this list on every full restart of APF. Refer
  5. # to the 'internals/reserved.networks' file for listing of address space.
  6. BLK_RESNET="0"

Then, finally, start it /etc/init.d/apf start

You can confirm it is working with iptables -L

These are the Inbound tcp/udp and Outbound tcp/udp ports in question

Inbound TCP Ports

  • 20 FTP
  • 21 FTP
  • 22 SSH
  • 25 SMTP
  • 26 SMTP
  • 53 DNS
  • 80 HTTP
  • 110 POP
  • 3143 IMAP
  • 4443 HTTPS
  • 465 SMTP (TLS/SSL)
  • 993 IMAP4 (SSL)
  • 995 POP3 (SSL)
  • 2082 CPANEL
  • 2083 CPANEL (SSL)
  • 2086 WHM (Web Host Manager)
  • 2087 WHM (SSL)
  • 2095 WEBMAIL
  • 2096 WEBMAIL (SSL)

Inbound UDP Ports

  • 21 FTP
  • 53 DNS
  • 465 SMTP (TLS/SSL)

Outbound TCP Ports

  • 20  FTP
  • 21  FTP
  • 25  SMTP
  • 26  SMTP
  • 37  RDATE
  • 43  WHOIS
  • 53  DNS
  • 80  HTTP
  • 113  IDENT
  • 465  SMTP (TLS/SSL)
  • 873  RSYNC
  • 2089  CPANEL LICENSE

Outbound UDP Ports

  • 21 FTP
  • 53 DNS
  • 465 SMTP (TLS/SSL)
  • 873 RSYNC
** If you want MySQL remote access and have modified the my.cnf according make sure you add 3306 into EG_TCP_CPORTS and IG_TCP_CPORTS
** Its best practise to add your own IPs to the white list - /etc/apf/allow_hosts.rules
Now you've got a software firewall monitoring your server's incoming and outgoing requests.

Related posts

  1. Extending Advanced Policy Firewall with Brute Force Detection
    In my previous article I discussed setting up the Advanced Policy Firewall on your servers....
  2. CentOS / cPanel Firewall Setup
    I almost like CentOS now. That doesn't mean I can't get used to this daft...
  3. Upgrading to MySQL 5.1 in cPanel/WHM
    Upgrading to MySQL 5.1 in cPanel is currently not the easiest thing in the world....
  4. Installing mytop on cpanel
    MyTop is one of the best MySQL monitoring tools available, written by a MySQL guru,...
  5. [Snippet] Stupid Simple cPanel Install
    Open a clean server, Go have your lunch. Maybe lunch +VAT depending on the speed...

Posted by Kieran


Tagged as: , , , Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.