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/.
In order to use PF, the PF kernel module must be first
loaded. Add the following line to
/etc/rc.conf:
Then, run the startup script to load the module:
# service pf startThe 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:
/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.koLogging support for PF is provided by
pflog.ko which can be loaded by adding the
following line to /etc/rc.conf:
Then, run the startup script to load the module:
# service pflog startWhile 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 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”.
The following rc.conf(5) statements can be used to configure PF and pflog(4) at boot:
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:
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.
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.
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
| Enable PF. |
pfctl
| Disable PF. |
pfctl | Flush all NAT, filter, state, and table
rules and reload
/etc/pf.conf. |
pfctl | Report on the filter rules, NAT rules, or state table. |
pfctl | Check /etc/pf.conf for
errors, but do not load ruleset. |
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 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.
This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/
For questions about FreeBSD, read the
documentation before
contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.