Advanced Policy Firewall

Current Release:

Advanced Policy Firewall (APF) is an iptables(netfilter) based firewall system designed around the essential needs of today’s Internet deployed servers and the unique needs of custom deployed Linux installations. The configuration of APF is designed to be very informative and present the user with an easy to follow process, from top to bottom of the configuration file.

The technical side of APF is such that it utilizes the latest stable features from the iptables (netfilter) project to provide a very robust and powerful firewall. The filtering performed by APF is three fold:
1) Static rule based policies (not to be confused with a “static firewall”)
2) Connection based stateful policies
3) Sanity based policies

The first, static rule based policies, is the most traditional method of firewalling. This is when the firewall has an unchanging set of instructions (rules) on how traffic should be handled in certain conditions. An example of a static rule based policy would be when you allow/deny an address access to the server with the trust system or open a new port with conf.apf. So the short of it is rules that infrequently or never change while the firewall is running.

The second, connection based stateful policies, is a means to distinguish legitimate packets for different types of connections. Only packets matching a known connection will be allowed by the firewall; others will be rejected. An example of this would be FTP data transfers, in an older era of firewalling you would have to define a complex set of static policies to allow FTA data transfers to flow without a problem. That is not so with stateful policies, the firewall can see that an address has established a connection to port 21 then “relate” that address to the data transfer portion of the connection and dynamically alter the firewall to allow the traffic.

The third, sanity based policies, is the ability of the firewall to match various traffic patterns to known attack methods or scrutinize traffic to conform to Internet standards. An example of this would be when a would-be attacker attempts to forge the source IP address of data they are sending to you, APF can simply discard this traffic or optionally log it then discard it. To the same extent another example would be when a broken router on the Internet begins to relay malformed packets to you, APF can simply discard them or in other situations reply to the router and have it stop sending you new packets (TCP Reset).

– detailed and well commented configuration file
– granular inbound and outbound network filtering
– user id based outbound network filtering
– application based network filtering
– trust based rule files with an optional advanced syntax
– global trust system where rules can be downloaded from a central management server
– reactive address blocking (RAB), next generation in-line intrusion prevention
– debug mode provided for testing new features and configuration setups
– fast load feature that allows for 1000+ rules to load in under 1 second
– inbound and outbound network interfaces can be independently configured
– global tcp/udp port & icmp filtering with multiple filters (drop, reject, prohibit)
– configurable policies for each ip on the system with convenience variables to import settings
– packet flow rate limiting that prevents abuse on the most widely abused protocol, icmp
– prerouting and postrouting rules for optimal network performance
– block list support to ban networks exhibiting suspicious activity
– spamhaus Don’t Route Or Peer List support to ban known “hijacked zombie” IP blocks
– any number of additional interfaces may be configured as trusted or untrusted
– additional firewalled interfaces can have there own unique firewall policies applied
– intelligent route verification to prevent embarrassing configuration errors
– advanced packet sanity checks to make sure traffic coming and going meets the strictest of standards
– filter attacks such as fragmented UDP, port zero floods, stuffed routing, arp poisoning and more
– configurable type of service options to dictate the priority of different types of network traffic
– intelligent default settings to meet every day server setups
– dynamic configuration of your servers local DNS revolvers into the firewall
– optional filtering of common p2p applications
– optional filtering of private & reserved IP address space
– optional implicit blocks of the ident service
– configurable connection tracking settings to scale the firewall to the size of your network
– configurable kernel hooks (ties) to harden the system further to syn-flood attacks & routing abuses
– advanced network control such as explicit congestion notification and overflow control
– helper chains for FTP DATA and SSH connections to prevent client side issues
– optional rate limited event logging
– logging subsystem that allows for logging data to user space programs or standard syslog files
– comprehensive logging of every rule added
– detailed startup error checking
– if you are familiar with netfilter you can create your own rules in any of the policy files
– pluggable and ready advanced use of QoS algorithms provided by the Linux
– 3rd party add-on projects that compliment APF features

Funding for the continued development and research into this and other projects is solely dependent on public contributions and donations. If this is your first time using this software we ask that you evaluate it and consider a small donation; for those who frequent and are continued users of this and other projects we also ask that you make an occasional donation to help ensure the future of our public projects.

