1 .\" $OpenBSD: pfctl.8,v 1.138 2008/06/10 20:55:02 mcbride 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) device
38 .Op Fl AdeghMmNnOPqRrvz
40 .Oo Fl D Ar macro Ns =
45 .Op Fl K Ar host | network
48 .Ar host | network | label | id | gateway
63 utility communicates with the packet filter device using the
64 ioctl interface described in
66 It allows ruleset and parameter configuration and retrieval of status
67 information from the packet filter.
69 Packet filtering restricts the types of packets that pass through
70 network interfaces entering or leaving the host based on filter
73 The packet filter can also replace addresses and ports of packets.
74 Replacing source addresses and ports of outgoing packets is called
75 NAT (Network Address Translation) and is used to connect an internal
76 network (usually reserved address space) to an external one (the
77 Internet) by making all connections to external hosts appear to
78 come from the gateway.
79 Replacing destination addresses and ports of incoming packets
80 is used to redirect connections to different hosts and/or ports.
81 A combination of both translations, bidirectional NAT, is also
83 Translation rules are described in
92 the rule file specified with the variable
94 is loaded automatically by the
96 scripts and the packet filter is enabled.
98 The packet filter does not itself forward packets between interfaces.
99 Forwarding can be enabled by setting the
102 .Em net.inet.ip.forwarding
104 .Em net.inet6.ip6.forwarding
106 Set them permanently in
111 utility provides several commands.
112 The options are as follows:
115 Load only the queue rules present in the rule file.
116 Other rules and options are ignored.
123 only to the rules in the specified
125 In addition to the main ruleset,
127 can load and manipulate additional rulesets by name,
129 The main ruleset is the default anchor.
131 Anchors are referenced by name and may be nested,
132 with the various components of the anchor path separated by
134 characters, similar to how file system hierarchies are laid out.
135 The last component of the anchor path is where ruleset operations are
140 rules from the main ruleset is described in
143 For example, the following will show all filter rules (see the
145 flag below) inside the anchor
146 .Dq authpf/smith(1234) ,
147 which would have been created for user
152 .Bd -literal -offset indent
153 # pfctl -a "authpf/smith(1234)" -s rules
156 Private tables can also be put inside anchors, either by having table
159 file that is loaded in the anchor, or by using regular table commands, as in:
160 .Bd -literal -offset indent
161 # pfctl -a foo/bar -t mytable -T add 1.2.3.4 5.6.7.8
164 When a rule referring to a table is loaded in an anchor, the rule will use the
165 private table if one is defined, and then fall back to the table defined in the
166 main ruleset, if there is one.
167 This is similar to C rules for variable scope.
168 It is possible to create distinct tables with the same name in the global
169 ruleset and in an anchor, but this is often bad design and a warning will be
172 By default, recursive inline printing of anchors applies only to unnamed
173 anchors specified inline in the ruleset.
174 If the anchor name is terminated with a
178 flag will recursively print all anchors in a brace delimited block.
179 For example the following will print the
182 .Bd -literal -offset indent
183 # pfctl -a 'authpf/*' -sr
186 To print the main ruleset recursively, specify only
189 .Bd -literal -offset indent
192 .It Fl D Ar macro Ns = Ns Ar value
198 Overrides the definition of
202 Disable the packet filter.
204 Enable the packet filter.
206 Flush the filter parameters specified by
208 (may be abbreviated):
210 .Bl -tag -width xxxxxxxxxxxx -compact
214 Flush the queue rules.
216 Flush the Ethernet filter rules.
218 Flush the filter rules.
220 Flush the state table (NAT and filter).
222 Flush the source tracking table.
224 Flush the filter information (statistics that are not bound to rules).
228 Flush the passive operating system fingerprints.
230 Flush all of the above.
233 Load the rules contained in
237 may contain macros, tables, options, and normalization, queueing,
238 translation, and filtering rules.
239 With the exception of macros and tables, the statements must appear in that
242 Include output helpful for debugging.
245 .It Fl i Ar interface
246 Restrict the operation to the given
248 .It Fl K Ar host | network
249 Kill all of the source tracking entries originating from the specified
257 option may be specified, which will kill all the source tracking
258 entries from the first host/network to the second.
261 .Ar host | network | label | id | gateway
263 Kill all of the state entries matching the specified
271 For example, to kill all of the state entries originating from
280 option may be specified, which will kill all the state entries
281 from the first host/network to the second.
282 To kill all of the state entries from
287 .Dl # pfctl -k host1 -k host2
289 To kill all states originating from 192.168.1.0/24 to 172.16.0.0/16:
291 .Dl # pfctl -k 192.168.1.0/24 -k 172.16.0.0/16
293 A network prefix length of 0 can be used as a wildcard.
294 To kill all states with the target
297 .Dl # pfctl -k 0.0.0.0/0 -k host2
299 It is also possible to kill states by rule label or state ID.
300 In this mode the first
302 argument is used to specify the type
303 of the second argument.
304 The following command would kill all states that have been created
305 from rules carrying the label
308 .Dl # pfctl -k label -k foobar
310 To kill one specific state by its unique state ID
311 (as shown by pfctl -s state -vv),
314 modifier and as a second argument the state ID and optional creator ID.
315 To kill a state with ID 4823e84500000003 use:
317 .Dl # pfctl -k id -k 4823e84500000003
319 To kill a state with ID 4823e84500000018 created from a backup
320 firewall with hostid 00000002 use:
322 .Dl # pfctl -k id -k 4823e84500000018/2
324 It is also possible to kill states created from a rule with the route-to/reply-to
325 parameter set to route the connection through a particular gateway.
326 Note that rules routing via the default routing table (not via a route-to
327 rule) will have their rt_addr set as 0.0.0.0 or ::.
328 To kill all states using a gateway of 192.168.0.1 use:
330 .Dl # pfctl -k gateway -k 192.168.0.1
332 A network prefix length can also be specified.
333 To kill all states using a gateway in 192.168.0.0/24:
335 .Dl # pfctl -k gateway -k 192.168.0.0/24
338 Kill matching states in the opposite direction (on other interfaces) when
340 This applies to states killed using the -k option and also will apply to the
341 flush command when flushing states.
342 This is useful when an interface is specified when flushing states.
345 .Dl # pfctl -M -i interface -Fs
348 Merge in explicitly given options without resetting those
350 Allows single options to be modified without disturbing the others:
351 .Bd -literal -offset indent
352 # echo "set loginterface fxp0" | pfctl -mf -
355 Load only the NAT rules present in the rule file.
356 Other rules and options are ignored.
358 Do not actually load rules, just parse them.
360 Load only the options present in the rule file.
361 Other rules and options are ignored.
363 Control the ruleset optimizer, overriding any rule file settings.
365 .Bl -tag -width xxxxxxxxxxxx -compact
367 Disable the ruleset optimizer.
369 Enable basic ruleset optimizations.
370 This is the default behaviour.
372 Enable basic ruleset optimizations with profiling.
374 For further information on the ruleset optimizer, see
377 Do not perform service name lookup for port specific rules,
378 instead display the ports numerically.
382 instead of the default
385 Only print errors and warnings.
387 Load only the filter rules present in the rule file.
388 Other rules and options are ignored.
390 Perform reverse DNS lookups on states when displaying them.
392 Show the filter parameters specified by
394 (may be abbreviated):
396 .Bl -tag -width xxxxxxxxxxxxx -compact
398 Show the currently loaded NAT rules.
400 Show the currently loaded queue rules.
401 When used together with
403 per-queue statistics are also shown.
404 When used together with
407 will loop and show updated queue statistics every five seconds, including
408 measured bandwidth and packets per second.
410 Show the currently loaded Ethernet rules.
411 When used together with
413 the per-rule statistics (number of evaluations,
414 packets, and bytes) are also shown.
416 Show the currently loaded filter rules.
417 When used together with
419 the per-rule statistics (number of evaluations,
420 packets, and bytes) are also shown.
423 optimization done automatically by the kernel
424 will skip evaluation of rules where possible.
425 Packets passed statefully are counted in the rule that created the state
426 (even though the rule is not evaluated more than once for the entire
429 Show the currently loaded anchors directly attached to the main ruleset.
432 is specified as well, the anchors loaded directly below the given
437 is specified, all anchors attached under the target anchor will be
438 displayed recursively.
440 Show the contents of the state table.
442 Show the contents of the source tracking table.
444 Show filter information (statistics and counters).
445 When used together with
447 source tracking statistics are also shown.
449 Show the running status and provide a non-zero exit status when disabled.
451 Show per-rule statistics (label, evaluations, packets total, bytes total,
452 packets in, bytes in, packets out, bytes out, state creations) of
453 filter rules with labels, useful for accounting.
455 Show the current global timeouts.
457 Show the current pool memory hard limits.
459 Show the list of tables.
461 Show the list of operating system fingerprints.
462 .It Fl s Cm Interfaces
463 Show the list of interfaces and interface drivers available to PF.
464 When used together with
466 it additionally lists which interfaces have skip rules activated.
467 When used together with
469 interface statistics are also shown.
471 can be used to select an interface or a group of interfaces.
473 Show all of the above, except for the lists of interfaces and operating
476 .It Fl T Ar command Op Ar address ...
479 (may be abbreviated) to apply to the table.
482 .Bl -tag -width xxxxxxxxxxxx -compact
486 Flush all addresses of a table.
488 Add one or more addresses in a table.
489 Automatically create a nonexisting table.
491 Delete one or more addresses from a table.
492 .It Fl T Cm expire Ar number
493 Delete addresses which had their statistics cleared more than
496 For entries which have never had their statistics cleared,
498 refers to the time they were added to the table.
500 Replace the addresses of the table.
501 Automatically create a nonexisting table.
503 Show the content (addresses) of a table.
505 Test if the given addresses match a table.
507 Clear all the statistics of a table.
509 Load only the table definitions from
511 This is used in conjunction with the
514 .Bd -literal -offset indent
515 # pfctl -Tl -f pf.conf
525 commands, the list of addresses can be specified either directly on the command
526 line and/or in an unformatted text file, using the
529 Comments starting with a
531 are allowed in the text file.
532 With these commands, the
534 flag can also be used once or twice, in which case
537 detailed result of the operation for each individual address, prefixed by
538 one of the following letters:
540 .Bl -tag -width XXX -compact
542 The address/network has been added.
544 The address/network has been changed (negated).
546 The address/network has been deleted.
554 The address/network is duplicated and therefore ignored.
556 The address/network cannot be added/deleted due to conflicting
560 The address/network has been cleared (statistics).
563 Each table can maintain a set of counters that can be retrieved using the
567 For example, the following commands define a wide open firewall which will keep
568 track of packets going to or coming from the
571 The following commands configure the firewall and send 10 pings to the FTP
573 .Bd -literal -offset indent
574 # printf "table <test> counters { ftp.openbsd.org }\en \e
575 pass out to <test>\en" | pfctl -f-
576 # ping -qc10 ftp.openbsd.org
579 We can now use the table
581 command to output, for each address and packet direction, the number of packets
582 and bytes that are being passed or blocked by rules referencing the table.
583 The time at which the current accounting started is also shown with the
586 .Bd -literal -offset indent
587 # pfctl -t test -vTshow
589 Cleared: Thu Feb 13 18:55:18 2003
590 In/Block: [ Packets: 0 Bytes: 0 ]
591 In/Pass: [ Packets: 10 Bytes: 840 ]
592 Out/Block: [ Packets: 0 Bytes: 0 ]
593 Out/Pass: [ Packets: 10 Bytes: 840 ]
596 Similarly, it is possible to view global information about the tables
599 modifier twice and the
603 This will display the number of addresses on each table,
604 the number of rules which reference the table, and the global
605 packet statistics for the whole table:
606 .Bd -literal -offset indent
610 Cleared: Thu Feb 13 18:55:18 2003
611 References: [ Anchors: 0 Rules: 1 ]
612 Evaluations: [ NoMatch: 3496 Match: 1 ]
613 In/Block: [ Packets: 0 Bytes: 0 ]
614 In/Pass: [ Packets: 10 Bytes: 840 ]
615 In/XPass: [ Packets: 0 Bytes: 0 ]
616 Out/Block: [ Packets: 0 Bytes: 0 ]
617 Out/Pass: [ Packets: 10 Bytes: 840 ]
618 Out/XPass: [ Packets: 0 Bytes: 0 ]
621 As we can see here, only one packet \- the initial ping request \- matched the
622 table, but all packets passing as the result of the state are correctly
624 Reloading the table(s) or ruleset will not affect packet accounting in any way.
627 counters are incremented instead of the
631 packet is passed but does not match the table anymore.
632 This will happen in our example if someone flushes the table while the
636 When used with a single
639 will only display the first line containing the table flags and name.
640 The flags are defined as follows:
642 .Bl -tag -width XXX -compact
644 For constant tables, which cannot be altered outside
647 For persistent tables, which do not get automatically killed when no rules
650 For tables which are part of the
653 Tables without this flag do not really exist, cannot contain addresses, and are
658 For tables which are part of the
661 This flag can only be witnessed briefly during the loading of
664 For tables which are referenced (used) by rules.
666 This flag is set when a table in the main ruleset is hidden by one or more
667 tables of the same name from anchors attached below it.
669 This flag is set when per-address counters are enabled on the table.
672 Specify the name of the table.
674 Produce more verbose output.
677 will produce even more verbose output including ruleset warnings.
678 See the previous section for its effect on table commands.
682 (may be abbreviated) to one of the following:
684 .Bl -tag -width xxxxxxxxxxxx -compact
686 Do not generate debug messages.
688 Generate debug messages only for serious errors.
690 Generate debug messages for various errors.
692 Generate debug messages for common conditions.
695 Clear per-rule statistics.
698 .Bl -tag -width "/etc/pf.conf" -compact
700 Packet filter rules file.
702 Passive operating system fingerprint database.
720 filter mechanism appeared in
722 They first appeared in
724 ported from the version in