FreeBSD Handbook
Prev | Chapter 31 Firewalls | Next

# 31.4 PF and ALTQ

Revised and updated by John Ferrell.

Since FreeBSD 5.3, a ported version of OpenBSD's PF firewall has been included as an integrated part of the base system. PF is a complete, full-featured firewall that has optional support for ALTQ (Alternate Queuing), which provides Quality of Service (QoS).

Since the OpenBSD Project maintains the definitive reference for PF in thePF FAQ, this section of the Handbook focuses on PF as it pertains to FreeBSD, while providing some general usage information.

More information about porting PF to FreeBSD can be found at http://pf4freebsd.love2party.net/.

## 31.4.1 Using the PF Loadable Kernel Modules

In order to use PF, the PF kernel module must be first loaded. Add the following line to `/etc/rc.conf`:

    pf_enable="YES"

Then, run the startup script to load the module:

    # service pf start

The PF module will not load if it cannot find the ruleset configuration file. The default location is `/etc/pf.conf`. If the PF ruleset is located somewhere else, add a line to `/etc/rc.conf` which specifies the full path to the file:

    pf_rules="/path/to/pf.conf"

The sample `pf.conf` can be found in `/usr/share/examples/pf/`.

The PF module can also be loaded manually from the command line:

    # kldload pf.ko

Logging support for PF is provided by `pflog.ko` which can be loaded by adding the following line to `/etc/rc.conf`:

    pflog_enable="YES"

Then, run the startup script to load the module:

    # service pflog start

## 31.4.2 PF Kernel Options

While it is not necessary to compile PF support into the FreeBSD kernel, some of PF's advanced features are not included in the loadable module, namely pfsync(4), which is a pseudo-device that exposes certain changes to the state table used by PF. It can be paired with carp(4) to create failover firewalls using PF. More information on CARP can be found in of the Handbook.

The following PF kernel options can be found in `/usr/src/sys/conf/NOTES`:

    device pf
    device pflog
    device pfsync

`device pf` enables PF support.

`device pflog` enables the optional pflog(4) pseudo network device which can be used to log traffic to a bpf(4) descriptor. The pflogd(8) daemon can then be used to store the logging information to disk.

`device pfsync` enables the optional pfsync(4) pseudo-network device that is used to monitor “state changes”.

## 31.4.3 Available `rc.conf` Options

The following rc.conf(5) statements can be used to configure PF and pflog(4) at boot:

    pf_enable="YES"                 # Enable PF (load module if required)
    pf_rules="/etc/pf.conf"         # rules definition file for pf
    pf_flags=""                     # additional flags for pfctl startup
    pflog_enable="YES"              # start pflogd(8)
    pflog_logfile="/var/log/pflog"  # where pflogd should store the logfile
    pflog_flags=""                  # additional flags for pflogd startup

If there is a LAN behind the firewall and packets need to be forwarded for the computers on the LAN, or NAT is required, add the following option:

    gateway_enable="YES"            # Enable as LAN gateway

## 31.4.4 Creating Filtering Rules

By default, PF reads its configuration rules from `/etc/pf.conf` and modifies, drops, or passes packets according to the rules or definitions specified in this file. The FreeBSD installation includes several sample files located in `/usr/share/examples/pf/`. Refer to the PF FAQ for complete coverage of PF rulesets.

> Warning: When reading the PF FAQ, keep in mind that different versions of FreeBSD contain different versions of PF. Currently, FreeBSD 8.`X` is using the same version of PF as OpenBSD 4.1. FreeBSD 9.`X` and later is using the same version of PF as OpenBSD 4.5.

The FreeBSD packet filter mailing list is a good place to ask questions about configuring and running the PF firewall. Do not forget to check the mailing list archives before asking questions.

## 31.4.5 Working with PF

To control PF, use pfctl(8). Below are some useful options to this command. Review pfctl(8) for a description of all available options:

Command | Purpose
--- | ---
`pfctl `-e`` | Enable PF.
`pfctl `-d`` | Disable PF.
`pfctl `-F` all `-f` /etc/pf.conf` | Flush all NAT, filter, state, and table rules and reload `/etc/pf.conf`.
`pfctl `-s` [ rules | nat state ]` | Report on the filter rules, NAT rules, or state table.
`pfctl `-vnf` /etc/pf.conf` | Check `/etc/pf.conf` for errors, but do not load ruleset.

## 31.4.6 Enabling ALTQ

ALTQ is only available by compiling its support into the FreeBSD kernel. ALTQ is not supported by all network card drivers. Refer to altq(4) for a list of drivers that are supported by the release of FreeBSD.

The following kernel options will enable ALTQ and add additional functionality:

    options         ALTQ
    options         ALTQ_CBQ        # Class Based Queuing (CBQ)
    options         ALTQ_RED        # Random Early Detection (RED)
    options         ALTQ_RIO        # RED In/Out
    options         ALTQ_HFSC       # Hierarchical Packet Scheduler (HFSC)
    options         ALTQ_PRIQ       # Priority Queuing (PRIQ)
    options         ALTQ_NOPCC      # Required for SMP build

`options ALTQ` enables the ALTQ framework.

`options ALTQ_CBQ` enables Class Based Queuing (CBQ). CBQ can be used to divide a connection's bandwidth into different classes or queues to prioritize traffic based on filter rules.

`options ALTQ_RED` enables Random Early Detection (RED). RED is used to avoid network congestion by measuring the length of the queue and comparing it to the minimum and maximum thresholds for the queue. If the queue is over the maximum, all new packets will be dropped. RED drops packets from different connections randomly.

`options ALTQ_RIO` enables Random Early Detection In and Out.

`options ALTQ_HFSC` enables the Hierarchical Fair Service Curve Packet Scheduler HFSC. For more information, refer to http://www-2.cs.cmu.edu/~hzhang/HFSC/main.html.

`options ALTQ_PRIQ` enables Priority Queuing (PRIQ). PRIQ will always pass traffic that is in a higher queue first.

`options ALTQ_NOPCC` enables SMP support for ALTQ. This option is required on SMP systems.

Prev | Home | Next
Firewall Packages | Up | The IPFILTER (IPF) Firewall