236 Replies to “Advanced Policy Firewall”

  1. The current version of APF doesn’t like Ubuntu’s new kernel. Is there anything I can adjust in the configs to allow it to start?

    apf(32091): {glob} activating firewall
    apf(32131): {glob} kernel version not equal to 2.4.x or 2.6.x, aborting.
    apf(32091): {glob} firewall initalized

    uname -a
    Linux xxxxxx 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

    1. You must go into the conf.apf and set a “1” to MONOKERN. This is likely because you have a non-modular IPTables on your system.

      I ran into the same issue when I tried to run it the first time.


  2. what about this error:

    apf(22428): {rab} force set RAB disabled, kernel module ipt_recent not found.

    on recent centos installations the module used is xt_recent not ipt_recent

  3. BARRY:

    How can I filter access to port 3306 and allow only internal “c-class” access

    you can that by editing


    add in there something like:


    to allow incoming tcp traffic with source and dest port 3306


  4. I couldn’t find anything in the docs or the changelog regarding IPv6 support, save for a one year old comment that promised it to be implemented in the “near future”. So what’s the current status of IPv6 support?

  5. Great firewall!! Best I’ve seen so far. But there is one tiny thing I wish for. I run Debian Squeeze and when looking into the apache2 access.log I often see IP’s trying to get files like PHPMYADMIN. Then I wish I could block that IP, a kind of conditional blocking.
    Otherwise I’m satified. Many thanks.

  6. I have a question on upgrading APF from a previous (any) version to the latest:
    Is it OK to install on top of the installed version while the firewall is running or we should uninstall the previous first??

    Thank you

  7. Hi,

    I use your script with debian squeeze..

    Recently, I have :

    [email protected]:~# apf -d
    iptables: No chain/target/match by that name.
    iptables: No chain/target/match by that name.
    apf(15440): (trust) added deny all to/from xx.xx.xx.xx

    Why ?

    My kernel is

    Thx for answer

  8. Found a server having very bad berformance on “high” latencies links (~80ms RTT, gbit USEU resulting in max 7mbit…)

    the poor performances were caused by
    “echo 0 > /proc/sys/net/ipv4/tcp_window_scaling”
    (part of SYSCTL_TCP)

    Is there a specific reason to keep it disabled?

    Re-enabling window_scaling allowed me to reach the expected 500mbit+ on the exact same link :/

    1. I have the same problem as evcz .

      SYSCTL_TCP=”1″ results in “tcp_window_scaling=0” – which leads to very much poorer server performance!

      1. This issue has been fixed in the production release of APF, I have removed tcp_window_scaling from the SYSCTL_TCP function. To enable window scaling again, run:
        echo 1 > /proc/sys/net/ipv4/tcp_window_scaling

        The use of window scaling is a double edged sword and though years ago posed some security implications along with standards issues, that is no longer the case today and its usage, being default enabled on most distro releases now, warrants the removal of disabling it from APF.

  9. Philippe Bolduc:

    Philippe Bolduc:

    Are you aware on any bug in apf 9.7 rev 1 or bfd removing local network from the firewall with a line like this in apf log ?
    {trust} removed 168 from trust system

    It’s related to ddos deflate
    it’s using command apf -u ip_adresse to unband ip !!
    What is does it delete remove host from [glob]*_hosts.rules and immediately remove rule from firewall

    So for an reason that i don’t understand it run apf -u 160 witch delete rules who match 160 in /etc/apf/allow_hosts.rules and /etc/apf/deny_hosts.rules

  10. Philippe Bolduc:

    Are you aware on any bug in apf 9.7 rev 1 or bfd removing local network from the firewall with a line like this in apf log ?
    {trust} removed 168 from trust system

    It’s related to ddos deflate

    it’s using command apf -u ip_adresse to unband ip !!

    What is does it delete remove host from [glob]*_hosts.rules and immediately remove rule from firewall

  11. Hi,

    thx for your great tools,
    and i meet some problems as I have two NICs to the internet to different isp,I want apf work on them two,
    how can i do that?

    my config is :
    # Untrusted Network interface(s); all traffic on defined interface will be
    # subject to all firewall rules. This should be your internet exposed
    # interfaces. Only one interface is accepted for each value.

Leave a Reply

Your email address will not be published. Required fields are marked *