1 .\" $NetBSD: pfctl.8,v 1.8 2009/03/21 00:15:54 perry Exp $
2 .\" $OpenBSD: pfctl.8,v 1.133 2007/07/01 11:38:51 henning Exp $
4 .\" Copyright (c) 2001 Kjell Wooding. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. The name of the author may not be used to endorse or promote products
15 .\" derived from this software without specific prior written permission.
17 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 .Nd "control the packet filter (PF) and network address translation (NAT) device"
39 .Oo Fl D Ar macro Ns =
44 .Op Fl K Ar host | network
45 .Op Fl k Ar host | network
59 utility communicates with the packet filter device using the
60 ioctl interface described in
62 It allows ruleset and parameter configuration and retrieval of status
63 information from the packet filter.
65 Packet filtering restricts the types of packets that pass through
66 network interfaces entering or leaving the host based on filter
69 The packet filter can also replace addresses and ports of packets.
70 Replacing source addresses and ports of outgoing packets is called
71 NAT (Network Address Translation) and is used to connect an internal
72 network (usually reserved address space) to an external one (the
73 Internet) by making all connections to external hosts appear to
74 come from the gateway.
75 Replacing destination addresses and ports of incoming packets
76 is used to redirect connections to different hosts and/or ports.
77 A combination of both translations, bidirectional NAT, is also
79 Translation rules are described in
88 the rule file specified with the variable
90 is loaded automatically by the
92 scripts and the packet filter is enabled.
94 The packet filter does not itself forward packets between interfaces.
95 Forwarding can be enabled by setting the
98 .Em net.inet.ip.forwarding
100 .Em net.inet6.ip6.forwarding
102 Set them permanently in
103 .Pa /etc/sysctl.conf .
107 utility provides several commands.
108 The options are as follows:
111 Load only the queue rules present in the rule file.
112 Other rules and options are ignored.
119 only to the rules in the specified
121 In addition to the main ruleset,
123 can load and manipulate additional rulesets by name,
125 The main ruleset is the default anchor.
127 Anchors are referenced by name and may be nested,
128 with the various components of the anchor path separated by
130 characters, similar to how file system hierarchies are laid out.
131 The last component of the anchor path is where ruleset operations are
136 rules from the main ruleset is described in
139 For example, the following will show all filter rules (see the
141 flag below) inside the anchor
142 .Dq authpf/smith(1234) ,
143 which would have been created for user
148 .Bd -literal -offset indent
149 # pfctl -a "authpf/smith(1234)" -s rules
152 Private tables can also be put inside anchors, either by having table
155 file that is loaded in the anchor, or by using regular table commands, as in:
156 .Bd -literal -offset indent
157 # pfctl -a foo/bar -t mytable -T add 1.2.3.4 5.6.7.8
160 When a rule referring to a table is loaded in an anchor, the rule will use the
161 private table if one is defined, and then fall back to the table defined in the
162 main ruleset, if there is one.
163 This is similar to C rules for variable scope.
164 It is possible to create distinct tables with the same name in the global
165 ruleset and in an anchor, but this is often bad design and a warning will be
168 By default, recursive inline printing of anchors applies only to unnamed
169 anchors specified inline in the ruleset.
170 If the anchor name is terminated with a
174 flag will recursively print all anchors in a brace delimited block.
175 For example the following will print the
178 .Bd -literal -offset indent
179 # pfctl -a 'authpf/*' -sr
182 To print the main ruleset recursively, specify only
185 .Bd -literal -offset indent
188 .It Fl D Ar macro Ns = Ns Ar value
194 Overrides the definition of
198 Disable the packet filter.
200 Enable the packet filter.
202 Flush the filter parameters specified by
204 (may be abbreviated):
206 .Bl -tag -width xxxxxxxxxxxx -compact
210 Flush the queue rules.
212 Flush the filter rules.
214 Flush the state table (NAT and filter).
216 Flush the source tracking table.
218 Flush the filter information (statistics that are not bound to rules).
222 Flush the passive operating system fingerprints.
224 Flush all of the above.
227 Load the rules contained in
231 may contain macros, tables, options, and normalization, queueing,
232 translation, and filtering rules.
233 With the exception of macros and tables, the statements must appear in that
236 Include output helpful for debugging.
239 .It Fl i Ar interface
240 Restrict the operation to the given
242 .It Fl K Ar host | network
243 Kill all of the source tracking entries originating from the specified
251 option may be specified, which will kill all the source tracking
252 entries from the first host/network to the second.
253 .It Fl k Ar host | network
254 Kill all of the state entries originating from the specified
262 option may be specified, which will kill all the state entries
263 from the first host/network to the second.
264 For example, to kill all of the state entries originating from
269 To kill all of the state entries from
274 .Dl # pfctl -k host1 -k host2
276 To kill all states originating from 192.168.1.0/24 to 172.16.0.0/16:
278 .Dl # pfctl -k 192.168.1.0/24 -k 172.16.0.0/16
280 A network prefix length of 0 can be used as a wildcard.
281 To kill all states with the target
284 .Dl # pfctl -k 0.0.0.0/0 -k host2
286 Merge in explicitly given options without resetting those
288 Allows single options to be modified without disturbing the others:
289 .Bd -literal -offset indent
290 # echo "set loginterface fxp0" | pfctl -mf -
293 Load only the NAT rules present in the rule file.
294 Other rules and options are ignored.
296 Do not actually load rules, just parse them.
298 Load only the options present in the rule file.
299 Other rules and options are ignored.
301 Control the ruleset optimizer, overriding any rule file settings.
303 .Bl -tag -width xxxxxxxxxxxx -compact
305 Disable the ruleset optimizer.
307 Enable basic ruleset optimizations.
308 This is the default behaviour.
310 Enable basic ruleset optimizations with profiling.
312 For further information on the ruleset optimizer, see
317 instead of the default
320 Only print errors and warnings.
322 Load only the filter rules present in the rule file.
323 Other rules and options are ignored.
325 Perform reverse DNS lookups on states when displaying them.
327 Show the filter parameters specified by
329 (may be abbreviated):
331 .Bl -tag -width xxxxxxxxxxxxx -compact
333 Show the currently loaded NAT rules.
335 Show the currently loaded queue rules.
336 When used together with
338 per-queue statistics are also shown.
339 When used together with
342 will loop and show updated queue statistics every five seconds, including
343 measured bandwidth and packets per second.
345 Show the currently loaded filter rules.
346 When used together with
348 the per-rule statistics (number of evaluations,
349 packets and bytes) are also shown.
352 optimization done automatically by the kernel
353 will skip evaluation of rules where possible.
354 Packets passed statefully are counted in the rule that created the state
355 (even though the rule isn't evaluated more than once for the entire
358 Show the currently loaded anchors directly attached to the main ruleset.
361 is specified as well, the anchors loaded directly below the given
366 is specified, all anchors attached under the target anchor will be
367 displayed recursively.
369 Show the contents of the state table.
371 Show the contents of the source tracking table.
373 Show filter information (statistics and counters).
374 When used together with
376 source tracking statistics are also shown.
378 Show per-rule statistics (label, evaluations, packets total, bytes total,
379 packets in, bytes in, packets out, bytes out) of
380 filter rules with labels, useful for accounting.
382 Show the current global timeouts.
384 Show the current pool memory hard limits.
386 Show the list of tables.
388 Show the list of operating system fingerprints.
389 .It Fl s Cm Interfaces
390 Show the list of interfaces and interface drivers available to PF.
391 When used together with
393 it additionally lists which interfaces have skip rules activated.
394 When used together with
396 interface statistics are also shown.
398 can be used to select an interface or a group of interfaces.
400 Show all of the above, except for the lists of interfaces and operating
403 .It Fl T Ar command Op Ar address ...
406 (may be abbreviated) to apply to the table.
409 .Bl -tag -width xxxxxxxxxxxx -compact
413 Flush all addresses of a table.
415 Add one or more addresses in a table.
416 Automatically create a nonexisting table.
418 Delete one or more addresses from a table.
419 .It Fl T Cm expire Ar number
420 Delete addresses which had their statistics cleared more than
423 For entries which have never had their statistics cleared,
425 refers to the time they were added to the table.
427 Replace the addresses of the table.
428 Automatically create a nonexisting table.
430 Show the content (addresses) of a table.
432 Test if the given addresses match a table.
434 Clear all the statistics of a table.
436 Load only the table definitions from
438 This is used in conjunction with the
441 .Bd -literal -offset indent
442 # pfctl -Tl -f pf.conf
452 commands, the list of addresses can be specified either directly on the command
453 line and/or in an unformatted text file, using the
456 Comments starting with a
458 are allowed in the text file.
459 With these commands, the
461 flag can also be used once or twice, in which case
464 detailed result of the operation for each individual address, prefixed by
465 one of the following letters:
467 .Bl -tag -width XXX -compact
469 The address/network has been added.
471 The address/network has been changed (negated).
473 The address/network has been deleted.
481 The address/network is duplicated and therefore ignored.
483 The address/network cannot be added/deleted due to conflicting
487 The address/network has been cleared (statistics).
490 Each table maintains a set of counters that can be retrieved using the
494 For example, the following commands define a wide open firewall which will keep
495 track of packets going to or coming from the
498 The following commands configure the firewall and send 10 pings to the FTP
500 .Bd -literal -offset indent
501 # printf "table \*[Lt]test\*[Gt] { ftp.NetBSD.org }\en \e
502 pass out to \*[Lt]test\*[Gt]\en" | pfctl -f-
503 # ping -qc10 ftp.NetBSD.org
506 We can now use the table
508 command to output, for each address and packet direction, the number of packets
509 and bytes that are being passed or blocked by rules referencing the table.
510 The time at which the current accounting started is also shown with the
513 .Bd -literal -offset indent
514 # pfctl -t test -vTshow
516 Cleared: Thu Feb 13 18:55:18 2003
517 In/Block: [ Packets: 0 Bytes: 0 ]
518 In/Pass: [ Packets: 10 Bytes: 840 ]
519 Out/Block: [ Packets: 0 Bytes: 0 ]
520 Out/Pass: [ Packets: 10 Bytes: 840 ]
523 Similarly, it is possible to view global information about the tables
526 modifier twice and the
530 This will display the number of addresses on each table,
531 the number of rules which reference the table, and the global
532 packet statistics for the whole table:
533 .Bd -literal -offset indent
537 Cleared: Thu Feb 13 18:55:18 2003
538 References: [ Anchors: 0 Rules: 1 ]
539 Evaluations: [ NoMatch: 3496 Match: 1 ]
540 In/Block: [ Packets: 0 Bytes: 0 ]
541 In/Pass: [ Packets: 10 Bytes: 840 ]
542 In/XPass: [ Packets: 0 Bytes: 0 ]
543 Out/Block: [ Packets: 0 Bytes: 0 ]
544 Out/Pass: [ Packets: 10 Bytes: 840 ]
545 Out/XPass: [ Packets: 0 Bytes: 0 ]
548 As we can see here, only one packet \- the initial ping request \- matched the
549 table, but all packets passing as the result of the state are correctly
551 Reloading the table(s) or ruleset will not affect packet accounting in any way.
554 counters are incremented instead of the
558 packet is passed but doesn't match the table anymore.
559 This will happen in our example if someone flushes the table while the
563 When used with a single
566 will only display the first line containing the table flags and name.
567 The flags are defined as follows:
569 .Bl -tag -width XXX -compact
571 For constant tables, which cannot be altered outside
574 For persistent tables, which don't get automatically killed when no rules
577 For tables which are part of the
580 Tables without this flag do not really exist, cannot contain addresses, and are
585 For tables which are part of the
588 This flag can only be witnessed briefly during the loading of
591 For tables which are referenced (used) by rules.
593 This flag is set when a table in the main ruleset is hidden by one or more
594 tables of the same name from anchors attached below it.
597 Specify the name of the table.
599 Produce more verbose output.
602 will produce even more verbose output including ruleset warnings.
603 See the previous section for its effect on table commands.
607 (may be abbreviated) to one of the following:
609 .Bl -tag -width xxxxxxxxxxxx -compact
611 Don't generate debug messages.
613 Generate debug messages only for serious errors.
615 Generate debug messages for various errors.
617 Generate debug messages for common conditions.
620 Clear per-rule statistics.
623 .Bl -tag -width "/etc/pf.conf" -compact
625 Packet filter rules file.
627 Passive operating system fingerprint database.
643 filter mechanism first appeared in