1 .\" $OpenBSD: pfctl.8,v 1.118 2005/01/05 23:41:45 jmc Exp $
3 .\" Copyright (c) 2001 Kjell Wooding. All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. The name of the author may not be used to endorse or promote products
14 .\" derived from this software without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 .Nd "control the packet filter (PF) and network address translation (NAT) device"
38 .Op Fl AdeghmNnOoqRrvz
42 .Ar macro Ns = Ns Ar value Oc
60 utility communicates with the packet filter device using the
61 ioctl interface described in
63 It allows ruleset and parameter configuration and retrieval of status
64 information from the packet filter.
66 Packet filtering restricts the types of packets that pass through
67 network interfaces entering or leaving the host based on filter
70 The packet filter can also replace addresses and ports of packets.
71 Replacing source addresses and ports of outgoing packets is called
72 NAT (Network Address Translation) and is used to connect an internal
73 network (usually reserved address space) to an external one (the
74 Internet) by making all connections to external hosts appear to
75 come from the gateway.
76 Replacing destination addresses and ports of incoming packets
77 is used to redirect connections to different hosts and/or ports.
78 A combination of both translations, bidirectional NAT, is also
80 Translation rules are described in
89 the rule file specified with the variable
91 is loaded automatically by the
93 scripts and the packet filter is enabled.
95 The packet filter does not itself forward packets between interfaces.
96 Forwarding can be enabled by setting the
99 .Em net.inet.ip.forwarding
101 .Em net.inet6.ip6.forwarding
103 Set them permanently in
108 utility provides several commands.
109 The options are as follows:
112 Load only the queue rules present in the rule file.
113 Other rules and options are ignored.
120 only to the rules in the specified
122 In addition to the main ruleset,
124 can load and manipulate additional rulesets by name,
126 The main ruleset is the default anchor.
128 Anchors are referenced by name and may be nested,
129 with the various components of the anchor path separated by
131 characters, similar to how file system hierarchies are laid out.
132 The last component of the anchor path is where ruleset operations are
137 rules from the main ruleset is described in
140 For example, the following will show all filter rules (see the
142 flag below) inside the anchor
143 .Li authpf/smith(1234) ,
144 which would have been created for user smith by
147 .Bd -literal -offset indent
148 # pfctl -a "authpf/smith(1234)" -s rules
151 Private tables can also be put inside anchors, either by having table
154 file that is loaded in the anchor, or by using regular table commands, as in:
155 .Bd -literal -offset indent
156 # pfctl -a foo/bar -t mytable -T add 1.2.3.4 5.6.7.8
159 When a rule referring to a table is loaded in an anchor, the rule will use the
160 private table if one is defined, and then fall back to the table defined in the
161 main ruleset, if there is one.
162 This is similar to C rules for variable scope.
163 It is possible to create distinct tables with the same name in the global
164 ruleset and in an anchor, but this is often bad design and a warning will be
166 .It Fl D Ar macro Ns = Ns Ar value
172 Overrides the definition of
176 Disable the packet filter.
178 Enable the packet filter.
180 Flush the filter parameters specified by
182 (may be abbreviated):
184 .Bl -tag -width xxxxxxxxxxxx -compact
188 Flush the queue rules.
190 Flush the filter rules.
192 Flush the state table (NAT and filter).
194 Flush the source tracking table.
196 Flush the filter information (statistics that are not bound to rules).
200 Flush the passive operating system fingerprints.
202 Flush all of the above.
205 Load the rules contained in
209 may contain macros, tables, options, and normalization, queueing,
210 translation, and filtering rules.
211 With the exception of macros and tables, the statements must appear in that
214 Include output helpful for debugging.
217 .It Fl i Ar interface
218 Restrict the operation to the given
221 Kill all of the state entries originating from the specified
225 option may be specified, which will kill all the state entries
230 For example, to kill all of the state entries originating from
232 .Bd -literal -offset indent
236 To kill all of the state entries from
240 .Bd -literal -offset indent
241 # pfctl -k host1 -k host2
244 Merge in explicitly given options without resetting those
246 Allows single options to be modified without disturbing the others:
247 .Bd -literal -offset indent
248 # echo "set loginterface fxp0" | pfctl -mf -
251 Load only the NAT rules present in the rule file.
252 Other rules and options are ignored.
254 Do not actually load rules, just parse them.
256 Load only the options present in the rule file.
257 Other rules and options are ignored.
259 Enable the ruleset optimizer.
260 The ruleset optimizer attempts to improve rulesets by removing rule
261 duplication and making better use of rule ordering.
262 Specifically, it does four things:
266 remove duplicate rules
268 remove rules that are a subset of another rule
270 combine multiple rules into a table when advantageous
272 re-order the rules to improve evaluation performance
277 may be specified to use the currently loaded ruleset as a feedback profile
278 to tailor the optimization of the
280 rules to the actual network behavior.
282 It is important to note that the ruleset optimizer will modify the ruleset
283 to improve performance.
284 A side effect of the ruleset modification is that per-rule accounting
285 statistics will have different meanings than before.
286 If per-rule accounting is important for billing purposes or whatnot, either
287 the ruleset optimizer should not be used or a
289 field should be added to all of the accounting rules to act as optimization
294 instead of the default
297 Only print errors and warnings.
299 Load only the filter rules present in the rule file.
300 Other rules and options are ignored.
302 Perform reverse DNS lookups on states when displaying them.
304 Show the filter parameters specified by
306 (may be abbreviated):
308 .Bl -tag -width xxxxxxxxxxxxx -compact
310 Show the currently loaded NAT rules.
312 Show the currently loaded queue rules.
313 When used together with
315 per-queue statistics are also shown.
316 When used together with
319 will loop and show updated queue statistics every five seconds, including
320 measured bandwidth and packets per second.
322 Show the currently loaded filter rules.
323 When used together with
325 the per-rule statistics (number of evaluations,
326 packets and bytes) are also shown.
329 optimization done automatically by the kernel
330 will skip evaluation of rules where possible.
331 Packets passed statefully are counted in the rule that created the state
332 (even though the rule isn't evaluated more than once for the entire
335 Show the currently loaded anchors directly attached to the main ruleset.
338 is specified as well, the anchors loaded directly below the given
343 is specified, all anchors attached under the target anchor will be
344 displayed recursively.
346 Show the contents of the state table.
348 Show the contents of the source tracking table.
350 Show filter information (statistics and counters).
351 When used together with
353 source tracking statistics are also shown.
355 Show per-rule statistics (label, evaluations, packets, bytes) of
356 filter rules with labels, useful for accounting.
358 Show the current global timeouts.
360 Show the current pool memory hard limits.
362 Show the list of tables.
364 Show the list of operating system fingerprints.
365 .It Fl s Cm Interfaces
366 Show the list of interfaces and interface drivers available to PF.
367 When used together with a double
369 interface statistics are also shown.
371 can be used to select an interface or a group of interfaces.
373 Show all of the above, except for the lists of interfaces and operating
376 .It Fl T Ar command Op Ar address ...
379 (may be abbreviated) to apply to the table.
382 .Bl -tag -width xxxxxxxxxxxx -compact
386 Flush all addresses of a table.
388 Add one or more addresses in a table.
389 Automatically create a nonexisting table.
391 Delete one or more addresses from a table.
393 Replace the addresses of the table.
394 Automatically create a nonexisting table.
396 Show the content (addresses) of a table.
398 Test if the given addresses match a table.
400 Clear all the statistics of a table.
402 Load only the table definitions from
404 This is used in conjunction with the
407 .Bd -literal -offset indent
408 # pfctl -Tl -f pf.conf
418 commands, the list of addresses can be specified either directly on the command
419 line and/or in an unformatted text file, using the
422 Comments starting with a
424 are allowed in the text file.
425 With these commands, the
427 flag can also be used once or twice, in which case
430 detailed result of the operation for each individual address, prefixed by
431 one of the following letters:
433 .Bl -tag -width XXX -compact
435 The address/network has been added.
437 The address/network has been changed (negated).
439 The address/network has been deleted.
447 The address/network is duplicated and therefore ignored.
449 The address/network cannot be added/deleted due to conflicting
453 The address/network has been cleared (statistics).
456 Each table maintains a set of counters that can be retrieved using the
460 For example, the following commands define a wide open firewall which will keep
461 track of packets going to or coming from the
464 The following commands configure the firewall and send 10 pings to the FTP
466 .Bd -literal -offset indent
467 # printf "table <test> { ftp.openbsd.org }\en \e
468 pass out to <test> keep state\en" | pfctl -f-
469 # ping -qc10 ftp.openbsd.org
472 We can now use the table
474 command to output, for each address and packet direction, the number of packets
475 and bytes that are being passed or blocked by rules referencing the table.
476 The time at which the current accounting started is also shown with the
479 .Bd -literal -offset indent
480 # pfctl -t test -vTshow
482 Cleared: Thu Feb 13 18:55:18 2003
483 In/Block: [ Packets: 0 Bytes: 0 ]
484 In/Pass: [ Packets: 10 Bytes: 840 ]
485 Out/Block: [ Packets: 0 Bytes: 0 ]
486 Out/Pass: [ Packets: 10 Bytes: 840 ]
489 Similarly, it is possible to view global information about the tables
492 modifier twice and the
496 This will display the number of addresses on each table,
497 the number of rules which reference the table, and the global
498 packet statistics for the whole table:
499 .Bd -literal -offset indent
503 Cleared: Thu Feb 13 18:55:18 2003
504 References: [ Anchors: 0 Rules: 1 ]
505 Evaluations: [ NoMatch: 3496 Match: 1 ]
506 In/Block: [ Packets: 0 Bytes: 0 ]
507 In/Pass: [ Packets: 10 Bytes: 840 ]
508 In/XPass: [ Packets: 0 Bytes: 0 ]
509 Out/Block: [ Packets: 0 Bytes: 0 ]
510 Out/Pass: [ Packets: 10 Bytes: 840 ]
511 Out/XPass: [ Packets: 0 Bytes: 0 ]
514 As we can see here, only one packet \- the initial ping request \- matched the
515 table, but all packets passing as the result of the state are correctly
517 Reloading the table(s) or ruleset will not affect packet accounting in any way.
520 counters are incremented instead of the
524 packet is passed but doesn't match the table anymore.
525 This will happen in our example if someone flushes the table while the
529 When used with a single
532 will only display the first line containing the table flags and name.
533 The flags are defined as follows:
535 .Bl -tag -width XXX -compact
537 For constant tables, which cannot be altered outside
540 For persistent tables, which don't get automatically killed when no rules
543 For tables which are part of the
546 Tables without this flag do not really exist, cannot contain addresses, and are
551 For tables which are part of the
554 This flag can only be witnessed briefly during the loading of
557 For tables which are referenced (used) by rules.
559 This flag is set when a table in the main ruleset is hidden by one or more
560 tables of the same name from anchors attached below it.
563 Specify the name of the table.
565 Produce more verbose output.
568 will produce even more verbose output including ruleset warnings.
569 See the previous section for its effect on table commands.
573 (may be abbreviated) to one of the following:
575 .Bl -tag -width xxxxxxxxxxxx -compact
577 Don't generate debug messages.
579 Generate debug messages only for serious errors.
581 Generate debug messages for various errors.
583 Generate debug messages for common conditions.
586 Clear per-rule statistics.
589 .Bl -tag -width "/etc/pf.conf" -compact
591 Packet filter rules file.
593 Passive operating system fingerprint database.
610 filter mechanism first appeared in