1 .\" $OpenBSD: pfctl.8,v 1.110 2004/03/20 09:31:42 david Exp $
2 .\" $DragonFly: src/usr.sbin/pfctl/pfctl.8,v 1.4 2007/07/29 17:27:45 swildner 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"
38 .Op Fl a Ar anchor Ns Op Ar :ruleset
39 .Op Fl D Ar macro=value
46 .Op Fl T Ar command Op Ar address ...
53 utility communicates with the packet filter device using the
54 ioctl interface described in
56 It allows ruleset and parameter configuration and retrieval of status
57 information from the packet filter.
59 Packet filtering restricts the types of packets that pass through
60 network interfaces entering or leaving the host based on filter
63 The packet filter can also replace addresses and ports of packets.
64 Replacing source addresses and ports of outgoing packets is called
65 NAT (Network Address Translation) and is used to connect an internal
66 network (usually reserved address space) to an external one (the
67 Internet) by making all connections to external hosts appear to
68 come from the gateway.
69 Replacing destination addresses and ports of incoming packets
70 is used to redirect connections to different hosts and/or ports.
71 A combination of both translations, bidirectional NAT, is also
73 Translation rules are described in
80 the rule file specified with the variable
82 is loaded automatically by the
84 scripts and the packet filter is enabled.
86 The packet filter does not itself forward packets between interfaces.
87 Forwarding can be enabled by setting the
90 .Va net.inet.ip.forwarding
92 .Va net.inet6.ip6.forwarding ,
94 Set them permanently in
99 utility provides several commands.
100 The options are as follows:
103 Load only the queue rules present in the rule file.
104 Other rules and options are ignored.
105 .It Fl a Ar anchor Ns Op Ar :ruleset
111 only to the rules in the specified
113 and optional named ruleset
115 In addition to the main ruleset,
117 can load and manipulate additional rulesets by name.
118 Named rulesets are attached at
120 points, which are also referenced by name.
123 rules from the main ruleset is described in
125 For example, to show all filter rules inside anchor
127 .Bd -literal -offset indent
128 # pfctl -a foo -s rules
131 Private tables can also be put inside subrulesets, either by having table
134 file that is loaded in the anchor, or by using regular table commands as in:
135 .Bd -literal -offset indent
136 # pfctl -a foo:bar -t mytable -T add 1.2.3.4 5.6.7.8
139 When a rule referring to a table is loaded in an anchor, the rule will use the
140 private table if one is defined, and then fallback to the table defined in the
141 main ruleset, if there is one.
142 This is similar to C rules for variables.
143 It is possible to create distinct tables with the same name in the global
144 ruleset and in an anchor, but this is often bad design and a warning will be
146 .It Fl D Ar macro=value
152 Overrides the definition of
156 Disable the packet filter.
158 Enable the packet filter.
160 Flush the filter parameters specified by
162 (may be abbreviated):
164 .Bl -tag -width xxxxxxxxxxxx -compact
168 Flush the queue rules.
170 Flush the filter rules.
172 Flush the state table (NAT and filter).
174 Flush the source tracking table.
176 Flush the filter information (statistics that are not bound to rules).
180 Flush the passive operating system fingerprints.
182 Flush all of the above.
185 Load the rules contained in
189 may contain macros, tables, options, and normalization, queueing,
190 translation, and filtering rules.
191 With the exception of macros and tables, the statements must appear in that
194 Include output helpful for debugging.
197 .It Fl i Ar interface
198 Restrict the operation to the given
201 Kill all of the state entries originating from the specified
205 option may be specified, which will kill all the state entries
210 For example, to kill all of the state entries originating from
212 .Bd -literal -offset indent
216 To kill all of the state entries from
220 .Bd -literal -offset indent
221 # pfctl -k host1 -k host2
224 Load only the NAT rules present in the rule file.
225 Other rules and options are ignored.
227 Do not actually load rules, just parse them.
229 Load only the options present in the rule file.
230 Other rules and options are ignored.
234 instead of the default
237 Only print errors and warnings.
239 Load only the filter rules present in the rule file.
240 Other rules and options are ignored.
242 Perform reverse DNS lookups on states when displaying them.
244 Show the filter parameters specified by
246 (may be abbreviated):
248 .Bl -tag -width xxxxxxxxxxxxx -compact
250 Show the currently loaded NAT rules.
252 Show the currently loaded queue rules.
253 When used together with
255 per-queue statistics are also shown.
256 When used together with
259 will loop and show updated queue statistics every five seconds, including
260 measured bandwidth and packets per second.
262 Show the currently loaded filter rules.
263 When used together with
265 the per-rule statistics (number of evaluations,
266 packets and bytes) are also shown.
267 Note that the 'skip step' optimization done automatically by the kernel
268 will skip evaluation of rules where possible.
269 Packets passed statefully are counted in the rule that created the state
270 (even though the rule isn't evaluated more than once for the entire
273 Show the currently loaded anchors.
276 is specified as well, the named rulesets currently loaded in the specified
277 anchor are shown instead.
279 Show the contents of the state table.
281 Show the contents of the source tracking table.
283 Show filter information (statistics and counters).
284 When used together with
286 source tracking statistics are also shown.
288 Show per-rule statistics (label, evaluations, packets, bytes) of
289 filter rules with labels, useful for accounting.
291 Show the current global timeouts.
293 Show the current pool memory hard limits.
295 Show the list of tables.
297 Show the list of operating system fingerprints.
298 .It Fl s Ar Interfaces
299 Show the list of interfaces and interface drivers available to PF.
300 When used together with a double
302 interface statistics are also shown.
304 can be used to select an interface or a group of interfaces.
306 Show all of the above, except for the lists of interfaces and operating
309 .It Fl T Ar command Op Ar address ...
312 (may be abbreviated) to apply to the table.
315 .Bl -tag -width xxxxxxxxxxxx -compact
319 Flush all addresses of a table.
321 Add one or more addresses in a table.
322 Automatically create a nonexisting table.
324 Delete one or more addresses from a table.
326 Replace the addresses of the table.
327 Automatically create a nonexisting table.
329 Show the content (addresses) of a table.
331 Test if the given addresses match a table.
333 Clear all the statistics of a table.
335 Load only the table definitions from
337 This is used in conjunction with the
340 .Bd -literal -offset indent
341 # pfctl -Tl -f pf.conf
351 commands, the list of addresses can be specified either directly on the command
352 line and/or in an unformatted text file, using the
355 Comments starting with a "#" are allowed in the text file.
356 With these commands, the
358 flag can also be used once or twice, in which case
361 detailed result of the operation for each individual address, prefixed by
362 one of the following letters:
364 .Bl -tag -width XXX -compact
366 The address/network has been added.
368 The address/network has been changed (negated).
370 The address/network has been deleted.
372 The address matches (test operation only).
374 The address/network is duplicated and therefore ignored.
376 The address/network cannot be added/deleted due to conflicting "!" attribute.
378 The address/network has been cleared (statistics).
381 Each table maintains a set of counters that can be retrieved using the
385 For example, the following commands define a wide open firewall which will keep
386 track of packets going to or coming from the
389 The following commands configure the firewall and send 10 pings to the ftp
391 .Bd -literal -offset indent
392 # printf "table <test> { ftp.openbsd.org }\en \e
393 pass out to <test> keep state\en" | pfctl -f-
394 # ping -qc10 ftp.openbsd.org
397 We can now use the table
399 command to output, for each address and packet direction, the number of packets
400 and bytes that are being passed or blocked by rules referencing the table.
401 The time at which the current accounting started is also shown with the
404 .Bd -literal -offset indent
405 # pfctl -t test -vTshow
407 Cleared: Thu Feb 13 18:55:18 2003
408 In/Block: [ Packets: 0 Bytes: 0 ]
409 In/Pass: [ Packets: 10 Bytes: 840 ]
410 Out/Block: [ Packets: 0 Bytes: 0 ]
411 Out/Pass: [ Packets: 10 Bytes: 840 ]
414 Similarly, it is possible to view global information about the tables
417 modifier twice and the
420 This will display the number of addresses on each table,
421 the number of rules which reference the table, and the global
422 packet statistics for the whole table:
423 .Bd -literal -offset indent
427 Cleared: Thu Feb 13 18:55:18 2003
428 References: [ Anchors: 0 Rules: 1 ]
429 Evaluations: [ NoMatch: 3496 Match: 1 ]
430 In/Block: [ Packets: 0 Bytes: 0 ]
431 In/Pass: [ Packets: 10 Bytes: 840 ]
432 In/XPass: [ Packets: 0 Bytes: 0 ]
433 Out/Block: [ Packets: 0 Bytes: 0 ]
434 Out/Pass: [ Packets: 10 Bytes: 840 ]
435 Out/XPass: [ Packets: 0 Bytes: 0 ]
438 As we can see here, only one packet \- the initial ping request \- matched the
439 table; but all packets passing as the result of the state are correctly
441 Reloading the table(s) or ruleset will not affect packet accounting in any way.
444 counters are incremented instead of the
446 counters when a "stateful" packet is passed but doesn't match the table
448 This will happen in our example if someone flushes the table while the ping
451 When used with a single
454 will only display the first line containing the table flags and name.
455 The flags are defined as follows:
457 .Bl -tag -width XXX -compact
459 For constant tables, which cannot be altered outside
462 For persistent tables, which don't get automatically flushed when no rules
465 For tables which are part of the
468 Tables without this flag do not really exist, cannot contain addresses, and are
473 For tables which are part of the
476 This flag can only be witnessed briefly during the loading of
479 For tables which are referenced (used) by rules.
481 This flag is set when a table in the main ruleset is hidden by one or more
482 tables of the same name in sub-rulesets (anchors).
485 Specify the name of the table.
487 Produce more verbose output.
490 will produce even more verbose output including ruleset warnings.
491 See previous section for its effect on table commands.
495 (may be abbreviated) to one of the following:
497 .Bl -tag -width xxxxxxxxxxxx -compact
499 Don't generate debug messages.
501 Generate debug messages only for serious errors.
503 Generate debug messages for various errors.
505 Generate debug messages for common conditions.
508 Clear per-rule statistics.
511 .Bl -tag -width "/etc/pf.conf" -compact
513 Packet filter rules file.
529 filter mechanism first appeared in