1 .\" $NetBSD: pf.conf.5,v 1.15 2009/03/22 14:29:35 perry Exp $
2 .\" $OpenBSD: pf.conf.5,v 1.383 2007/07/17 16:27:38 jmc Exp $
4 .\" Copyright (c) 2002, Daniel Hartmeier
5 .\" All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
11 .\" - Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" - Redistributions in binary form must reproduce the above
14 .\" copyright notice, this list of conditions and the following
15 .\" disclaimer in the documentation and/or other materials provided
16 .\" with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 .\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 .\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 .\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 .\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 .\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 .\" POSSIBILITY OF SUCH DAMAGE.
36 .Nd packet filter configuration file
40 packet filter modifies, drops or passes packets according to rules or
41 definitions specified in
44 There are seven types of statements in
48 User-defined variables may be defined and used later, simplifying
49 the configuration file.
50 Macros must be defined before they are referenced in
53 Tables provide a mechanism for increasing the performance and flexibility of
54 rules with large numbers of source or destination addresses.
56 Options tune the behaviour of the packet filtering engine.
57 .It Cm Traffic Normalization Li (e.g. Em scrub )
58 Traffic normalization protects internal machines against inconsistencies
59 in Internet protocols and implementations.
61 Queueing provides rule-based bandwidth control.
62 .It Cm Translation Li (Various forms of NAT)
63 Translation rules specify how addresses are to be mapped or redirected to
65 .It Cm Packet Filtering
66 Packet filtering provides rule-based blocking or passing of packets.
73 the types of statements should be grouped and appear in
75 in the order shown above, as this matches the operation of the underlying
76 packet filtering engine.
79 enforces this order (see
83 Macros can be defined that will later be expanded in context.
84 Macro names must start with a letter, and may contain letters, digits
86 Macro names may not be reserved words (for example
90 Macros are not expanded inside quotes.
93 .Bd -literal -offset indent
95 all_ifs = \&"{\&" $ext_if lo0 \&"}\&"
96 pass out on $ext_if from any to any
97 pass in on $ext_if proto tcp from any to any port 25
100 Tables are named structures which can hold a collection of addresses and
102 Lookups against tables in
104 are relatively fast, making a single rule with tables much more efficient,
106 processor usage and memory consumption, than a large number of rules which
107 differ only in IP address (either created explicitly or automatically by rule
110 Tables can be used as the source or destination of filter rules,
114 translation rules such as
118 (see below for details on the various rule types).
119 Tables can also be used for the redirect address of
123 rules and in the routing options of filter rules, but only for
127 Tables can be defined with any of the following
130 As with macros, reserved words may not be used as table names.
131 .Bl -tag -width "manually"
133 Persistent tables can be manually created with the
139 before or after the ruleset has been loaded.
141 Table definitions can be placed directly in this file, and loaded at the
142 same time as other rules are loaded, atomically.
143 Table definitions inside
147 statement, and are especially useful to define non-persistent tables.
148 The contents of a pre-existing table defined without a list of addresses
149 to initialize it is not altered when
152 A table initialized with the empty list,
154 will be cleared on load.
157 Tables may be defined with the following two attributes:
158 .Bl -tag -width persist
162 flag forces the kernel to keep the table even when no rules refer to it.
163 If the flag is not set, the kernel will automatically remove the table
164 when the last rule referring to it is flushed.
168 flag prevents the user from altering the contents of the table once it
172 can be used to add or remove addresses from the table at any time, even
173 when running with securelevel = 2.
177 .Bd -literal -offset indent
178 table \*(Ltprivate\*(Gt const { 10/8, 172.16/12, 192.168/16 }
179 table \*(Ltbadhosts\*(Gt persist
180 block on fxp0 from { \*(Ltprivate\*(Gt, \*(Ltbadhosts\*(Gt } to any
183 creates a table called private, to hold RFC 1918 private network
184 blocks, and a table called badhosts, which is initially empty.
185 A filter rule is set up to block all traffic coming from addresses listed in
187 The private table cannot have its contents changed and the badhosts table
188 will exist even when no active filter rules reference it.
189 Addresses may later be added to the badhosts table, so that traffic from
190 these hosts can be blocked by using
191 .Bd -literal -offset indent
192 # pfctl -t badhosts -Tadd 204.92.77.111
195 A table can also be initialized with an address list specified in one or more
196 external files, using the following syntax:
197 .Bd -literal -offset indent
198 table \*(Ltspam\*(Gt persist file \&"/etc/spammers\&" file \&"/etc/openrelays\&"
199 block on fxp0 from \*(Ltspam\*(Gt to any
206 list IP addresses, one per line.
207 Any lines beginning with a # are treated as comments and ignored.
208 In addition to being specified by IP address, hosts may also be
209 specified by their hostname.
210 When the resolver is called to add a hostname to a table,
212 resulting IPv4 and IPv6 addresses are placed into the table.
213 IP addresses can also be entered in a table by specifying a valid interface
214 name, a valid interface group or the
216 keyword, in which case all addresses assigned to the interface(s) will be
220 may be tuned for various situations using the
226 .Bl -tag -width "src.track" -compact
228 Interval between purging expired states and fragments.
230 Seconds before an unassembled fragment is expired.
232 Length of time to retain a source tracking entry after the last state
236 When a packet matches a stateful connection, the seconds to live for the
237 connection will be updated to that of the
239 which corresponds to the connection state.
240 Each packet which matches this state will reset the TTL.
241 Tuning these values may improve the performance of the
242 firewall at the risk of dropping valid idle connections.
244 .Bl -tag -width xxxx -compact
246 The state after the first packet.
248 The state before the destination host ever sends a packet.
249 .It Ar tcp.established
250 The fully established state.
252 The state after the first FIN has been sent.
254 The state after both FINs have been exchanged and the connection is closed.
255 Some hosts (notably web servers on Solaris) send TCP packets even after closing
261 can prevent blocking of such packets.
263 The state after one endpoint sends an RST.
266 ICMP and UDP are handled in a fashion similar to TCP, but with a much more
267 limited set of states:
269 .Bl -tag -width xxxx -compact
271 The state after the first packet.
273 The state if the source host sends more than one packet but the destination
274 host has never sent one back.
276 The state if both hosts have sent packets.
278 The state after the first packet.
280 The state after an ICMP error came back in response to an ICMP packet.
283 Other protocols are handled similarly to UDP:
285 .Bl -tag -width xxxx -compact
288 .It Ar other.multiple
291 Timeout values can be reduced adaptively as the number of state table
294 .Bl -tag -width xxxx -compact
295 .It Ar adaptive.start
296 When the number of state entries exceeds this value, adaptive scaling
298 All timeout values are scaled linearly with factor
299 (adaptive.end - number of states) / (adaptive.end - adaptive.start).
301 When reaching this number of state entries, all timeout values become
302 zero, effectively purging all state entries immediately.
303 This value is used to define the scale factor, it should not actually
304 be reached (set a lower state limit, see below).
307 Adaptive timeouts are enabled by default, with an adaptive.start value
308 equal to 60% of the state limit, and an adaptive.end value equal to
309 120% of the state limit.
310 They can be disabled by setting both adaptive.start and adaptive.end to 0.
312 The adaptive timeout values can be defined both globally and for each rule.
313 When used on a per-rule basis, the values relate to the number of
314 states created by the rule, otherwise to the total number of
318 .Bd -literal -offset indent
319 set timeout tcp.first 120
320 set timeout tcp.established 86400
321 set timeout { adaptive.start 6000, adaptive.end 12000 }
322 set limit states 10000
325 With 9000 state table entries, the timeout values are scaled to 50%
326 (tcp.first 60, tcp.established 43200).
328 .It Ar set loginterface
329 Enable collection of packet and byte count statistics for the given interface.
330 These statistics can be viewed using
331 .Bd -literal -offset indent
337 collects statistics on the interface named dc0:
338 .Bd -literal -offset indent
342 One can disable the loginterface using:
343 .Bd -literal -offset indent
344 set loginterface none
348 Sets hard limits on the memory pools used by the packet filter.
351 for an explanation of memory pools.
354 .Bd -literal -offset indent
355 set limit states 20000
358 sets the maximum number of entries in the memory pool used by state table
359 entries (generated by
361 rules which do not specify
365 .Bd -literal -offset indent
366 set limit frags 20000
369 sets the maximum number of entries in the memory pool used for fragment
370 reassembly (generated by
374 .Bd -literal -offset indent
375 set limit src-nodes 2000
378 sets the maximum number of entries in the memory pool used for tracking
379 source IP addresses (generated by the
385 .Bd -literal -offset indent
386 set limit tables 1000
387 set limit table-entries 100000
390 sets limits on the memory pools used by tables.
391 The first limits the number of tables that can exist to 1000.
392 The second limits the overall number of addresses that can be stored
395 Various limits can be combined on a single line:
396 .Bd -literal -offset indent
397 set limit { states 20000, frags 20000, src-nodes 2000 }
400 .It Ar set ruleset-optimization
401 .Bl -tag -width xxxxxxxx -compact
403 Disable the ruleset optimizer.
405 Enable basic ruleset optimization.
406 This is the default behaviour.
407 Basic ruleset optimization does four things to improve the
408 performance of ruleset evaluations:
412 remove duplicate rules
414 remove rules that are a subset of another rule
416 combine multiple rules into a table when advantageous
418 re-order the rules to improve evaluation performance
422 Uses the currently loaded ruleset as a feedback profile to tailor the
423 ordering of quick rules to actual network traffic.
426 It is important to note that the ruleset optimizer will modify the ruleset
427 to improve performance.
428 A side effect of the ruleset modification is that per-rule accounting
429 statistics will have different meanings than before.
430 If per-rule accounting is important for billing purposes or whatnot,
431 either the ruleset optimizer should not be used or a label field should
432 be added to all of the accounting rules to act as optimization barriers.
434 Optimization can also be set as a command-line argument to
436 overriding the settings in
438 .It Ar set optimization
439 Optimize state timeouts for one of the following network environments:
441 .Bl -tag -width xxxx -compact
443 A normal network environment.
444 Suitable for almost all networks.
446 A high-latency environment (such as a satellite connection).
451 Aggressively expire connections.
452 This can greatly reduce the memory usage of the firewall at the cost of
453 dropping idle connections early.
455 Extremely conservative settings.
456 Avoid dropping legitimate connections at the
457 expense of greater memory utilization (possibly much greater on a busy
458 network) and slightly increased processor utilization.
462 .Bd -literal -offset indent
463 set optimization aggressive
466 .It Ar set block-policy
469 option sets the default behaviour for the packet
473 .Bl -tag -width xxxxxxxx -compact
475 Packet is silently dropped.
477 A TCP RST is returned for blocked TCP packets,
478 an ICMP UNREACHABLE is returned for blocked UDP packets,
479 and all other packets are silently dropped.
483 .Bd -literal -offset indent
484 set block-policy return
486 .It Ar set state-policy
489 option sets the default behaviour for states:
491 .Bl -tag -width group-bound -compact
493 States are bound to interface.
495 States can match packets on any interfaces (the default).
499 .Bd -literal -offset indent
500 set state-policy if-bound
505 identifies this firewall's state table entries to other firewalls
509 By default the hostid is set to a pseudo-random value, however it may be
510 desirable to manually configure it, for example to more easily identify the
511 source of state table entries.
512 .Bd -literal -offset indent
516 The hostid may be specified in either decimal or hexadecimal.
517 .It Ar set require-order
520 enforces an ordering of the statement types in the ruleset to:
526 Setting this option to
528 disables this enforcement.
529 There may be non-trivial and non-obvious implications to an out of
531 Consider carefully before disabling the order enforcement.
532 .It Ar set fingerprints
533 Load fingerprints of known operating systems from the given filename.
534 By default fingerprints of known operating systems are automatically
539 but can be overridden via this option.
540 Setting this option may leave a small period of time where the fingerprints
541 referenced by the currently active ruleset are inconsistent until the new
542 ruleset finishes loading.
546 .Dl set fingerprints \&"/etc/pf.os.devel\&"
548 .It Ar set skip on Aq Ar ifspec
549 List interfaces for which packets should not be filtered.
550 Packets passing in or out on such interfaces are passed as if pf was
551 disabled, i.e. pf does not process them in any way.
552 This can be useful on loopback and other virtual interfaces, when
553 packet filtering is not desired and can have unexpected effects.
561 to one of the following:
563 .Bl -tag -width xxxxxxxxxxxx -compact
565 Don't generate debug messages.
567 Generate debug messages only for serious errors.
569 Generate debug messages for various errors.
571 Generate debug messages for common conditions.
574 .Sh TRAFFIC NORMALIZATION
575 Traffic normalization is used to sanitize packet content in such
576 a way that there are no ambiguities in packet interpretation on
578 The normalizer does IP fragment reassembly to prevent attacks
579 that confuse intrusion detection systems by sending overlapping
581 Packet normalization is invoked with the
586 has the following options:
591 bit from a matching IP packet.
592 Some operating systems are known to generate fragmented packets with the
595 This is particularly true with NFS.
597 will drop such fragmented
603 Unfortunately some operating systems also generate their
605 packets with a zero IP identification field.
608 bit on packets with a zero IP ID may cause deleterious results if an
609 upstream router later fragments the packet.
612 modifier (see below) is recommended in combination with the
614 modifier to ensure unique IP identifiers.
615 .It Ar min-ttl Aq Ar number
616 Enforces a minimum TTL for matching IP packets.
617 .It Ar max-mss Aq Ar number
618 Enforces a maximum MSS for matching TCP packets.
620 Replaces the IP identification field with random values to compensate
621 for predictable values generated by many hosts.
622 This option only applies to packets that are not fragmented
623 after the optional fragment reassembly.
624 .It Ar fragment reassemble
627 rules, fragments can be reassembled by normalization.
628 In this case, fragments are buffered until they form a complete
629 packet, and only the completed packet is passed on to the filter.
630 The advantage is that filter rules have to deal only with complete
631 packets, and can ignore fragments.
632 The drawback of caching fragments is the additional memory cost.
633 But the full reassembly method is the only method that currently works
635 This is the default behavior of a
637 rule if no fragmentation modifier is supplied.
639 The default fragment reassembly method is expensive, hence the option
643 will track the fragments and cache a small range descriptor.
644 Duplicate fragments are dropped and overlaps are cropped.
645 Thus data will only occur once on the wire with ambiguities resolving to
646 the first occurrence.
648 .Ar fragment reassemble
649 modifier, fragments are not buffered, they are passed as soon as they
653 reassembly mechanism does not yet work with NAT.
655 .It Ar fragment drop-ovl
656 This option is similar to the
658 modifier except that all overlapping or duplicate fragments will be
659 dropped, and all further corresponding fragments will be
661 .It Ar reassemble tcp
662 Statefully normalizes TCP connections.
663 .Ar scrub reassemble tcp
664 rules may not have the direction (in/out) specified.
666 performs the following normalizations:
668 .Bl -tag -width timeout -compact
670 Neither side of the connection is allowed to reduce their IP TTL.
671 An attacker may send a packet such that it reaches the firewall, affects
672 the firewall state, and expires before reaching the destination host.
674 will raise the TTL of all packets back up to the highest value seen on
676 .It timestamp modulation
677 Modern TCP stacks will send a timestamp on every TCP packet and echo
678 the other endpoint's timestamp back to them.
679 Many operating systems will merely start the timestamp at zero when
680 first booted, and increment it several times a second.
681 The uptime of the host can be deduced by reading the timestamp and multiplying
683 Also observing several different timestamps can be used to count hosts
685 And spoofing TCP packets into a connection requires knowing or guessing
687 Timestamps merely need to be monotonically increasing and not derived off a
692 to modulate the TCP timestamps with a random number.
693 .It extended PAWS checks
694 There is a problem with TCP on long fat pipes, in that a packet might get
695 delayed for longer than it takes the connection to wrap its 32-bit sequence
697 In such an occurrence, the old packet would be indistinguishable from a
698 new packet and would be accepted as such.
699 The solution to this is called PAWS: Protection Against Wrapped Sequence
701 It protects against it by making sure the timestamp on each packet does
704 also makes sure the timestamp on the packet does not go forward more
708 artificially extends the security of TCP sequence numbers by 10 to 18
709 bits when the host uses appropriately randomized timestamps, since a
710 blind attacker would have to guess the timestamp as well.
715 .Bd -literal -offset indent
716 scrub in on $ext_if all fragment reassemble
721 option prefixed to a scrub rule causes matching packets to remain unscrubbed,
722 much in the same way as
724 works in the packet filter (see below).
725 This mechanism should be used when it is necessary to exclude specific packets
726 from broader scrub rules.
728 Packets can be assigned to queues for the purpose of bandwidth
730 At least two declarations are required to configure queues, and later
731 any packet filtering rule can reference the defined queues by name.
732 During the filtering component of
736 name is where any packets from
738 rules will be queued, while for
740 rules it specifies where any resulting ICMP or TCP RST
741 packets should be queued.
744 defines the algorithm used to decide which packets get delayed, dropped, or
745 sent out immediately.
751 Class Based Queueing.
753 attached to an interface build a tree, thus each
755 can have further child
757 Each queue can have a
763 mainly controls the time packets take to get sent out, while
765 has primarily effects on throughput.
767 achieves both partitioning and sharing of link bandwidth
768 by hierarchically structured classes.
769 Each class has its own
771 and is assigned its share of
773 A child class can borrow bandwidth from its parent class
774 as long as excess bandwidth is available
781 are flat attached to the interface, thus,
783 cannot have further child
789 assigned, ranging from 0 to 15.
796 Hierarchical Fair Service Curve.
798 attached to an interface build a tree, thus each
800 can have further child
802 Each queue can have a
808 mainly controls the time packets take to get sent out, while
810 has primarily effects on throughput.
812 supports both link-sharing and guaranteed real-time services.
813 It employs a service curve based QoS model,
814 and its unique feature is an ability to decouple
821 The interfaces on which queueing should be activated are declared using
826 has the following keywords:
829 Queueing is enabled on the named interface.
831 Specifies which queueing scheduler to use.
832 Currently supported values
835 for Class Based Queueing,
837 for Priority Queueing and
839 for the Hierarchical Fair Service Curve scheduler.
840 .It Ar bandwidth Aq Ar bw
841 The maximum bitrate for all queues on an
842 interface may be specified using the
845 The value can be specified as an absolute value or as a
846 percentage of the interface bandwidth.
847 When using an absolute value, the suffixes
853 are used to represent bits, kilobits, megabits, and
854 gigabits per second, respectively.
855 The value must not exceed the interface bandwidth.
858 is not specified, the interface bandwidth is used
859 (but take note that some interfaces do not know their bandwidth,
860 or can adapt their bandwidth rates).
861 .It Ar qlimit Aq Ar limit
862 The maximum number of packets held in the queue.
864 .It Ar tbrsize Aq Ar size
865 Adjusts the size, in bytes, of the token bucket regulator.
866 If not specified, heuristics based on the
867 interface bandwidth are used to determine the size.
868 .It Ar queue Aq Ar list
869 Defines a list of subqueues to create on an interface.
872 In the following example, the interface dc0
873 should queue up to 5 Mbit/s in four second-level queues using
874 Class Based Queueing.
875 Those four queues will be shown in a later example.
876 .Bd -literal -offset indent
877 altq on dc0 cbq bandwidth 5Mb queue { std, http, mail, ssh }
880 Once interfaces are activated for queueing using the
882 directive, a sequence of
884 directives may be defined.
885 The name associated with a
887 must match a queue defined in the
889 directive (e.g. mail), or, except for the
895 The following keywords can be used:
897 .It Ar on Aq Ar interface
898 Specifies the interface the queue operates on.
899 If not given, it operates on all matching interfaces.
900 .It Ar bandwidth Aq Ar bw
901 Specifies the maximum bitrate to be processed by the queue.
902 This value must not exceed the value of the parent
904 and can be specified as an absolute value or a percentage of the parent
906 If not specified, defaults to 100% of the parent queue's bandwidth.
909 scheduler does not support bandwidth specification.
910 .It Ar priority Aq Ar level
911 Between queues a priority level can be set.
916 the range is 0 to 7 and for
918 the range is 0 to 15.
919 The default for all is 1.
921 queues with a higher priority are always served first.
925 queues with a higher priority are preferred in the case of overload.
926 .It Ar qlimit Aq Ar limit
927 The maximum number of packets held in the queue.
933 can get additional parameters with
935 .Pf ( Aq Ar parameters ) .
937 Parameters are as follows:
940 Packets not matched by another queue are assigned to this one.
941 Exactly one default queue is required.
943 Enable RED (Random Early Detection) on this queue.
944 RED drops packets with a probability proportional to the average
947 Enables RIO on this queue.
948 RIO is RED with IN/OUT, thus running
949 RED two times more than RIO would achieve the same effect.
950 RIO is currently not supported in the GENERIC kernel.
952 Enables ECN (Explicit Congestion Notification) on this queue.
959 supports an additional option:
962 The queue can borrow bandwidth from the parent.
968 supports some additional options:
970 .It Ar realtime Aq Ar sc
971 The minimum required bandwidth for the queue.
972 .It Ar upperlimit Aq Ar sc
973 The maximum allowed bandwidth for the queue.
974 .It Ar linkshare Aq Ar sc
975 The bandwidth share of a backlogged queue.
982 The format for service curve specifications is
983 .Ar ( m1 , d , m2 ) .
985 controls the bandwidth assigned to the queue.
989 are optional and can be used to control the initial bandwidth assignment.
992 milliseconds the queue gets the bandwidth given as
994 afterwards the value given in
1001 child queues can be specified as in an
1003 declaration, thus building a tree of queues using a part of
1004 their parent's bandwidth.
1006 Packets can be assigned to queues based on filter rules by using the
1011 is specified; when a second one is specified it will instead be used for
1012 packets which have a
1016 and for TCP ACKs with no data payload.
1018 To continue the previous example, the examples below would specify the
1020 queues, plus a few child queues.
1023 sessions get priority over bulk transfers like
1027 The queues may then be referenced by filtering rules (see
1028 .Sx PACKET FILTERING
1031 queue std bandwidth 10% cbq(default)
1032 queue http bandwidth 60% priority 2 cbq(borrow red) \e
1033 { employees, developers }
1034 queue developers bandwidth 75% cbq(borrow)
1035 queue employees bandwidth 15%
1036 queue mail bandwidth 10% priority 0 cbq(borrow ecn)
1037 queue ssh bandwidth 20% cbq(borrow) { ssh_interactive, ssh_bulk }
1038 queue ssh_interactive bandwidth 50% priority 7 cbq(borrow)
1039 queue ssh_bulk bandwidth 50% priority 0 cbq(borrow)
1041 block return out on dc0 inet all queue std
1042 pass out on dc0 inet proto tcp from $developerhosts to any port 80 \e
1044 pass out on dc0 inet proto tcp from $employeehosts to any port 80 \e
1046 pass out on dc0 inet proto tcp from any to any port 22 \e
1047 queue(ssh_bulk, ssh_interactive)
1048 pass out on dc0 inet proto tcp from any to any port 25 \e
1052 Translation rules modify either the source or destination address of the
1053 packets associated with a stateful connection.
1054 A stateful connection is automatically created to track packets matching
1055 such a rule as long as they are not blocked by the filtering section of
1057 The translation engine modifies the specified address and/or port in the
1058 packet, recalculates IP, TCP and UDP checksums as necessary, and passes it to
1059 the packet filter for evaluation.
1061 Since translation occurs before filtering the filter
1062 engine will see packets as they look after any
1063 addresses and ports have been translated.
1064 Filter rules will therefore have to filter based on the translated
1065 address and port number.
1066 Packets that match a translation rule are only automatically passed if
1069 modifier is given, otherwise they are
1076 The state entry created permits
1078 to keep track of the original address for traffic associated with that state
1079 and correctly direct return traffic for that connection.
1081 Various types of translation are possible with pf:
1082 .Bl -tag -width xxxx
1086 rule specifies a bidirectional mapping between an external IP netblock
1087 and an internal IP netblock.
1091 rule specifies that IP addresses are to be changed as the packet
1092 traverses the given interface.
1093 This technique allows one or more IP addresses
1094 on the translating host to support network traffic for a larger range of
1095 machines on an "inside" network.
1096 Although in theory any IP address can be used on the inside, it is strongly
1097 recommended that one of the address ranges defined by RFC 1918 be used.
1098 These netblocks are:
1100 10.0.0.0 - 10.255.255.255 (all of net 10, i.e., 10/8)
1101 172.16.0.0 - 172.31.255.255 (i.e., 172.16/12)
1102 192.168.0.0 - 192.168.255.255 (i.e., 192.168/16)
1105 The packet is redirected to another destination and possibly a
1108 rules can optionally specify port ranges instead of single ports.
1109 rdr ... port 2000:2999 -\*(Gt ... port 4000
1110 redirects ports 2000 to 2999 (inclusive) to port 4000.
1111 rdr ... port 2000:2999 -\*(Gt ... port 4000:*
1112 redirects port 2000 to 4000, 2001 to 4001, ..., 2999 to 4999.
1115 In addition to modifying the address, some translation rules may modify
1116 source or destination ports for
1120 connections; implicitly in the case of
1122 rules and explicitly in the case of
1125 Port numbers are never translated with a
1129 Evaluation order of the translation rules is dependent on the type
1130 of the translation rules and of the direction of a packet.
1132 rules are always evaluated first.
1135 rules are evaluated on an inbound packet or the
1137 rules on an outbound packet.
1138 Rules of the same type are evaluated in the same order in which they
1139 appear in the ruleset.
1140 The first matching rule decides what action is taken.
1144 option prefixed to a translation rule causes packets to remain untranslated,
1145 much in the same way as
1147 works in the packet filter (see below).
1148 If no rule matches the packet it is passed to the filter engine unmodified.
1150 Translation rules apply only to packets that pass through
1151 the specified interface, and if no interface is specified,
1152 translation is applied to packets on all interfaces.
1153 For instance, redirecting port 80 on an external interface to an internal
1154 web server will only work for connections originating from the outside.
1155 Connections to the address of the external interface from local hosts will
1156 not be redirected, since such packets do not actually pass through the
1158 Redirections cannot reflect packets back through the interface they arrive
1159 on, they can only be redirected to hosts connected to different interfaces
1160 or to the firewall itself.
1162 Note that redirecting external incoming connections to the loopback
1164 .Bd -literal -offset indent
1165 rdr on ne3 inet proto tcp to port spamd -\*(Gt 127.0.0.1 port smtp
1168 will effectively allow an external host to connect to daemons
1169 bound solely to the loopback address, circumventing the traditional
1170 blocking of such connections on a real interface.
1171 Unless this effect is desired, any of the local non-loopback addresses
1172 should be used as redirection target instead, which allows external
1173 connections only to daemons bound to this address or not bound to
1177 .Sx TRANSLATION EXAMPLES
1179 .Sh PACKET FILTERING
1185 packets based on attributes of their layer 3 (see
1195 In addition, packets may also be
1196 assigned to queues for the purpose of bandwidth control.
1198 For each packet processed by the packet filter, the filter rules are
1199 evaluated in sequential order, from first to last.
1200 The last matching rule decides what action is taken.
1201 If no rule matches the packet, the default action is to pass
1204 The following actions can be used in the filter:
1205 .Bl -tag -width xxxx
1207 The packet is blocked.
1208 There are a number of ways in which a
1210 rule can behave when blocking a packet.
1211 The default behaviour is to
1213 packets silently, however this can be overridden or made
1214 explicit either globally, by setting the
1216 option, or on a per-rule basis with one of the following options:
1218 .Bl -tag -width xxxx -compact
1220 The packet is silently dropped.
1222 This applies only to
1224 packets, and issues a TCP RST which closes the
1228 This causes ICMP messages to be returned for packets which match the rule.
1229 By default this is an ICMP UNREACHABLE message, however this
1230 can be overridden by specifying a message as a code or number.
1232 This causes a TCP RST to be returned for
1234 packets and an ICMP UNREACHABLE for UDP and other packets.
1237 Options returning ICMP packets currently have no effect if
1241 as the code to support this feature has not yet been implemented.
1243 The simplest mechanism to block everything by default and only pass
1244 packets that match explicit rules is specify a first filter rule of:
1245 .Bd -literal -offset indent
1249 The packet is passed;
1250 state is created unless the
1252 option is specified.
1257 filters packets statefully; the first time a packet matches a
1259 rule, a state entry is created; for subsequent packets the filter checks
1260 whether the packet matches any state.
1261 If it does, the packet is passed without evaluation of any rules.
1262 After the connection is closed or times out, the state entry is automatically
1265 This has several advantages.
1266 For TCP connections, comparing a packet to a state involves checking
1267 its sequence numbers, as well as TCP timestamps if a
1268 .Ar scrub reassemble tcp
1269 rule applies to the connection.
1270 If these values are outside the narrow windows of expected
1271 values, the packet is dropped.
1272 This prevents spoofing attacks, such as when an attacker sends packets with
1273 a fake source address/port but does not know the connection's sequence
1277 knows how to match ICMP replies to states.
1279 .Bd -literal -offset indent
1280 pass out inet proto icmp all icmp-type echoreq
1283 allows echo requests (such as those created by
1285 out statefully, and matches incoming echo replies correctly to states.
1287 Also, looking up states is usually faster than evaluating rules.
1288 If there are 50 rules, all of them are evaluated sequentially in O(n).
1289 Even with 50000 states, only 16 comparisons are needed to match a
1290 state, since states are stored in a binary search tree that allows
1291 searches in O(log2 n).
1293 Furthermore, correct handling of ICMP error messages is critical to
1294 many protocols, particularly TCP.
1296 matches ICMP error messages to the correct connection, checks them against
1297 connection parameters, and passes them if appropriate.
1298 For example if an ICMP source quench message referring to a stateful TCP
1299 connection arrives, it will be matched to the state and get passed.
1301 Finally, state tracking is required for
1302 .Ar nat , binat No and Ar rdr
1303 rules, in order to track address and port translations and reverse the
1304 translation on returning packets.
1307 will also create state for other protocols which are effectively stateless by
1309 UDP packets are matched to states using only host addresses and ports,
1310 and other protocols are matched to states using only the host addresses.
1312 If stateless filtering of individual packets is desired,
1315 keyword can be used to specify that state will not be created
1316 if this is the last matching rule.
1317 A number of parameters can also be set to affect how
1319 handles state tracking.
1321 .Sx STATEFUL TRACKING OPTIONS
1322 below for further details.
1324 The rule parameters specify the packets to which a rule applies.
1325 A packet always comes in on, or goes out through, one interface.
1326 Most parameters are optional.
1327 If a parameter is specified, the rule only applies to packets with
1328 matching attributes.
1329 Certain parameters can be expressed as lists, in which case
1331 generates all needed rule combinations.
1332 .Bl -tag -width xxxx
1333 .It Ar in No or Ar out
1334 This rule applies to incoming or outgoing packets.
1339 are specified, the rule will match packets in both directions.
1341 In addition to the action specified, a log message is generated.
1342 Only the packet that establishes the state is logged,
1345 option is specified.
1346 The logged packets are sent to a
1348 interface, by default
1350 This interface is monitored by the
1352 logging daemon, which dumps the logged packets to the file
1358 Used to force logging of all packets for a connection.
1359 This is not necessary when
1361 is explicitly specified.
1364 packets are logged to
1369 user ID of the user that owns the socket and the PID of the process that
1370 has the socket open where the packet is sourced from or destined to
1371 (depending on which socket is local).
1372 This is in addition to the normal information logged.
1373 .It Ar log (to Aq Ar interface )
1374 Send logs to the specified
1376 interface instead of
1379 If a packet matches a rule which has the
1381 option set, this rule
1382 is considered the last matching rule, and evaluation of subsequent rules
1384 .It Ar on Aq Ar interface
1385 This rule applies only to packets coming in on, or going out through, this
1386 particular interface or interface group.
1387 For more information on interface groups,
1393 This rule applies only to packets of this address family.
1394 Supported values are
1398 .It Ar proto Aq Ar protocol
1399 This rule applies only to packets of this protocol.
1400 Common protocols are
1406 For a list of all the protocol name to number mappings used by
1409 .Em /etc/protocols .
1410 .It Ar from Ao Ar source Ac Ar port Ao Ar source Ac Ar os Ao Ar source Ac \
1411 Ar to Ao Ar dest Ac Ar port Aq Ar dest
1412 This rule applies only to packets with the specified source and destination
1413 addresses and ports.
1415 Addresses can be specified in CIDR notation (matching netblocks), as
1416 symbolic host names, interface names or interface group names, or as any
1417 of the following keywords:
1419 .Bl -tag -width xxxxxxxxxxxxxx -compact
1422 .It Ar route Aq Ar label
1423 Any address whose associated route has label
1430 Any address which is not currently routable.
1432 Any source address that fails a unicast reverse path forwarding (URPF)
1433 check, i.e. packets coming in on an interface other than that which holds
1434 the route back to the packet's source address.
1436 Any address that matches the given table.
1439 Interface names and interface group names can have modifiers appended:
1441 .Bl -tag -width xxxxxxxxxxxx -compact
1443 Translates to the network(s) attached to the interface.
1445 Translates to the interface's broadcast address(es).
1447 Translates to the point to point interface's peer address(es).
1449 Do not include interface aliases.
1452 Host names may also have the
1454 option appended to restrict the name resolution to the first of each
1455 v4 and v6 address found.
1457 Host name resolution and interface to address translation are done at
1459 When the address of an interface (or host name) changes (under DHCP or PPP,
1460 for instance), the ruleset must be reloaded for the change to be reflected
1462 Surrounding the interface name (and optional modifiers) in parentheses
1463 changes this behaviour.
1464 When the interface name is surrounded by parentheses, the rule is
1465 automatically updated whenever the interface changes its address.
1466 The ruleset does not need to be reloaded.
1467 This is especially useful with
1470 Ports can be specified either by number or by name.
1471 For example, port 80 can be specified as
1473 For a list of all port name to number mappings used by
1478 Ports and ranges of ports are specified by using these operators:
1479 .Bd -literal -offset indent
1483 \*(Le (less than or equal)
1484 \*(Gt (greater than)
1485 \*(Ge (greater than or equal)
1486 : (range including boundaries)
1487 \*(Gt\*(Lt (range excluding boundaries)
1488 \*(Lt\*(Gt (except range)
1495 are binary operators (they take two arguments).
1498 .It Ar port 2000:2004
1500 .Sq all ports \*(Ge 2000 and \*(Le 2004 ,
1501 hence ports 2000, 2001, 2002, 2003 and 2004.
1502 .It Ar port 2000 \*(Gt\*(Lt 2004
1504 .Sq all ports \*(Gt 2000 and \*(Lt 2004 ,
1505 hence ports 2001, 2002 and 2003.
1506 .It Ar port 2000 \*(Lt\*(Gt 2004
1508 .Sq all ports \*(Lt 2000 or \*(Gt 2004 ,
1509 hence ports 1-1999 and 2005-65535.
1512 The operating system of the source host can be specified in the case of TCP
1517 .Sx OPERATING SYSTEM FINGERPRINTING
1518 section for more information.
1520 The host, port and OS specifications are optional, as in the following examples:
1521 .Bd -literal -offset indent
1523 pass in from any to any
1524 pass in proto tcp from any port \*(Le 1024 to any
1525 pass in proto tcp from any to any port 25
1526 pass in proto tcp from 10.0.0.0/8 port \*(Gt 1024 \e
1527 to ! 10.1.2.3 port != ssh
1528 pass in proto tcp from any os "OpenBSD"
1529 pass in proto tcp from route "DTAG"
1532 This is equivalent to "from any to any".
1533 .It Ar group Aq Ar group
1534 This functionality is not supported in this version of
1538 .\" this rule only applies to packets of sockets owned by the specified group.
1539 .It Ar user Aq Ar user
1540 This rule only applies to packets of sockets owned by the specified user.
1541 For outgoing connections initiated from the firewall, this is the user
1542 that opened the connection.
1543 For incoming connections to the firewall itself, this is the user that
1544 listens on the destination port.
1545 For forwarded connections, where the firewall is not a connection endpoint,
1546 the user and group are
1549 All packets, both outgoing and incoming, of one connection are associated
1550 with the same user and group.
1551 Only TCP and UDP packets can be associated with users; for other protocols
1552 these parameters are ignored.
1554 User and group refer to the effective (as opposed to the real) IDs, in
1555 case the socket is created by a setuid/setgid process.
1556 User and group IDs are stored when a socket is created;
1557 when a process creates a listening socket as root (for instance, by
1558 binding to a privileged port) and subsequently changes to another
1559 user ID (to drop privileges), the credentials will remain root.
1561 User and group IDs can be specified as either numbers or names.
1562 The syntax is similar to the one for ports.
1565 matches packets of forwarded connections.
1567 can only be used with the operators
1571 Other constructs like
1572 .Cm user \*(Ge unknown
1574 Forwarded packets with unknown user and group ID match only rules
1575 that explicitly compare against
1583 does not match forwarded packets.
1584 The following example allows only selected users to open outgoing
1586 .Bd -literal -offset indent
1587 block out proto { tcp, udp } all
1588 pass out proto { tcp, udp } all user { \*(Lt 1000, dhartmei }
1590 .It Ar flags Ao Ar a Ac Pf / Ns Ao Ar b Ac No \*(Ba / Ns \
1591 Ao Ar b Ac No \*(Ba any
1592 This rule only applies to TCP packets that have the flags
1596 Flags not specified in
1599 For stateful connections, the default is
1601 To indicate that flags should not be checked at all, specify
1603 The flags are: (F)IN, (S)YN, (R)ST, (P)USH, (A)CK, (U)RG, (E)CE, and C(W)R.
1607 The other flags are ignored.
1609 This is the default setting for stateful connections.
1610 Out of SYN and ACK, exactly SYN may be set.
1611 SYN, SYN+PSH and SYN+RST match, but SYN+ACK, ACK and ACK+RST do not.
1612 This is more restrictive than the previous example.
1614 If the first set is not specified, it defaults to none.
1615 All of SYN, FIN, RST and ACK must be unset.
1620 is applied by default (unless
1622 is specified), only the initial SYN packet of a TCP handshake will create
1623 a state for a TCP connection.
1624 It is possible to be less restrictive, and allow state creation from
1627 packets, by specifying
1631 to synchronize to existing connections, for instance
1632 if one flushes the state table.
1633 However, states created from such intermediate packets may be missing
1634 connection details such as the TCP window scaling factor.
1635 States which modify the packet flow, such as those affected by
1636 .Ar nat , binat No or Ar rdr
1638 .Ar modulate No or Ar synproxy state
1639 options, or scrubbed with
1641 will also not be recoverable from intermediate packets.
1642 Such connections will stall and time out.
1643 .It Ar icmp-type Ao Ar type Ac Ar code Ao Ar code Ac
1644 .It Ar icmp6-type Ao Ar type Ac Ar code Ao Ar code Ac
1645 This rule only applies to ICMP or ICMPv6 packets with the specified type
1647 Text names for ICMP types and codes are listed in
1651 This parameter is only valid for rules that cover protocols ICMP or
1653 The protocol and the ICMP type indicator
1660 .It Ar tos Ao Ar string Ac No \*(Ba Aq Ar number
1661 This rule applies to packets with the specified
1670 or as either hex or decimal.
1672 For example, the following rules are identical:
1673 .Bd -literal -offset indent
1674 pass all tos lowdelay
1679 By default, IPv4 packets with IP options or IPv6 packets with routing
1680 extension headers are blocked.
1685 rule, packets that pass the filter based on that rule (last matching)
1686 do so even if they contain IP options or routing extension headers.
1687 For packets that match state, the rule that initially created the
1691 rule that is used when a packet does not match any rules does not
1693 .It Ar label Aq Ar string
1694 Adds a label (name) to the rule, which can be used to identify the rule.
1697 shows per-rule statistics for rules that have labels.
1699 The following macros can be used in labels:
1701 .Bl -tag -width $srcaddr -compact -offset indent
1705 The source IP address.
1707 The destination IP address.
1709 The source port specification.
1711 The destination port specification.
1719 .Bd -literal -offset indent
1720 ips = \&"{ 1.2.3.4, 1.2.3.5 }\&"
1721 pass in proto tcp from any to $ips \e
1722 port \*(Gt 1023 label \&"$dstaddr:$dstport\&"
1726 .Bd -literal -offset indent
1727 pass in inet proto tcp from any to 1.2.3.4 \e
1728 port \*(Gt 1023 label \&"1.2.3.4:\*(Gt1023\&"
1729 pass in inet proto tcp from any to 1.2.3.5 \e
1730 port \*(Gt 1023 label \&"1.2.3.5:\*(Gt1023\&"
1733 The macro expansion for the
1735 directive occurs only at configuration file parse time, not during runtime.
1736 .It Ar queue Ao Ar queue Ac No \*(Ba ( Ao Ar queue Ac , Aq Ar queue )
1737 Packets matching this rule will be assigned to the specified queue.
1738 If two queues are given, packets which have a
1742 and TCP ACKs with no data payload will be assigned to the second one.
1748 .Bd -literal -offset indent
1749 pass in proto tcp to port 25 queue mail
1750 pass in proto tcp to port 22 queue(ssh_bulk, ssh_prio)
1752 .It Ar tag Aq Ar string
1753 Packets matching this rule will be tagged with the
1755 The tag acts as an internal marker that can be used to
1756 identify these packets later on.
1757 This can be used, for example, to provide trust between
1758 interfaces and to determine if packets have been
1759 processed by translation rules.
1762 meaning that the packet will be tagged even if the rule
1763 is not the last matching rule.
1764 Further matching rules can replace the tag with a
1765 new one but will not remove a previously applied tag.
1766 A packet is only ever assigned one tag at a time.
1767 Packet tagging can be done during
1772 rules in addition to filter rules.
1773 Tags take the same macros as labels (see above).
1774 .It Ar tagged Aq Ar string
1775 Used with filter or translation rules to specify that packets must already
1776 be tagged with the given tag in order to match the rule.
1777 Inverse tag matching can also be done
1783 .It Ar rtable Aq Ar number
1784 Used to select an alternate routing table for the routing lookup.
1785 Only effective before the route lookup happened, i.e. when filtering inbound.
1786 .It Ar probability Aq Ar number
1787 A probability attribute can be attached to a rule, with a value set between
1788 0 and 1, bounds not included.
1789 In that case, the rule will be honoured using the given probability value
1791 For example, the following rule will drop 20% of incoming ICMP packets:
1792 .Bd -literal -offset indent
1793 block in proto icmp probability 20%
1797 If a packet matches a rule with a route option set, the packet filter will
1798 route the packet according to the type of route option.
1799 When such a rule creates state, the route option is also applied to all
1800 packets matching the same connection.
1801 .Bl -tag -width xxxx
1805 option does a normal route lookup to find the next hop for the packet.
1809 option routes the packet to the specified interface with an optional address
1813 rule creates state, only packets that pass in the same direction as the
1814 filter rule specifies will be routed in this way.
1815 Packets passing in the opposite direction (replies) are not affected
1816 and are routed normally.
1820 option is similar to
1822 but routes packets that pass in the opposite direction (replies) to the
1823 specified interface.
1824 Opposite direction is only defined in the context of a state entry, and
1826 is useful only in rules that create state.
1827 It can be used on systems with multiple external connections to
1828 route all outgoing packets of a connection through the interface
1829 the incoming connection arrived through (symmetric routing enforcement).
1833 option creates a duplicate of the packet and routes it like
1835 The original packet gets routed as it normally would.
1842 rules, (as well as for the
1847 rule options) for which there is a single redirection address which has a
1848 subnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP
1849 address), a variety of different methods for assigning this address can be
1851 .Bl -tag -width xxxx
1855 option applies the network portion of the redirection address to the address
1856 to be modified (source with
1863 option selects an address at random within the defined block of addresses.
1867 option uses a hash of the source address to determine the redirection address,
1868 ensuring that the redirection address is always the same for a given source.
1869 An optional key can be specified after this keyword either in hex or as a
1872 randomly generates a key for source-hash every time the
1873 ruleset is reloaded.
1877 option loops through the redirection address(es).
1879 When more than one redirection address is specified,
1881 is the only permitted pool type.
1889 from modifying the source port on TCP and UDP packets.
1894 option can be specified to help ensure that multiple connections from the
1895 same source are mapped to the same redirection address.
1896 This option can be used with the
1901 Note that by default these associations are destroyed as soon as there are
1902 no longer states which refer to them; in order to make the mappings last
1903 beyond the lifetime of the states, increase the global options with
1904 .Ar set timeout src.track .
1906 .Sx STATEFUL TRACKING OPTIONS
1907 for more ways to control the source tracking.
1908 .Sh STATE MODULATION
1909 Much of the security derived from TCP is attributable to how well the
1910 initial sequence numbers (ISNs) are chosen.
1911 Some popular stack implementations choose
1913 poor ISNs and thus are normally susceptible to ISN prediction exploits.
1916 rule to a TCP connection,
1918 will create a high quality random sequence number for each connection
1923 directive implicitly keeps state on the rule and is
1924 only applicable to TCP connections.
1927 .Bd -literal -offset indent
1929 pass out proto tcp from any to any modulate state
1930 pass in proto tcp from any to any port 25 flags S/SFRA modulate state
1933 Note that modulated connections will not recover when the state table
1934 is lost (firewall reboot, flushing the state table, etc...).
1936 will not be able to infer a connection again after the state table flushes
1937 the connection's modulator.
1938 When the state is lost, the connection may be left dangling until the
1939 respective endpoints time out the connection.
1940 It is possible on a fast local network for the endpoints to start an ACK
1941 storm while trying to resynchronize after the loss of the modulator.
1944 settings (or a more strict equivalent) should be used on
1946 rules to prevent ACK storms.
1948 Note that alternative methods are available
1949 to prevent loss of the state table
1950 and allow for firewall failover.
1955 for further information.
1959 passes packets that are part of a
1961 handshake between the endpoints.
1964 option can be used to cause
1966 itself to complete the handshake with the active endpoint, perform a handshake
1967 with the passive endpoint, and then forward packets between the endpoints.
1969 No packets are sent to the passive endpoint before the active endpoint has
1970 completed the handshake, hence so-called SYN floods with spoofed source
1971 addresses will not reach the passive endpoint, as the sender can't complete the
1974 The proxy is transparent to both endpoints, they each see a single
1975 connection from/to the other endpoint.
1977 chooses random initial sequence numbers for both handshakes.
1978 Once the handshakes are completed, the sequence number modulators
1979 (see previous section) are used to translate further packets of the
1983 .Ar modulate state .
1993 .Bd -literal -offset indent
1994 pass in proto tcp from any to any port www synproxy state
1996 .Sh STATEFUL TRACKING OPTIONS
1997 A number of options related to stateful tracking can be applied on a
2003 support these options, and
2005 must be specified explicitly to apply options to a rule.
2007 .Bl -tag -width xxxx -compact
2008 .It Ar max Aq Ar number
2009 Limits the number of concurrent states the rule may create.
2010 When this limit is reached, further packets matching the rule that would
2011 create state are dropped, until existing states time out.
2013 .\" Prevent state changes for states created by this rule from appearing on the
2016 .It Ao Ar timeout Ac Aq Ar seconds
2017 Changes the timeout values used for states created by this rule.
2018 For a list of all valid timeout names, see
2023 Multiple options can be specified, separated by commas:
2024 .Bd -literal -offset indent
2025 pass in proto tcp from any to any \e
2026 port www keep state \e
2027 (max 100, source-track rule, max-src-nodes 75, \e
2028 max-src-states 3, tcp.established 60, tcp.closing 5)
2033 keyword is specified, the number of states per source IP is tracked.
2035 .Bl -tag -width xxxx -compact
2036 .It Ar source-track rule
2037 The maximum number of states created by this rule is limited by the rule's
2042 Only state entries created by this particular rule count toward the rule's
2044 .It Ar source-track global
2045 The number of states created by all rules that use this option is limited.
2046 Each rule can specify different
2050 options, however state entries created by any participating rule count towards
2051 each individual rule's limits.
2054 The following limits can be set:
2056 .Bl -tag -width xxxx -compact
2057 .It Ar max-src-nodes Aq Ar number
2058 Limits the maximum number of source addresses which can simultaneously
2059 have state table entries.
2060 .It Ar max-src-states Aq Ar number
2061 Limits the maximum number of simultaneous state entries that a single
2062 source address can create with this rule.
2065 For stateful TCP connections, limits on established connections (connections
2066 which have completed the TCP 3-way handshake) can also be enforced
2069 .Bl -tag -width xxxx -compact
2070 .It Ar max-src-conn Aq Ar number
2071 Limits the maximum number of simultaneous TCP connections which have
2072 completed the 3-way handshake that a single host can make.
2073 .It Ar max-src-conn-rate Ao Ar number Ac No / Aq Ar seconds
2074 Limit the rate of new connections over a time interval.
2075 The connection rate is an approximation calculated as a moving average.
2078 Because the 3-way handshake ensures that the source address is not being
2079 spoofed, more aggressive action can be taken based on these limits.
2081 .Ar overload Aq Ar table
2082 state option, source IP addresses which hit either of the limits on
2083 established connections will be added to the named table.
2084 This table can be used in the ruleset to block further activity from
2085 the offending host, redirect it to a tarpit process, or restrict its
2090 keyword kills all states created by the matching rule which originate
2091 from the host which exceeds these limits.
2094 modifier to the flush command kills all states originating from the
2095 offending host, regardless of which rule created the state.
2097 For example, the following rules will protect the webserver against
2098 hosts making more than 100 connections in 10 seconds.
2099 Any host which connects faster than this rate will have its address added
2102 table and have all states originating from it flushed.
2103 Any new packets arriving from this host will be dropped unconditionally
2105 .Bd -literal -offset indent
2106 block quick from \*(Ltbad_hosts\*(Gt
2107 pass in on $ext_if proto tcp to $webserver port www keep state \e
2108 (max-src-conn-rate 100/10, overload \*(Ltbad_hosts\*(Gt flush global)
2111 You can adjust the state policy on individual
2115 translation rules by adding a keyword
2120 at the end of the rule.
2121 For example, a rule such as this,
2122 .Bd -literal -offset indent
2123 nat on sip0 from 10/8 to ! 10/8 -> 192.168.1.4/32 if-bound
2126 will create states that only match packets on sip0.
2127 .Sh OPERATING SYSTEM FINGERPRINTING
2128 Passive OS Fingerprinting is a mechanism to inspect nuances of a TCP
2129 connection's initial SYN packet and guess at the host's operating system.
2130 Unfortunately these nuances are easily spoofed by an attacker so the
2131 fingerprint is not useful in making security decisions.
2132 But the fingerprint is typically accurate enough to make policy decisions
2135 The fingerprints may be specified by operating system class, by
2136 version, or by subtype/patchlevel.
2137 The class of an operating system is typically the vendor or genre
2143 The version of the oldest available
2145 release on the main FTP site
2146 would be 2.6 and the fingerprint would be written
2148 .Dl \&"OpenBSD 2.6\&"
2150 The subtype of an operating system is typically used to describe the
2151 patchlevel if that patch led to changes in the TCP stack behavior.
2154 the only subtype is for a fingerprint that was
2157 scrub option and would be specified as
2159 .Dl \&"OpenBSD 3.3 no-df\&"
2161 Fingerprints for most popular operating systems are provided by
2165 is running, a complete list of known operating system fingerprints may
2166 be listed by running:
2170 Filter rules can enforce policy at any level of operating system specification
2171 assuming a fingerprint is present.
2172 Policy could limit traffic to approved operating systems or even ban traffic
2173 from hosts that aren't at the latest service pack.
2177 class can also be used as the fingerprint which will match packets for
2178 which no operating system fingerprint is known.
2181 .Bd -literal -offset indent
2182 pass out proto tcp from any os OpenBSD
2183 block out proto tcp from any os Doors
2184 block out proto tcp from any os "Doors PT"
2185 block out proto tcp from any os "Doors PT SP3"
2186 block out from any os "unknown"
2187 pass on lo0 proto tcp from any os "OpenBSD 3.3 lo0"
2190 Operating system fingerprinting is limited only to the TCP SYN packet.
2191 This means that it will not work on other protocols and will not match
2192 a currently established connection.
2194 Caveat: operating system fingerprints are occasionally wrong.
2195 There are three problems: an attacker can trivially craft his packets to
2196 appear as any operating system he chooses;
2197 an operating system patch could change the stack behavior and no fingerprints
2198 will match it until the database is updated;
2199 and multiple operating systems may have the same fingerprint.
2200 .Sh BLOCKING SPOOFED TRAFFIC
2201 "Spoofing" is the faking of IP addresses, typically for malicious
2205 directive expands to a set of filter rules which will block all
2206 traffic with a source IP from the network(s) directly connected
2207 to the specified interface(s) from entering the system through
2208 any other interface.
2210 For example, the line
2211 .Bd -literal -offset indent
2216 .Bd -literal -offset indent
2217 block drop in on ! lo0 inet from 127.0.0.1/8 to any
2218 block drop in on ! lo0 inet6 from ::1 to any
2221 For non-loopback interfaces, there are additional rules to block incoming
2222 packets with a source IP address identical to the interface's IP(s).
2223 For example, assuming the interface wi0 had an IP address of 10.0.0.1 and a
2224 netmask of 255.255.255.0,
2226 .Bd -literal -offset indent
2227 antispoof for wi0 inet
2231 .Bd -literal -offset indent
2232 block drop in on ! wi0 inet from 10.0.0.0/24 to any
2233 block drop in inet from 10.0.0.1 to any
2236 Caveat: Rules created by the
2238 directive interfere with packets sent over loopback interfaces
2240 One should pass these explicitly.
2241 .Sh FRAGMENT HANDLING
2242 The size of IP datagrams (packets) can be significantly larger than the
2243 maximum transmission unit (MTU) of the network.
2244 In cases when it is necessary or more efficient to send such large packets,
2245 the large packet will be fragmented into many smaller packets that will each
2247 Unfortunately for a firewalling device, only the first logical fragment will
2248 contain the necessary header information for the subprotocol that allows
2250 to filter on things such as TCP ports or to perform NAT.
2254 rules as described in
2255 .Sx TRAFFIC NORMALIZATION
2256 above, there are three options for handling fragments in the packet filter.
2258 One alternative is to filter individual fragments with filter rules.
2261 rule applies to a fragment, it is passed to the filter.
2262 Filter rules with matching IP header parameters decide whether the
2263 fragment is passed or blocked, in the same way as complete packets
2265 Without reassembly, fragments can only be filtered based on IP header
2266 fields (source/destination address, protocol), since subprotocol header
2267 fields are not available (TCP/UDP port numbers, ICMP code/type).
2270 option can be used to restrict filter rules to apply only to
2271 fragments, but not complete packets.
2272 Filter rules without the
2274 option still apply to fragments, if they only specify IP header fields.
2275 For instance, the rule
2276 .Bd -literal -offset indent
2277 pass in proto tcp from any to any port 80
2280 never applies to a fragment, even if the fragment is part of a TCP
2281 packet with destination port 80, because without reassembly this information
2282 is not available for each fragment.
2283 This also means that fragments cannot create new or match existing
2284 state table entries, which makes stateful filtering and address
2285 translation (NAT, redirection) for fragments impossible.
2287 It's also possible to reassemble only certain fragments by specifying
2288 source or destination addresses or protocols as parameters in
2292 In most cases, the benefits of reassembly outweigh the additional
2293 memory cost, and it's recommended to use
2296 all fragments via the
2297 .Ar fragment reassemble
2300 The memory allocated for fragment caching can be limited using
2302 Once this limit is reached, fragments that would have to be cached
2303 are dropped until other entries time out.
2304 The timeout value can also be adjusted.
2306 Currently, only IPv4 fragments are supported and IPv6 fragments
2307 are blocked unconditionally.
2309 Besides the main ruleset,
2311 can load rulesets into
2316 is a container that can hold rules, address tables, and other anchors.
2320 has a name which specifies the path where
2322 can be used to access the anchor to perform operations on it, such as
2323 attaching child anchors to it or loading rules into it.
2324 Anchors may be nested, with components separated by
2326 characters, similar to how file system hierarchies are laid out.
2327 The main ruleset is actually the default anchor, so filter and
2328 translation rules, for example, may also be contained in any anchor.
2330 An anchor can reference another
2333 using the following kinds
2335 .Bl -tag -width xxxx
2336 .It Ar nat-anchor Aq Ar name
2339 rules in the specified
2341 .It Ar rdr-anchor Aq Ar name
2344 rules in the specified
2346 .It Ar binat-anchor Aq Ar name
2349 rules in the specified
2351 .It Ar anchor Aq Ar name
2352 Evaluates the filter rules in the specified
2354 .It Ar load anchor Ao Ar name Ac Ar from Aq Ar file
2355 Loads the rules from the specified file into the
2360 When evaluation of the main ruleset reaches an
2364 will proceed to evaluate all rules specified in that anchor.
2366 Matching filter and translation rules marked with the
2368 option are final and abort the evaluation of the rules in other
2369 anchors and the main ruleset.
2372 itself is marked with the
2375 ruleset evaluation will terminate when the anchor is exited if the packet is
2376 matched by any rule within the anchor.
2379 rules are evaluated relative to the anchor in which they are contained.
2382 rules specified in the main ruleset will reference anchor
2383 attachment points underneath the main ruleset, and
2385 rules specified in a file loaded from a
2387 rule will be attached under that anchor point.
2389 Rules may be contained in
2391 attachment points which do not contain any rules when the main ruleset
2392 is loaded, and later such anchors can be manipulated through
2394 without reloading the main ruleset or other anchors.
2396 .Bd -literal -offset indent
2398 block on $ext_if all
2400 pass out on $ext_if all
2401 pass in on $ext_if proto tcp from any \e
2402 to $ext_if port smtp
2405 blocks all packets on the external interface by default, then evaluates
2408 named "spam", and finally passes all outgoing connections and
2409 incoming connections to port 25.
2410 .Bd -literal -offset indent
2411 # echo \&"block in quick from 1.2.3.4 to any\&" \&| \e
2415 This loads a single rule into the
2417 which blocks all packets from a specific address.
2419 The anchor can also be populated by adding a
2424 .Bd -literal -offset indent
2426 load anchor spam from "/etc/pf-spam.conf"
2433 it will also load all the rules from the file
2434 .Pa /etc/pf-spam.conf
2439 rules can specify the parameter's
2440 direction, interface, address family, protocol and source/destination
2442 using the same syntax as filter rules.
2443 When parameters are used, the
2445 rule is only evaluated for matching packets.
2446 This allows conditional evaluation of anchors, like:
2447 .Bd -literal -offset indent
2448 block on $ext_if all
2449 anchor spam proto tcp from any to any port smtp
2450 pass out on $ext_if all
2451 pass in on $ext_if proto tcp from any to $ext_if port smtp
2456 spam are only evaluated for
2458 packets with destination port 25.
2460 .Bd -literal -offset indent
2461 # echo \&"block in quick from 1.2.3.4 to any" \&| \e
2465 will only block connections from 1.2.3.4 to port 25.
2467 Anchors may end with the asterisk
2469 character, which signifies that all anchors attached at that point
2470 should be evaluated in the alphabetical ordering of their anchor name.
2472 .Bd -literal -offset indent
2476 will evaluate each rule in each anchor attached to the
2479 Note that it will only evaluate anchors that are directly attached to the
2481 anchor, and will not descend to evaluate anchors recursively.
2483 Since anchors are evaluated relative to the anchor in which they are
2484 contained, there is a mechanism for accessing the parent and ancestor
2485 anchors of a given anchor.
2486 Similar to file system path name resolution, if the sequence
2488 appears as an anchor path component, the parent anchor of the current
2489 anchor in the path evaluation at that point will become the new current
2491 As an example, consider the following:
2492 .Bd -literal -offset indent
2493 # echo ' anchor "spam/allowed" ' | pfctl -f -
2494 # echo -e ' anchor "../banned" \en pass' | \e
2495 pfctl -a spam/allowed -f -
2498 Evaluation of the main ruleset will lead into the
2500 anchor, which will evaluate the rules in the
2502 anchor, if any, before finally evaluating the
2508 can also be loaded inline in the ruleset within a brace ('{' '}') delimited
2510 Brace delimited blocks may contain rules or other brace-delimited blocks.
2511 When anchors are loaded this way the anchor name becomes optional.
2512 .Bd -literal -offset indent
2513 anchor "external" on egress {
2516 pass proto tcp from any to port { 25, 80, 443 }
2518 pass in proto tcp to any port 22
2522 Since the parser specification for anchor names is a string, any
2523 reference to an anchor name containing solidus
2525 characters will require double quote
2527 characters around the anchor name.
2528 .Sh TRANSLATION EXAMPLES
2529 This example maps incoming requests on port 80 to port 8080, on
2530 which a daemon is running (because, for example, it is not run as root,
2531 and therefore lacks permission to bind to port 80).
2533 # use a macro for the interface name, so it can be changed easily
2536 # map daemon on 8080 to appear to be on 80
2537 rdr on $ext_if proto tcp from any to any port 80 -\*(Gt 127.0.0.1 port 8080
2542 modifier is given, packets matching the translation rule are passed without
2543 inspecting the filter rules:
2545 rdr pass on $ext_if proto tcp from any to any port 80 -\*(Gt 127.0.0.1 \e
2549 In the example below, vlan12 is configured as 192.168.168.1;
2550 the machine translates all packets coming from 192.168.168.0/24 to 204.92.77.111
2551 when they are going out any interface except vlan12.
2552 This has the net effect of making traffic from the 192.168.168.0/24
2553 network appear as though it is the Internet routable address
2554 204.92.77.111 to nodes behind any interface on the router except
2555 for the nodes on vlan12.
2556 (Thus, 192.168.168.1 can talk to the 192.168.168.0/24 nodes.)
2558 nat on ! vlan12 from 192.168.168.0/24 to any -\*(Gt 204.92.77.111
2561 In the example below, the machine sits between a fake internal 144.19.74.*
2562 network, and a routable external IP of 204.92.77.100.
2565 rule excludes protocol AH from being translated.
2568 no nat on $ext_if proto ah from 144.19.74.0/24 to any
2569 nat on $ext_if from 144.19.74.0/24 to any -\*(Gt 204.92.77.100
2572 In the example below, packets bound for one specific server, as well as those
2573 generated by the sysadmins are not proxied; all other connections are.
2576 no rdr on $int_if proto { tcp, udp } from any to $server port 80
2577 no rdr on $int_if proto { tcp, udp } from $sysadmins to any port 80
2578 rdr on $int_if proto { tcp, udp } from any to any port 80 -\*(Gt 127.0.0.1 \e
2582 This longer example uses both a NAT and a redirection.
2583 The external interface has the address 157.161.48.183.
2584 On localhost, we are running
2586 waiting for FTP sessions to be redirected to it.
2587 The three mandatory anchors for
2589 are omitted from this example; see the
2594 # Translate outgoing packets' source addresses (any protocol).
2595 # In this case, any address but the gateway's external address is mapped.
2596 nat on $ext_if inet from ! ($ext_if) to any -\*(Gt ($ext_if)
2599 # Map outgoing packets' source port to an assigned proxy port instead of
2600 # an arbitrary port.
2601 # In this case, proxy outgoing isakmp with port 500 on the gateway.
2602 nat on $ext_if inet proto udp from any port = isakmp to any -\*(Gt ($ext_if) \e
2606 # Translate outgoing packets' source address (any protocol).
2607 # Translate incoming packets' destination address to an internal machine
2609 binat on $ext_if from 10.1.2.150 to any -\*(Gt $ext_if
2612 # Translate incoming packets' destination addresses.
2613 # As an example, redirect a TCP and UDP port to an internal machine.
2614 rdr on $ext_if inet proto tcp from any to ($ext_if) port 8080 \e
2615 -\*(Gt 10.1.2.151 port 22
2616 rdr on $ext_if inet proto udp from any to ($ext_if) port 8080 \e
2617 -\*(Gt 10.1.2.151 port 53
2620 # Translate outgoing ftp control connections to send them to localhost
2621 # for proxying with ftp-proxy(8) running on port 8021.
2622 rdr on $int_if proto tcp from any to any port 21 -\*(Gt 127.0.0.1 port 8021
2625 In this example, a NAT gateway is set up to translate internal addresses
2626 using a pool of public addresses (192.0.2.16/28) and to redirect
2627 incoming web server connections to a group of web servers on the internal
2631 # Translate outgoing packets' source addresses using an address pool.
2632 # A given source address is always translated to the same pool address by
2633 # using the source-hash keyword.
2634 nat on $ext_if inet from any to any -\*(Gt 192.0.2.16/28 source-hash
2637 # Translate incoming web server connections to a group of web servers on
2638 # the internal network.
2639 rdr on $ext_if proto tcp from any to any port 80 \e
2640 -\*(Gt { 10.1.2.155, 10.1.2.160, 10.1.2.161 } round-robin
2644 # The external interface is kue0
2645 # (157.161.48.183, the only routable address)
2646 # and the private network is 10.0.0.0/8, for which we are doing NAT.
2648 # use a macro for the interface name, so it can be changed easily
2651 # normalize all incoming traffic
2652 scrub in on $ext_if all fragment reassemble
2654 # block and log everything by default
2655 block return log on $ext_if all
2657 # block anything coming from source we have no back routes for
2658 block in from no-route to any
2660 # block packets whose ingress interface does not match the one in
2661 # the route back to their source address
2662 block in from urpf-failed to any
2664 # block and log outgoing packets that do not have our address as source,
2665 # they are either spoofed or something is misconfigured (NAT disabled,
2666 # for instance), we want to be nice and do not send out garbage.
2667 block out log quick on $ext_if from ! 157.161.48.183 to any
2669 # silently drop broadcasts (cable modem noise)
2670 block in quick on $ext_if from any to 255.255.255.255
2672 # block and log incoming packets from reserved address space and invalid
2673 # addresses, they are either spoofed or misconfigured, we cannot reply to
2674 # them anyway (hence, no return-rst).
2675 block in log quick on $ext_if from { 10.0.0.0/8, 172.16.0.0/12, \e
2676 192.168.0.0/16, 255.255.255.255/32 } to any
2680 # pass out/in certain ICMP queries and keep state (ping)
2681 # state matching is done on host addresses and ICMP id (not type/code),
2682 # so replies (like 0/0 for 8/0) will match queries
2683 # ICMP error messages (which always refer to a TCP/UDP packet) are
2684 # handled by the TCP/UDP states
2685 pass on $ext_if inet proto icmp all icmp-type 8 code 0
2689 # pass out all UDP connections and keep state
2690 pass out on $ext_if proto udp all
2692 # pass in certain UDP connections and keep state (DNS)
2693 pass in on $ext_if proto udp from any to any port domain
2697 # pass out all TCP connections and modulate state
2698 pass out on $ext_if proto tcp all modulate state
2700 # pass in certain TCP connections and keep state (SSH, SMTP, DNS, IDENT)
2701 pass in on $ext_if proto tcp from any to any port { ssh, smtp, domain, \e
2704 # Do not allow Windows 9x SMTP connections since they are typically
2705 # a viral worm. Alternately we could limit these OSes to 1 connection each.
2706 block in on $ext_if proto tcp from any os {"Windows 95", "Windows 98"} \e
2710 # pass in/out all IPv6 traffic: note that we have to enable this in two
2711 # different ways, on both our physical interface and our tunnel
2712 pass quick on gif0 inet6
2713 pass quick on $ext_if proto ipv6
2717 # three interfaces: $int_if, $ext_if, and $wifi_if (wireless). NAT is
2718 # being done on $ext_if for all outgoing packets. tag packets in on
2719 # $int_if and pass those tagged packets out on $ext_if. all other
2720 # outgoing packets (i.e., packets from the wireless network) are only
2721 # permitted to access port 80.
2723 pass in on $int_if from any to any tag INTNET
2724 pass in on $wifi_if from any to any
2726 block out on $ext_if from any to any
2727 pass out quick on $ext_if tagged INTNET
2728 pass out on $ext_if proto tcp from any to any port 80
2730 # tag incoming packets as they are redirected to spamd(8). use the tag
2731 # to pass those packets through the packet filter.
2733 rdr on $ext_if inet proto tcp from \*(Ltspammers\*(Gt to port smtp \e
2734 tag SPAMD -\*(Gt 127.0.0.1 port spamd
2737 pass in on $ext_if inet proto tcp tagged SPAMD
2744 line = ( option | pf-rule | nat-rule | binat-rule | rdr-rule |
2745 antispoof-rule | altq-rule | queue-rule | trans-anchors |
2746 anchor-rule | anchor-close | load-anchor | table-rule | )
2748 option = "set" ( [ "timeout" ( timeout | "{" timeout-list "}" ) ] |
2749 [ "ruleset-optimization" [ "none" | "basic" | "profile" ]] |
2750 [ "optimization" [ "default" | "normal" |
2751 "high-latency" | "satellite" |
2752 "aggressive" | "conservative" ] ]
2753 [ "limit" ( limit-item | "{" limit-list "}" ) ] |
2754 [ "loginterface" ( interface-name | "none" ) ] |
2755 [ "block-policy" ( "drop" | "return" ) ] |
2756 [ "state-policy" ( "if-bound" | "floating" ) ]
2757 [ "require-order" ( "yes" | "no" ) ]
2758 [ "fingerprints" filename ] |
2759 [ "skip on" ifspec ] |
2760 [ "debug" ( "none" | "urgent" | "misc" | "loud" ) ] )
2762 pf-rule = action [ ( "in" | "out" ) ]
2763 [ "log" [ "(" logopts ")"] ] [ "quick" ]
2764 [ "on" ifspec ] [ "fastroute" | route ] [ af ] [ protospec ]
2765 hosts [ filteropt-list ]
2767 logopts = logopt [ "," logopts ]
2768 logopt = "all" | "user" | "to" interface-name
2770 filteropt-list = filteropt-list filteropt | filteropt
2771 filteropt = user | group | flags | icmp-type | icmp6-type | tos |
2772 ( "no" | "keep" | "modulate" | "synproxy" ) "state"
2773 [ "(" state-opts ")" ] |
2774 "fragment" | "no-df" | "min-ttl" number |
2775 "max-mss" number | "random-id" | "reassemble tcp" |
2776 fragmentation | "allow-opts" |
2777 "label" string | "tag" string | [ ! ] "tagged" string |
2778 "queue" ( string | "(" string [ [ "," ] string ] ")" ) |
2779 "rtable" number | "probability" number"%"
2781 nat-rule = [ "no" ] "nat" [ "pass" [ "log" [ "(" logopts ")" ] ] ]
2782 [ "on" ifspec ] [ af ]
2783 [ protospec ] hosts [ "tag" string ] [ "tagged" string ]
2784 [ "-\*(Gt" ( redirhost | "{" redirhost-list "}" )
2785 [ portspec ] [ pooltype ] [ "static-port" ] ]
2786 [ ( "if-bound" | "group-bound" | "floating" ) ]
2788 binat-rule = [ "no" ] "binat" [ "pass" [ "log" [ "(" logopts ")" ] ] ]
2789 [ "on" interface-name ] [ af ]
2790 [ "proto" ( proto-name | proto-number ) ]
2791 "from" address [ "/" mask-bits ] "to" ipspec
2792 [ "tag" string ] [ "tagged" string ]
2793 [ "-\*(Gt" address [ "/" mask-bits ] ]
2795 rdr-rule = [ "no" ] "rdr" [ "pass" [ "log" [ "(" logopts ")" ] ] ]
2796 [ "on" ifspec ] [ af ]
2797 [ protospec ] hosts [ "tag" string ] [ "tagged" string ]
2798 [ "-\*(Gt" ( redirhost | "{" redirhost-list "}" )
2799 [ portspec ] [ pooltype ] ]
2800 [ ( "if-bound" | "group-bound" | "floating" ) ]
2802 antispoof-rule = "antispoof" [ "log" ] [ "quick" ]
2803 "for" ifspec [ af ] [ "label" string ]
2805 table-rule = "table" "\*(Lt" string "\*(Gt" [ tableopts-list ]
2806 tableopts-list = tableopts-list tableopts | tableopts
2807 tableopts = "persist" | "const" | "file" string |
2808 "{" [ tableaddr-list ] "}"
2809 tableaddr-list = tableaddr-list [ "," ] tableaddr-spec | tableaddr-spec
2810 tableaddr-spec = [ "!" ] tableaddr [ "/" mask-bits ]
2811 tableaddr = hostname | ifspec | "self" |
2812 ipv4-dotted-quad | ipv6-coloned-hex
2814 altq-rule = "altq on" interface-name queueopts-list
2816 queue-rule = "queue" string [ "on" interface-name ] queueopts-list
2819 anchor-rule = "anchor" [ string ] [ ( "in" | "out" ) ] [ "on" ifspec ]
2820 [ af ] [ protospec ] [ hosts ] [ "{" ]
2824 trans-anchors = ( "nat-anchor" | "rdr-anchor" | "binat-anchor" ) string
2825 [ "on" ifspec ] [ af ] [ "proto" ] [ protospec ] [ hosts ]
2827 load-anchor = "load anchor" string "from" filename
2829 queueopts-list = queueopts-list queueopts | queueopts
2830 queueopts = [ "bandwidth" bandwidth-spec ] |
2831 [ "qlimit" number ] | [ "tbrsize" number ] |
2832 [ "priority" number ] | [ schedulers ]
2833 schedulers = ( cbq-def | priq-def | hfsc-def )
2834 bandwidth-spec = "number" ( "b" | "Kb" | "Mb" | "Gb" | "%" )
2836 action = "pass" | "block" [ return ] | [ "no" ] "scrub"
2837 return = "drop" | "return" | "return-rst" [ "( ttl" number ")" ] |
2838 "return-icmp" [ "(" icmpcode [ [ "," ] icmp6code ] ")" ] |
2839 "return-icmp6" [ "(" icmp6code ")" ]
2840 icmpcode = ( icmp-code-name | icmp-code-number )
2841 icmp6code = ( icmp6-code-name | icmp6-code-number )
2843 ifspec = ( [ "!" ] ( interface-name | interface-group ) ) |
2844 "{" interface-list "}"
2845 interface-list = [ "!" ] ( interface-name | interface-group )
2846 [ [ "," ] interface-list ]
2847 route = ( "route-to" | "reply-to" | "dup-to" )
2848 ( routehost | "{" routehost-list "}" )
2850 af = "inet" | "inet6"
2852 protospec = "proto" ( proto-name | proto-number |
2853 "{" proto-list "}" )
2854 proto-list = ( proto-name | proto-number ) [ [ "," ] proto-list ]
2857 "from" ( "any" | "no-route" | "urpf-failed" | "self" | host |
2858 "{" host-list "}" | "route" string ) [ port ] [ os ]
2859 "to" ( "any" | "no-route" | "self" | host |
2860 "{" host-list "}" | "route" string ) [ port ]
2862 ipspec = "any" | host | "{" host-list "}"
2863 host = [ "!" ] ( address [ "/" mask-bits ] | "\*(Lt" string "\*(Gt" )
2864 redirhost = address [ "/" mask-bits ]
2865 routehost = "(" interface-name [ address [ "/" mask-bits ] ] ")"
2866 address = ( interface-name | interface-group |
2867 "(" ( interface-name | interface-group ) ")" |
2868 hostname | ipv4-dotted-quad | ipv6-coloned-hex )
2869 host-list = host [ [ "," ] host-list ]
2870 redirhost-list = redirhost [ [ "," ] redirhost-list ]
2871 routehost-list = routehost [ [ "," ] routehost-list ]
2873 port = "port" ( unary-op | binary-op | "{" op-list "}" )
2874 portspec = "port" ( number | name ) [ ":" ( "*" | number | name ) ]
2875 os = "os" ( os-name | "{" os-list "}" )
2876 user = "user" ( unary-op | binary-op | "{" op-list "}" )
2877 .\" group = "group" ( unary-op | binary-op | "{" op-list "}" )
2879 unary-op = [ "=" | "!=" | "\*(Lt" | "\*(Le" | "\*(Gt" | "\*(Ge" ]
2881 binary-op = number ( "\*(Lt\*(Gt" | "\*(Gt\*(Lt" | ":" ) number
2882 op-list = ( unary-op | binary-op ) [ [ "," ] op-list ]
2884 os-name = operating-system-name
2885 os-list = os-name [ [ "," ] os-list ]
2887 flags = "flags" ( [ flag-set ] "/" flag-set | "any" )
2888 flag-set = [ "F" ] [ "S" ] [ "R" ] [ "P" ] [ "A" ] [ "U" ] [ "E" ]
2891 icmp-type = "icmp-type" ( icmp-type-code | "{" icmp-list "}" )
2892 icmp6-type = "icmp6-type" ( icmp-type-code | "{" icmp-list "}" )
2893 icmp-type-code = ( icmp-type-name | icmp-type-number )
2894 [ "code" ( icmp-code-name | icmp-code-number ) ]
2895 icmp-list = icmp-type-code [ [ "," ] icmp-list ]
2897 tos = "tos" ( "lowdelay" | "throughput" | "reliability" |
2900 state-opts = state-opt [ [ "," ] state-opts ]
2901 state-opt = ( "max" number | timeout |
2902 "source-track" [ ( "rule" | "global" ) ] |
2903 "max-src-nodes" number | "max-src-states" number |
2904 "max-src-conn" number |
2905 "max-src-conn-rate" number "/" number |
2906 "overload" "\*(Lt" string "\*(Gt" [ "flush" ] |
2907 "if-bound" | "floating" )
2909 fragmentation = [ "fragment reassemble" | "fragment crop" |
2910 "fragment drop-ovl" ]
2912 timeout-list = timeout [ [ "," ] timeout-list ]
2913 timeout = ( "tcp.first" | "tcp.opening" | "tcp.established" |
2914 "tcp.closing" | "tcp.finwait" | "tcp.closed" |
2915 "udp.first" | "udp.single" | "udp.multiple" |
2916 "icmp.first" | "icmp.error" |
2917 "other.first" | "other.single" | "other.multiple" |
2918 "frag" | "interval" | "src.track" |
2919 "adaptive.start" | "adaptive.end" ) number
2921 limit-list = limit-item [ [ "," ] limit-list ]
2922 limit-item = ( "states" | "frags" | "src-nodes" ) number
2924 pooltype = ( "bitmask" | "random" |
2925 "source-hash" [ ( hex-key | string-key ) ] |
2926 "round-robin" ) [ sticky-address ]
2928 subqueue = string | "{" queue-list "}"
2929 queue-list = string [ [ "," ] string ]
2930 cbq-def = "cbq" [ "(" cbq-opt [ [ "," ] cbq-opt ] ")" ]
2931 priq-def = "priq" [ "(" priq-opt [ [ "," ] priq-opt ] ")" ]
2932 hfsc-def = "hfsc" [ "(" hfsc-opt [ [ "," ] hfsc-opt ] ")" ]
2933 cbq-opt = ( "default" | "borrow" | "red" | "ecn" | "rio" )
2934 priq-opt = ( "default" | "red" | "ecn" | "rio" )
2935 hfsc-opt = ( "default" | "red" | "ecn" | "rio" |
2936 linkshare-sc | realtime-sc | upperlimit-sc )
2937 linkshare-sc = "linkshare" sc-spec
2938 realtime-sc = "realtime" sc-spec
2939 upperlimit-sc = "upperlimit" sc-spec
2940 sc-spec = ( bandwidth-spec |
2941 "(" bandwidth-spec number bandwidth-spec ")" )
2944 .Bl -tag -width "/etc/protocols" -compact
2948 Default location of the ruleset file.
2950 Default location of OS fingerprints.
2951 .It Pa /etc/protocols
2952 Protocol name database.
2953 .It Pa /etc/services
2954 Service name database.
2955 .It Pa /usr/share/examples/pf
2980 file format first appeared in