1 .\" $OpenBSD: pfctl.8,v 1.128 2007/01/30 21:01:56 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.
32 .Nd "control the packet filter (PF) and network address translation (NAT) device"
38 .Oo Fl D Ar macro Ns =
43 .Op Fl K Ar host | network
44 .Op Fl k Ar host | network
58 utility communicates with the packet filter device using the
59 ioctl interface described in
61 It allows ruleset and parameter configuration and retrieval of status
62 information from the packet filter.
64 Packet filtering restricts the types of packets that pass through
65 network interfaces entering or leaving the host based on filter
68 The packet filter can also replace addresses and ports of packets.
69 Replacing source addresses and ports of outgoing packets is called
70 NAT (Network Address Translation) and is used to connect an internal
71 network (usually reserved address space) to an external one (the
72 Internet) by making all connections to external hosts appear to
73 come from the gateway.
74 Replacing destination addresses and ports of incoming packets
75 is used to redirect connections to different hosts and/or ports.
76 A combination of both translations, bidirectional NAT, is also
78 Translation rules are described in
87 the rule file specified with the variable
89 is loaded automatically by the
91 scripts and the packet filter is enabled.
93 The packet filter does not itself forward packets between interfaces.
94 Forwarding can be enabled by setting the
97 .Em net.inet.ip.forwarding
99 .Em net.inet6.ip6.forwarding
101 Set them permanently in
106 utility provides several commands.
107 The options are as follows:
110 Load only the queue rules present in the rule file.
111 Other rules and options are ignored.
118 only to the rules in the specified
120 In addition to the main ruleset,
122 can load and manipulate additional rulesets by name,
124 The main ruleset is the default anchor.
126 Anchors are referenced by name and may be nested,
127 with the various components of the anchor path separated by
129 characters, similar to how file system hierarchies are laid out.
130 The last component of the anchor path is where ruleset operations are
135 rules from the main ruleset is described in
138 For example, the following will show all filter rules (see the
140 flag below) inside the anchor
141 .Dq authpf/smith(1234) ,
142 which would have been created for user
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
167 By default, recursive inline printing of anchors applies only to unnamed
168 anchors specified inline in the ruleset.
169 If the anchor name is terminated with a
173 flag will recursively print all anchors in a brace delimited block.
174 For example the following will print the
177 .Bd -literal -offset indent
178 # pfctl -a 'authpf/*' -sr
181 To print the main ruleset recursively, specify only
184 .Bd -literal -offset indent
187 .It Fl D Ar macro Ns = Ns Ar value
193 Overrides the definition of
197 Disable the packet filter.
199 Enable the packet filter.
201 Flush the filter parameters specified by
203 (may be abbreviated):
205 .Bl -tag -width xxxxxxxxxxxx -compact
209 Flush the queue rules.
211 Flush the filter rules.
213 Flush the state table (NAT and filter).
215 Flush the source tracking table.
217 Flush the filter information (statistics that are not bound to rules).
221 Flush the passive operating system fingerprints.
223 Flush all of the above.
226 Load the rules contained in
230 may contain macros, tables, options, and normalization, queueing,
231 translation, and filtering rules.
232 With the exception of macros and tables, the statements must appear in that
235 Include output helpful for debugging.
238 .It Fl i Ar interface
239 Restrict the operation to the given
241 .It Fl K Ar host | network
242 Kill all of the source tracking entries originating from the specified
250 option may be specified, which will kill all the source tracking
251 entries from the first host/network to the second.
252 .It Fl k Ar host | network
253 Kill all of the state entries originating from the specified
261 option may be specified, which will kill all the state entries
262 from the first host/network to the second.
263 For example, to kill all of the state entries originating from
268 To kill all of the state entries from
273 .Dl # pfctl -k host1 -k host2
275 To kill all states originating from 192.168.1.0/24 to 172.16.0.0/16:
277 .Dl # pfctl -k 192.168.1.0/24 -k 172.16.0.0/16
279 A network prefix length of 0 can be used as a wildcard.
280 To kill all states with the target
283 .Dl # pfctl -k 0.0.0.0/0 -k host2
285 Merge in explicitly given options without resetting those
287 Allows single options to be modified without disturbing the others:
288 .Bd -literal -offset indent
289 # echo "set loginterface fxp0" | pfctl -mf -
292 Load only the NAT rules present in the rule file.
293 Other rules and options are ignored.
295 Do not actually load rules, just parse them.
297 Load only the options present in the rule file.
298 Other rules and options are ignored.
300 Control the ruleset optimizer.
301 The ruleset optimizer attempts to improve rulesets by removing rule
302 duplication and making better use of rule ordering.
304 .Bl -tag -width xxxxxxxxxxxx -compact
306 Disable the ruleset optimizer.
308 Enable basic ruleset optimizations.
310 Enable basic ruleset optimizations with profiling.
314 optimization does does four things:
318 remove duplicate rules
320 remove rules that are a subset of another rule
322 combine multiple rules into a table when advantageous
324 re-order the rules to improve evaluation performance
329 is specified, the currently loaded ruleset will be examined as a feedback
330 profile to tailor the optimization of the
332 rules to the actual network behavior.
334 It is important to note that the ruleset optimizer will modify the ruleset
335 to improve performance.
336 A side effect of the ruleset modification is that per-rule accounting
337 statistics will have different meanings than before.
338 If per-rule accounting is important for billing purposes or whatnot, either
339 the ruleset optimizer should not be used or a
341 field should be added to all of the accounting rules to act as optimization
344 To retain compatibility with previous behaviour, a single
346 without any options will enable
348 optimizations, and a second
350 will enable profiling.
354 instead of the default
357 Only print errors and warnings.
359 Load only the filter rules present in the rule file.
360 Other rules and options are ignored.
362 Perform reverse DNS lookups on states when displaying them.
364 Show the filter parameters specified by
366 (may be abbreviated):
368 .Bl -tag -width xxxxxxxxxxxxx -compact
370 Show the currently loaded NAT rules.
372 Show the currently loaded queue rules.
373 When used together with
375 per-queue statistics are also shown.
376 When used together with
379 will loop and show updated queue statistics every five seconds, including
380 measured bandwidth and packets per second.
382 Show the currently loaded filter rules.
383 When used together with
385 the per-rule statistics (number of evaluations,
386 packets and bytes) are also shown.
389 optimization done automatically by the kernel
390 will skip evaluation of rules where possible.
391 Packets passed statefully are counted in the rule that created the state
392 (even though the rule isn't evaluated more than once for the entire
395 Show the currently loaded anchors directly attached to the main ruleset.
398 is specified as well, the anchors loaded directly below the given
403 is specified, all anchors attached under the target anchor will be
404 displayed recursively.
406 Show the contents of the state table.
408 Show the contents of the source tracking table.
410 Show filter information (statistics and counters).
411 When used together with
413 source tracking statistics are also shown.
415 Show per-rule statistics (label, evaluations, packets total, bytes total,
416 packets in, bytes in, packets out, bytes out) of
417 filter rules with labels, useful for accounting.
419 Show the current global timeouts.
421 Show the current pool memory hard limits.
423 Show the list of tables.
425 Show the list of operating system fingerprints.
426 .It Fl s Cm Interfaces
427 Show the list of interfaces and interface drivers available to PF.
428 When used together with
430 it additionally lists which interfaces have skip rules activated.
431 When used together with
433 interface statistics are also shown.
435 can be used to select an interface or a group of interfaces.
437 Show all of the above, except for the lists of interfaces and operating
440 .It Fl T Ar command Op Ar address ...
443 (may be abbreviated) to apply to the table.
446 .Bl -tag -width xxxxxxxxxxxx -compact
450 Flush all addresses of a table.
452 Add one or more addresses in a table.
453 Automatically create a nonexisting table.
455 Delete one or more addresses from a table.
456 .It Fl T Cm expire Ar number
457 Delete addresses which had their statistics cleared more than
460 For entries which have never had their statistics cleared,
462 refers to the time they were added to the table.
464 Replace the addresses of the table.
465 Automatically create a nonexisting table.
467 Show the content (addresses) of a table.
469 Test if the given addresses match a table.
471 Clear all the statistics of a table.
473 Load only the table definitions from
475 This is used in conjunction with the
478 .Bd -literal -offset indent
479 # pfctl -Tl -f pf.conf
489 commands, the list of addresses can be specified either directly on the command
490 line and/or in an unformatted text file, using the
493 Comments starting with a
495 are allowed in the text file.
496 With these commands, the
498 flag can also be used once or twice, in which case
501 detailed result of the operation for each individual address, prefixed by
502 one of the following letters:
504 .Bl -tag -width XXX -compact
506 The address/network has been added.
508 The address/network has been changed (negated).
510 The address/network has been deleted.
518 The address/network is duplicated and therefore ignored.
520 The address/network cannot be added/deleted due to conflicting
524 The address/network has been cleared (statistics).
527 Each table maintains a set of counters that can be retrieved using the
531 For example, the following commands define a wide open firewall which will keep
532 track of packets going to or coming from the
535 The following commands configure the firewall and send 10 pings to the FTP
537 .Bd -literal -offset indent
538 # printf "table <test> { ftp.openbsd.org }\en \e
539 pass out to <test>\en" | pfctl -f-
540 # ping -qc10 ftp.openbsd.org
543 We can now use the table
545 command to output, for each address and packet direction, the number of packets
546 and bytes that are being passed or blocked by rules referencing the table.
547 The time at which the current accounting started is also shown with the
550 .Bd -literal -offset indent
551 # pfctl -t test -vTshow
553 Cleared: Thu Feb 13 18:55:18 2003
554 In/Block: [ Packets: 0 Bytes: 0 ]
555 In/Pass: [ Packets: 10 Bytes: 840 ]
556 Out/Block: [ Packets: 0 Bytes: 0 ]
557 Out/Pass: [ Packets: 10 Bytes: 840 ]
560 Similarly, it is possible to view global information about the tables
563 modifier twice and the
567 This will display the number of addresses on each table,
568 the number of rules which reference the table, and the global
569 packet statistics for the whole table:
570 .Bd -literal -offset indent
574 Cleared: Thu Feb 13 18:55:18 2003
575 References: [ Anchors: 0 Rules: 1 ]
576 Evaluations: [ NoMatch: 3496 Match: 1 ]
577 In/Block: [ Packets: 0 Bytes: 0 ]
578 In/Pass: [ Packets: 10 Bytes: 840 ]
579 In/XPass: [ Packets: 0 Bytes: 0 ]
580 Out/Block: [ Packets: 0 Bytes: 0 ]
581 Out/Pass: [ Packets: 10 Bytes: 840 ]
582 Out/XPass: [ Packets: 0 Bytes: 0 ]
585 As we can see here, only one packet \- the initial ping request \- matched the
586 table, but all packets passing as the result of the state are correctly
588 Reloading the table(s) or ruleset will not affect packet accounting in any way.
591 counters are incremented instead of the
595 packet is passed but doesn't match the table anymore.
596 This will happen in our example if someone flushes the table while the
600 When used with a single
603 will only display the first line containing the table flags and name.
604 The flags are defined as follows:
606 .Bl -tag -width XXX -compact
608 For constant tables, which cannot be altered outside
611 For persistent tables, which don't get automatically killed when no rules
614 For tables which are part of the
617 Tables without this flag do not really exist, cannot contain addresses, and are
622 For tables which are part of the
625 This flag can only be witnessed briefly during the loading of
628 For tables which are referenced (used) by rules.
630 This flag is set when a table in the main ruleset is hidden by one or more
631 tables of the same name from anchors attached below it.
634 Specify the name of the table.
636 Produce more verbose output.
639 will produce even more verbose output including ruleset warnings.
640 See the previous section for its effect on table commands.
644 (may be abbreviated) to one of the following:
646 .Bl -tag -width xxxxxxxxxxxx -compact
648 Don't generate debug messages.
650 Generate debug messages only for serious errors.
652 Generate debug messages for various errors.
654 Generate debug messages for common conditions.
657 Clear per-rule statistics.
660 .Bl -tag -width "/etc/pf.conf" -compact
662 Packet filter rules file.
664 Passive operating system fingerprint database.
681 filter mechanism first appeared in