PFCTL(8)
π pfctl β System Manager's Manual, section 8 π
πΈ NAME πΈ
pfctl β control the packet filter (PF) device. It's literally the remote control for PF. ποΈπ
β¨ SYNOPSIS β¨
pfctl [-AdeghMmNnOPqRrvz] [-a anchor] [-D macro= value] [-F modifier]
[-f file] [-i interface] [-K host | network] [-k host | network |
label | id | gateway | nat] [-o level] [-p device] [-s modifier]
[-t table -T command [address ...]] [-x level]
π¦ DESCRIPTION π¦
Okay so pfctl is the utility that talks to the packet filter device through the ioctl interface described in pf(4). It handles ruleset and parameter configuration, and it also retrieves status information from the packet filter. Main character energy, honestly. β¨
Packet filtering is the whole vibe of restricting which types of packets can pass through network interfaces when they enter or leave the host, based on filter rules as described in pf.conf(5). The packet filter can also replace addresses and ports of packets. Replacing source addresses and ports of outgoing packets is called NAT (Network Address Translation), and it's used to connect an internal network (usually reserved address space) to an external one (the Internet) by making all connections to external hosts appear to come from the gateway. Replacing destination addresses and ports of incoming packets is used to redirect connections to different hosts and/or ports. A combination of both translations, bidirectional NAT, is also supported. Translation rules are described in pf.conf(5). π
When the variable pf_enable is set to YES in rc.conf(5), the rule file specified with the variable pf_rules is loaded automatically by the rc(8) scripts and the packet filter is enabled. π«Ά
Heads up, bestie: the packet filter does not itself forward packets between interfaces. Forwarding can be enabled by setting the sysctl(8) variables net.inet.ip.forwarding and/or net.inet6.ip6.forwarding to 1. Set them permanently in sysctl.conf(5). π₯
At least one option must be specified. The options are as follows:
-Aβ Load only the queue rules present in the rule file. Other rules and options are ignored.-aanchor β Apply flags-f,-F,-s, and-Tonly to the rules in the specified anchor. In addition to the main ruleset,pfctlcan load and manipulate additional rulesets by name, called anchors. The main ruleset is the default anchor.
Anchors are referenced by name and may be nested, with the various components of the anchor path separated by / characters, similar to how file system hierarchies are laid out. The last component of the anchor path is where ruleset operations are performed.
Evaluation of anchor rules from the main ruleset is described in pf.conf(5).
For example, the following will show all filter rules (see the -s flag below) inside the anchor authpf/smith(1234), which would have been created for user smith by authpf(8), PID 1234:
# pfctl -a "authpf/smith(1234)" -s rules
Private tables can also be put inside anchors, either by having table statements in the pf.conf(5) file that is loaded in the anchor, or by using regular table commands, as in:
# pfctl -a foo/bar -t mytable -T add 1.2.3.4 5.6.7.8
When a rule referring to a table is loaded in an anchor, the rule will use the private table if one is defined, and then fall back to the table defined in the main ruleset, if there is one. This is similar to C rules for variable scope. It is possible to create distinct tables with the same name in the global ruleset and in an anchor, but this is often bad design and a warning will be issued in that case. π
By default, recursive inline printing of anchors applies only to unnamed anchors specified inline in the ruleset. If the anchor name is terminated with a * character, the -s flag will recursively print all anchors in a brace delimited block. For example the following will print the authpf ruleset recursively:
# pfctl -a 'authpf/*' -sr
To print the main ruleset recursively, specify only * as the anchor name:
# pfctl -a '*' -sr
To flush all rulesets and tables recursively, specify only * as the anchor name:
# pfctl -a '*' -Fa
-Dmacro=value β Define macro to be set to value on the command line. Overrides the definition of macro in the ruleset.-dβ Disable the packet filter.-eβ Enable the packet filter.-Fmodifier β Flush the filter parameters specified by modifier (may be abbreviated):-F natβ Flush the NAT rules.-F queueβ Flush the queue rules.-F ethernetβ Flush the Ethernet filter rules.-F rulesβ Flush the filter rules.-F statesβ Flush the state table (NAT and filter).-F Sourcesβ Flush the source tracking table.-F infoβ Flush the filter information (statistics that are not bound to rules).-F Tablesβ Flush the tables.-F osfpβ Flush the passive operating system fingerprints.-F Resetβ Reset limits, timeouts and other options back to default settings. See the OPTIONS section inpf.conf(5)for details.-F allβ Flush all of the above.
If -a is specified as well and anchor is terminated with a * character, rules, Tables and all flush the given anchor recursively.
-ffile β Load the rules contained in file. This file may contain macros, tables, options, and normalization, queueing, translation, and filtering rules. With the exception of macros and tables, the statements must appear in that order. π-gβ Include output helpful for debugging.-hβ Help. π-iinterface β Restrict the operation to the given interface.-Khost | network β Kill all of the source tracking entries originating from the specified host or network. A second-K hostor-K networkoption may be specified, which will kill all the source tracking entries from the first host/network to the second.-khost | network | label | id | key | gateway | nat β Kill all of the state entries matching the specified host, network, label, id, key, gateway, or nat.
For example, to kill all of the state entries originating from host:
# pfctl -k host
A second -k host or -k network option may be specified, which will kill all of the state entries from the first host/network to the second. To kill all of the state entries from host1 to host2:
# pfctl -k host1 -k host2
To kill all states originating from 192.168.1.0/24 to 172.16.0.0/16:
# pfctl -k 192.168.1.0/24 -k 172.16.0.0/16
A network prefix length of 0 can be used as a wildcard. To kill all states with the target host2:
# pfctl -k 0.0.0.0/0 -k host2
It is also possible to kill states by rule label, state key or state ID. In this mode the first -k argument is used to specify the type of the second argument. The following command would kill all states that have been created from rules carrying the label foobar:
# pfctl -k label -k foobar
To kill one specific state by its key (protocol, host1, port1, direction, host2 and port2 in the same format of pfctl -s state), use the key modifier and as a second argument the state key. To kill a state whose protocol is TCP and originating from 10.0.0.101:32123 to 10.0.0.1:80 use:
# pfctl -k key -k 'tcp 10.0.0.1:80 <- 10.0.0.101:32123'
To kill one specific state by its unique state ID (as shown by pfctl -s state -vv), use the id modifier and as a second argument the state ID and optional creator ID. To kill a state with ID 4823e84500000003 use:
# pfctl -k id -k 4823e84500000003
To kill a state with ID 4823e84500000018 created from a backup firewall with hostid 00000002 use:
# pfctl -k id -k 4823e84500000018/2
It is also possible to kill states created from a rule with the route-to/reply-to parameter set to route the connection through a particular gateway. Note that rules routing via the default routing table (not via a route-to rule) will have their rt_addr set as 0.0.0.0 or ::. To kill all states using a gateway of 192.168.0.1 use:
# pfctl -k gateway -k 192.168.0.1
A network prefix length can also be specified. To kill all states using a gateway in 192.168.0.0/24:
# pfctl -k gateway -k 192.168.0.0/24
States can also be killed based on their pre-NAT address:
# pfctl -k nat -k 192.168.0.1
-Mβ Kill matching states in the opposite direction (on other interfaces) when killing states. This applies to states killed using the-koption and also will apply to the flush command when flushing states. This is useful when an interface is specified when flushing states. Example:
# pfctl -M -i interface -Fs
-mβ Merge in explicitly given options without resetting those which are omitted. Allows single options to be modified without disturbing the others:
# echo "set loginterface fxp0" | pfctl -mf -
-Nβ Load only the NAT rules present in the rule file. Other rules and options are ignored.-nβ Do not actually load rules, just parse them.-Oβ Load only the options present in the rule file. Other rules and options are ignored.-olevel β Control the ruleset optimizer, overriding any rule file settings.-o noneβ Disable the ruleset optimizer.-o basicβ Enable basic ruleset optimizations. This is the default behaviour.-o profileβ Enable basic ruleset optimizations with profiling.
For further information on the ruleset optimizer, see pf.conf(5).
-Pβ Do not perform service name lookup for port specific rules, instead display the ports numerically.-pdevice β Use the device file device instead of the default/dev/pf.-qβ Only print errors and warnings.-Rβ okay so this is the βfilter rules only, bestieβ mode. Load only the filter rules present in the rule file. Other rules and options are ignored, periodt. π-rβ perform reverse DNS lookups on states and tables when displaying them. Heads up:-Nand-rare mutually exclusive, so pick one, iykyk. π«Ά-s modifier [-R id]β show the filter parameters specified bymodifier(it may be abbreviated, slay β¨). The modifiers are giving main character energy:-s natβ show the currently loaded NAT rules.-s queueβ show the currently loaded queue rules. When used together with-v, per-queue statistics are also shown. When used together with-v -v,pfctlwill loop and show updated queue statistics every five seconds, including measured bandwidth and packets per second. Obsessed with the live updates ngl. π-s ethernetβ show the currently loaded Ethernet rules. When used together with-v, the per-rule statistics (number of evaluations, packets, and bytes) are also shown.-s rulesβ show the currently loaded filter rules. When used together with-v, the per-rule statistics (number of evaluations, packets, and bytes) are also shown. Note that the βskip stepβ optimization done automatically by the kernel will skip evaluation of rules where possible. Packets passed statefully are counted in the rule that created the state (even though the rule is not evaluated more than once for the entire connection). Kernel really said βbestie I got this.β-s Anchorsβ show the currently loaded anchors directly attached to the main ruleset. If-a anchoris specified as well, the anchors loaded directly below the given anchor are shown instead. If-vis specified, all anchors attached under the target anchor will be displayed recursively.-s statesβ show the contents of the state table.-s Sourcesβ show the contents of the source tracking table.-s infoβ show filter information (statistics and counters). When used together with-v, source tracking statistics, the firewall's 32-bit hostid number and the main ruleset's MD5 checksum for use withpfsync(4)are also shown. Big y2k data-dump energy, but make it useful. πΎ-s Runningβ show the running status and provide a non-zero exit status when disabled.-s labelsβ show per-rule statistics (label, evaluations, packets total, bytes total, packets in, bytes in, packets out, bytes out, state creations) of filter rules with labels, useful for accounting.-s timeoutsβ show the current global timeouts.-s memoryβ show the current pool memory hard limits.-s Tablesβ show the list of tables.-s osfpβ show the list of operating system fingerprints.-s Interfacesβ show the list of interfaces and interface groups available to PF. When used together with-v, it additionally lists which interfaces have skip rules activated. When used together with-vv, interface statistics are also shown.-ican be used to select an interface or a group of interfaces.-s allβ show all of the above, except for the lists of interfaces and operating system fingerprints.
Counters shown with -s info are:
matchβ explicit rule matchbad-offsetβ currently unusedfragmentβ invalid fragments droppedshortβ short packets droppednormalizeβ dropped by normalizer: illegal packetsmemoryβ memory could not be allocatedbad-timestampβ bad TCP timestamp; RFC 1323congestionβ network interface queue congestedip-optionβ bad IP/IPv6 optionsproto-cksumβ invalid protocol checksumstate-mismatchβ packet was associated with a state entry, but sequence numbers did not matchstate-insertβ state insertion failurestate-limitβ configured state limit was reachedsrc-limitβ source node/connection limitsynproxyβ dropped by synproxymap-failedβ address mapping failedtranslateβ no free ports in translation port range-Sβ do not perform domain name resolution. If a name cannot be resolved without DNS, an error will be reported. So if DNS is acting up, this one says βweβre not doing that today.β π-t table -T command [address ...]β specify the command (may be abbreviated) to apply totable. Commands include:-T addβ add one or more addresses to a table. Automatically create a persistent table if it does not exist.-T deleteβ delete one or more addresses from a table.-T expire numberβ delete addresses which had their statistics cleared more thannumberseconds ago. For entries which have never had their statistics cleared,numberrefers to the time they were added to the table.-T flushβ flush all addresses in a table.-T killβ kill a table. Violent but iconic. π₯-T replaceβ replace the addresses of the table. Automatically create a persistent table if it does not exist.-T showβ show the content (addresses) of a table.-T testβ test if the given addresses match a table.-T zero [address ...]β clear all the statistics of a table, or only for specified addresses.-T resetβ clear statistics only for addresses with non-zero statistics. Addresses with counter values at zero and their βClearedβ timestamp are left untouched.-T loadβ load only the table definitions frompf.conf(5). This is used in conjunction with the-fflag, as in:
# pfctl -Tl -f pf.conf
For the add, delete, replace, and test commands, the list of addresses can be specified either directly on the command line and/or in an unformatted text file, using the -f flag. Comments starting with a β#β or β;β are allowed in the text file. With these commands, the -v flag can also be used once or twice, in which case pfctl will print the detailed result of the operation for each individual address, prefixed by one of the following letters:
Aβ the address/network has been added.Cβ the address/network has been changed (negated).Dβ the address/network has been deleted.Mβ the address matches (test operation only).Xβ the address/network is duplicated and therefore ignored.Yβ the address/network cannot be added/deleted due to conflicting β!β attributes.Zβ the address/network has been cleared (statistics).
Each table can maintain a set of counters that can be retrieved using the -v flag of pfctl. For example, the following commands define a wide open firewall which will keep track of packets going to or coming from the OpenBSD FTP server. The following commands configure the firewall and send 10 pings to the FTP server:
# printf "table <test> counters { ftp.openbsd.org }\n \
pass out to <test>\n" | pfctl -f-
# ping -qc10 ftp.openbsd.org
We can now use the table show command to output, for each address and packet direction, the number of packets and bytes that are being passed or blocked by rules referencing the table. The time at which the current accounting started is also shown with the βClearedβ line.
# pfctl -t test -vTshow
129.128.5.191
Cleared: Thu Feb 13 18:55:18 2003
In/Block: [ Packets: 0 Bytes: 0 ]
In/Pass: [ Packets: 10 Bytes: 840 ]
Out/Block: [ Packets: 0 Bytes: 0 ]
Out/Pass: [ Packets: 10 Bytes: 840 ]
Similarly, it is possible to view global information about the tables by using the -v modifier twice and the -s Tables command. This will display the number of addresses on each table, the number of rules which reference the table, and the global packet statistics for the whole table:
# pfctl -vvsTables
--a-r-C test
Addresses: 1
Cleared: Thu Feb 13 18:55:18 2003
References: [ Anchors: 0 Rules: 1 ]
Evaluations: [ NoMatch: 3496 Match: 1 ]
In/Block: [ Packets: 0 Bytes: 0 ]
In/Pass: [ Packets: 10 Bytes: 840 ]
In/XPass: [ Packets: 0 Bytes: 0 ]
Out/Block: [ Packets: 0 Bytes: 0 ]
Out/Pass: [ Packets: 10 Bytes: 840 ]
Out/XPass: [ Packets: 0 Bytes: 0 ]
As we can see here, only one packet - the initial ping request - matched the table, but all packets passing as the result of the state are correctly accounted for. Reloading the table(s) or ruleset will not affect packet accounting in any way. The two βXPassβ counters are incremented instead of the βPassβ counters when a βstatefulβ packet is passed but does not match the table anymore. This will happen in our example if someone flushes the table while the ping(8) command is running.
When used with a single -v, pfctl will only display the first line containing the table flags and name. The flags are defined as follows:
β¦and picking up right where we left off with the flag letters β here's what each one is telling you π
cβ for constant tables, which cannot be altered outsidepf.conf(5). locked down, no touchy πpβ for persistent tables, which do not get automatically killed when no rules refer to them. they simply refuse to leave the group chat β¨aβ for tables which are part of the active tableset. heads up: tables without this flag do not really exist, cannot contain addresses, and are only listed if the-gflag is given. like, they're giving ghost energy π»iβ for tables which are part of the inactive tableset. this flag can only be witnessed briefly during the loading ofpf.conf(5), so blink and you'll miss it πrβ for tables which are referenced (used) by rules. main character behavior, honestly πhβ this flag is set when a table in the main ruleset is hidden by one or more tables of the same name from anchors attached below it. shady behavior fr fr πCβ this flag is set when per-address counters are enabled on the table. numbers girlie π
-vβ produce more verbose output. a second use of-vwill produce even more verbose output including ruleset warnings. see the previous section for its effect on table commands β yes bestie, it's a whole escalation arc π¦-xlevel β set the debug level (may be abbreviated) to one of the following:-x noneβ do not generate debug messages. silence is golden π-x urgentβ generate debug messages only for serious errors. the "call me only if it's an emergency" setting π¨-x miscβ generate debug messages for various errors.-x loudβ generate debug messages for common conditions. full volume, no indoor voice π₯
-zβ clear per-rule statistics. fresh start, clean slate, we love a reset π
πΈ FILES πΈ
/etc/pf.confβ packet filter rules file. the whole personality lives here π/etc/pf.osβ passive operating system fingerprint database. lowkey a whole detective vibe π΅οΈ
π¦ SEE ALSO π¦
pf(4), pf.conf(5), pf.os(5), rc.conf(5), services(5), sysctl.conf(5), authpf(8), ftp-proxy(8), rc(8), sysctl(8)
the whole friend group, right there β go say hi π«Ά
β HISTORY β
the pfctl program and the pf(4) filter mechanism appeared in OpenBSD 3.0. they first appeared in FreeBSD 5.3 ported from the version in OpenBSD 3.5. vintage icon behavior, no cap π
and that's a wrap on the whole page, bestie πβ¨ this edition is the Debian one, dated August 5, 2025 β screenshot it, bookmark it, tattoo it on your forearm, whatever works for you ππ«Ά
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 2001 Kjell Wooding. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms