Main index | Section 8 | Options |
Packet filtering restricts the types of packets that pass through network interfaces entering or leaving 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 is 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 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.
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).
The pfctl utility provides several commands. The options are as follows:
| |
Load only the queue rules present in the rule file. Other rules and options are ignored. | |
| |
Apply flags
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
# 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
# pfctl -a 'authpf/*' -sr To print the main ruleset recursively, specify only '*' as the anchor name: # pfctl -a '*' -sr | |
| |
Define macro to be set to value on the command line. Overrides the definition of macro in the ruleset. | |
| |
Disable the packet filter. | |
| |
Enable the packet filter. | |
| |
Flush the filter parameters specified by
modifier
(may be abbreviated):
| |
| Flush the NAT rules. |
| |
Flush the queue rules. | |
| |
Flush the filter rules. | |
| |
Flush the state table (NAT and filter). | |
| |
Flush the source tracking table. | |
| |
Flush the filter information (statistics that are not bound to rules). | |
| |
Flush the tables. | |
| |
Flush the passive operating system fingerprints. | |
| Flush all of the above. |
| |
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. | |
| Include output helpful for debugging. |
| Help. |
| |
Restrict the operation to the given interface. | |
| |
Kill all of the source tracking entries originating from the specified
host
or
network.
A second
| |
For example, to kill all of the state entries originating from "host":
# pfctl -k host
A second
# 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 or state ID.
In this mode the first
# pfctl -k label -k foobar
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
| |
|
Kill matching states in the opposite direction (on other interfaces) when
killing states.
This applies to states killed using the -k option 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
|
|
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 - |
| Load only the NAT rules present in the rule file. Other rules and options are ignored. |
| Do not actually load rules, just parse them. |
| Load only the options present in the rule file. Other rules and options are ignored. |
| |
Control the ruleset optimizer, overriding any rule file settings.
| |
| |
Disable the ruleset optimizer. | |
| |
Enable basic ruleset optimizations. This is the default behaviour. | |
| |
Enable basic ruleset optimizations with profiling. | |
| Do not perform service name lookup for port specific rules, instead display the ports numerically. |
| |
Use the device file device instead of the default /dev/pf. | |
| Only print errors and warnings. |
| Load only the filter rules present in the rule file. Other rules and options are ignored. |
| Perform reverse DNS lookups on states when displaying them. |
| |
Show the filter parameters specified by
modifier
(may be abbreviated):
| |
| Show the currently loaded NAT rules. |
| |
Show the currently loaded queue rules.
When used together with
| |
| |
Show the currently loaded filter rules.
When used together with
| |
| |
Show the currently loaded anchors directly attached to the main ruleset.
If
| |
| |
Show the contents of the state table. | |
| |
Show the contents of the source tracking table. | |
|
Show filter information (statistics and counters).
When used together with
|
| |
Show the running status and provide a non-zero exit status when disabled. | |
| |
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. | |
| |
Show the current global timeouts. | |
| |
Show the current pool memory hard limits. | |
| |
Show the list of tables. | |
| Show the list of operating system fingerprints. |
| |
Show the list of interfaces and interface drivers available to PF.
When used together with
| |
| Show all of the above, except for the lists of interfaces and operating system fingerprints. |
| |
Specify the
command
(may be abbreviated) to apply to the table.
Commands include:
| |
| |
Kill a table. | |
| |
Flush all addresses of a table. | |
| Add one or more addresses in a table. Automatically create a nonexisting table. |
| |
Delete one or more addresses from a table. | |
| |
Delete addresses which had their statistics cleared more than number seconds ago. For entries which have never had their statistics cleared, number refers to the time they were added to the table. | |
| |
Replace the addresses of the table. Automatically create a nonexisting table. | |
| |
Show the content (addresses) of a table. | |
| |
Test if the given addresses match a table. | |
| |
Clear all the statistics of a table. | |
| |
Load only the table definitions from
pf.conf(5).
This is used in conjunction with the
# 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
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 'amp;!' attributes. |
Z | The address/network has been cleared (statistics). |
Each table can maintain a set of counters that can be retrieved using the
# 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
# 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
c | For constant tables, which cannot be altered outside pf.conf(5). |
p | For persistent tables, which do not get automatically killed when no rules refer to them. |
a |
For tables which are part of the
active
tableset.
Tables without this flag do not really exist, cannot contain addresses, and are
only listed if the
|
i | For tables which are part of the inactive tableset. This flag can only be witnessed briefly during the loading of pf.conf(5). |
r | For tables which are referenced (used) by rules. |
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. |
C | This flag is set when per-address counters are enabled on the table. |
| |
Specify the name of the table. | |
| |
Produce more verbose output.
A second use of
| |
| |
Set the debug
level
(may be abbreviated) to one of the following:
| |
| |
Do not generate debug messages. | |
| |
Generate debug messages only for serious errors. | |
| |
Generate debug messages for various errors. | |
| |
Generate debug messages for common conditions. | |
| Clear per-rule statistics. |
/etc/pf.conf | |
Packet filter rules file. | |
/etc/pf.os | Passive operating system fingerprint database. |
PFCTL (8) | October 3, 2016 |
Main index | Section 8 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | … one of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs. | ” |
— Robert Firth |