2 .\" $OpenBSD: pf.conf.5,v 1.406 2009/01/31 19:37:12 sobrado 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 Comments can be put anywhere in the file using a hash mark
85 and extend to the end of the current line.
87 Additional configuration files can be included with the
90 .Bd -literal -offset indent
91 include "/etc/pf/sub.filter.conf"
94 Macros can be defined that will later be expanded in context.
95 Macro names must start with a letter, and may contain letters, digits
97 Macro names may not be reserved words (for example
101 Macros are not expanded inside quotes.
104 .Bd -literal -offset indent
106 all_ifs = \&"{\&" $ext_if lo0 \&"}\&"
107 pass out on $ext_if from any to any
108 pass in on $ext_if proto tcp from any to any port 25
111 Tables are named structures which can hold a collection of addresses and
113 Lookups against tables in
115 are relatively fast, making a single rule with tables much more efficient,
117 processor usage and memory consumption, than a large number of rules which
118 differ only in IP address (either created explicitly or automatically by rule
121 Tables can be used as the source or destination of filter rules,
125 translation rules such as
129 (see below for details on the various rule types).
130 Tables can also be used for the redirect address of
134 rules and in the routing options of filter rules, but only for
138 Tables can be defined with any of the following
141 As with macros, reserved words may not be used as table names.
142 .Bl -tag -width "manually"
144 Persistent tables can be manually created with the
150 before or after the ruleset has been loaded.
152 Table definitions can be placed directly in this file, and loaded at the
153 same time as other rules are loaded, atomically.
154 Table definitions inside
158 statement, and are especially useful to define non-persistent tables.
159 The contents of a pre-existing table defined without a list of addresses
160 to initialize it is not altered when
163 A table initialized with the empty list,
165 will be cleared on load.
168 Tables may be defined with the following attributes:
169 .Bl -tag -width persist
173 flag forces the kernel to keep the table even when no rules refer to it.
174 If the flag is not set, the kernel will automatically remove the table
175 when the last rule referring to it is flushed.
179 flag prevents the user from altering the contents of the table once it
183 can be used to add or remove addresses from the table at any time, even
190 flag enables per-address packet and byte counters which can be displayed with
192 Note that this feature carries significant memory overhead for large tables.
196 .Bd -literal -offset indent
197 table \*(Ltprivate\*(Gt const { 10/8, 172.16/12, 192.168/16 }
198 table \*(Ltbadhosts\*(Gt persist
199 block on fxp0 from { \*(Ltprivate\*(Gt, \*(Ltbadhosts\*(Gt } to any
202 creates a table called private, to hold RFC 1918 private network
203 blocks, and a table called badhosts, which is initially empty.
204 A filter rule is set up to block all traffic coming from addresses listed in
206 The private table cannot have its contents changed and the badhosts table
207 will exist even when no active filter rules reference it.
208 Addresses may later be added to the badhosts table, so that traffic from
209 these hosts can be blocked by using
210 .Bd -literal -offset indent
211 # pfctl -t badhosts -Tadd 204.92.77.111
214 A table can also be initialized with an address list specified in one or more
215 external files, using the following syntax:
216 .Bd -literal -offset indent
217 table \*(Ltspam\*(Gt persist file \&"/etc/spammers\&" file \&"/etc/openrelays\&"
218 block on fxp0 from \*(Ltspam\*(Gt to any
225 list IP addresses, one per line.
226 Any lines beginning with a # are treated as comments and ignored.
227 In addition to being specified by IP address, hosts may also be
228 specified by their hostname.
229 When the resolver is called to add a hostname to a table,
231 resulting IPv4 and IPv6 addresses are placed into the table.
232 IP addresses can also be entered in a table by specifying a valid interface
233 name, a valid interface group or the
235 keyword, in which case all addresses assigned to the interface(s) will be
239 may be tuned for various situations using the
245 .Bl -tag -width "src.track" -compact
247 Interval between purging expired states and fragments.
249 Seconds before an unassembled fragment is expired.
251 Length of time to retain a source tracking entry after the last state
255 When a packet matches a stateful connection, the seconds to live for the
256 connection will be updated to that of the
258 which corresponds to the connection state.
259 Each packet which matches this state will reset the TTL.
260 Tuning these values may improve the performance of the
261 firewall at the risk of dropping valid idle connections.
263 .Bl -tag -width xxxx -compact
265 The state after the first packet.
267 The state before the destination host ever sends a packet.
268 .It Ar tcp.established
269 The fully established state.
271 The state after the first FIN has been sent.
273 The state after both FINs have been exchanged and the connection is closed.
274 Some hosts (notably web servers on Solaris) send TCP packets even after closing
280 can prevent blocking of such packets.
282 The state after one endpoint sends an RST.
285 ICMP and UDP are handled in a fashion similar to TCP, but with a much more
286 limited set of states:
288 .Bl -tag -width xxxx -compact
290 The state after the first packet.
292 The state if the source host sends more than one packet but the destination
293 host has never sent one back.
295 The state if both hosts have sent packets.
297 The state after the first packet.
299 The state after an ICMP error came back in response to an ICMP packet.
302 Other protocols are handled similarly to UDP:
304 .Bl -tag -width xxxx -compact
307 .It Ar other.multiple
310 Timeout values can be reduced adaptively as the number of state table
313 .Bl -tag -width xxxx -compact
314 .It Ar adaptive.start
315 When the number of state entries exceeds this value, adaptive scaling
317 All timeout values are scaled linearly with factor
318 (adaptive.end - number of states) / (adaptive.end - adaptive.start).
320 When reaching this number of state entries, all timeout values become
321 zero, effectively purging all state entries immediately.
322 This value is used to define the scale factor, it should not actually
323 be reached (set a lower state limit, see below).
326 Adaptive timeouts are enabled by default, with an adaptive.start value
327 equal to 60% of the state limit, and an adaptive.end value equal to
328 120% of the state limit.
329 They can be disabled by setting both adaptive.start and adaptive.end to 0.
331 The adaptive timeout values can be defined both globally and for each rule.
332 When used on a per-rule basis, the values relate to the number of
333 states created by the rule, otherwise to the total number of
337 .Bd -literal -offset indent
338 set timeout tcp.first 120
339 set timeout tcp.established 86400
340 set timeout { adaptive.start 6000, adaptive.end 12000 }
341 set limit states 10000
344 With 9000 state table entries, the timeout values are scaled to 50%
345 (tcp.first 60, tcp.established 43200).
346 .It Ar set loginterface
347 Enable collection of packet and byte count statistics for the given
348 interface or interface group.
349 These statistics can be viewed using
350 .Bd -literal -offset indent
356 collects statistics on the interface named dc0:
357 .Bd -literal -offset indent
361 One can disable the loginterface using:
362 .Bd -literal -offset indent
363 set loginterface none
366 Sets hard limits on the memory pools used by the packet filter.
369 for an explanation of memory pools.
372 .Bd -literal -offset indent
373 set limit states 20000
376 sets the maximum number of entries in the memory pool used by state table
377 entries (generated by
379 rules which do not specify
383 .Bd -literal -offset indent
384 set limit frags 20000
387 sets the maximum number of entries in the memory pool used for fragment
388 reassembly (generated by
392 .Bd -literal -offset indent
393 set limit src-nodes 2000
396 sets the maximum number of entries in the memory pool used for tracking
397 source IP addresses (generated by the
403 .Bd -literal -offset indent
404 set limit tables 1000
405 set limit table-entries 100000
408 sets limits on the memory pools used by tables.
409 The first limits the number of tables that can exist to 1000.
410 The second limits the overall number of addresses that can be stored
413 Various limits can be combined on a single line:
414 .Bd -literal -offset indent
415 set limit { states 20000, frags 20000, src-nodes 2000 }
417 .It Ar set ruleset-optimization
418 .Bl -tag -width xxxxxxxx -compact
420 Disable the ruleset optimizer.
422 Enable basic ruleset optimization.
423 This is the default behaviour.
424 Basic ruleset optimization does four things to improve the
425 performance of ruleset evaluations:
429 remove duplicate rules
431 remove rules that are a subset of another rule
433 combine multiple rules into a table when advantageous
435 re-order the rules to improve evaluation performance
439 Uses the currently loaded ruleset as a feedback profile to tailor the
440 ordering of quick rules to actual network traffic.
443 It is important to note that the ruleset optimizer will modify the ruleset
444 to improve performance.
445 A side effect of the ruleset modification is that per-rule accounting
446 statistics will have different meanings than before.
447 If per-rule accounting is important for billing purposes or whatnot,
448 either the ruleset optimizer should not be used or a label field should
449 be added to all of the accounting rules to act as optimization barriers.
451 Optimization can also be set as a command-line argument to
453 overriding the settings in
455 .It Ar set optimization
456 Optimize state timeouts for one of the following network environments:
458 .Bl -tag -width xxxx -compact
460 A normal network environment.
461 Suitable for almost all networks.
463 A high-latency environment (such as a satellite connection).
468 Aggressively expire connections.
469 This can greatly reduce the memory usage of the firewall at the cost of
470 dropping idle connections early.
472 Extremely conservative settings.
473 Avoid dropping legitimate connections at the
474 expense of greater memory utilization (possibly much greater on a busy
475 network) and slightly increased processor utilization.
479 .Bd -literal -offset indent
480 set optimization aggressive
482 .It Ar set block-policy
485 option sets the default behaviour for the packet
489 .Bl -tag -width xxxxxxxx -compact
491 Packet is silently dropped.
493 A TCP RST is returned for blocked TCP packets,
494 an ICMP UNREACHABLE is returned for blocked UDP packets,
495 and all other packets are silently dropped.
499 .Bd -literal -offset indent
500 set block-policy return
502 .It Ar set fail-policy
505 option sets the behaviour of rules which should pass a packet but were
507 This might happen when a nat or route-to rule uses an empty table as list
508 of targets or if a rule fails to create state or source node.
511 actions are possible:
513 .Bl -tag -width xxxxxxxx -compact
515 Incoming packet is silently dropped.
517 Incoming packet is dropped and TCP RST is returned for TCP packets,
518 an ICMP UNREACHABLE is returned for UDP packets,
519 and no response is sent for other packets.
523 .Bd -literal -offset indent
524 set fail-policy return
526 .It Ar set state-policy
529 option sets the default behaviour for states:
531 .Bl -tag -width group-bound -compact
533 States are bound to interface.
535 States can match packets on any interfaces (the default).
539 .Bd -literal -offset indent
540 set state-policy if-bound
542 .It Ar set state-defaults
545 option sets the state options for states created from rules
549 .Bd -literal -offset indent
550 set state-defaults no-sync
555 identifies this firewall's state table entries to other firewalls
559 By default the hostid is set to a pseudo-random value, however it may be
560 desirable to manually configure it, for example to more easily identify the
561 source of state table entries.
562 .Bd -literal -offset indent
566 The hostid may be specified in either decimal or hexadecimal.
567 .It Ar set require-order
570 enforces an ordering of the statement types in the ruleset to:
576 Setting this option to
578 disables this enforcement.
579 There may be non-trivial and non-obvious implications to an out of
581 Consider carefully before disabling the order enforcement.
582 .It Ar set fingerprints
583 Load fingerprints of known operating systems from the given filename.
584 By default fingerprints of known operating systems are automatically
589 but can be overridden via this option.
590 Setting this option may leave a small period of time where the fingerprints
591 referenced by the currently active ruleset are inconsistent until the new
592 ruleset finishes loading.
596 .Dl set fingerprints \&"/etc/pf.os.devel\&"
597 .It Ar set skip on Aq Ar ifspec
598 List interfaces for which packets should not be filtered.
599 Packets passing in or out on such interfaces are passed as if pf was
600 disabled, i.e. pf does not process them in any way.
601 This can be useful on loopback and other virtual interfaces, when
602 packet filtering is not desired and can have unexpected effects.
609 to one of the following:
611 .Bl -tag -width xxxxxxxxxxxx -compact
613 Don't generate debug messages.
615 Generate debug messages only for serious errors.
617 Generate debug messages for various errors.
619 Generate debug messages for common conditions.
622 .Sh TRAFFIC NORMALIZATION
623 Traffic normalization is used to sanitize packet content in such
624 a way that there are no ambiguities in packet interpretation on
626 The normalizer does IP fragment reassembly to prevent attacks
627 that confuse intrusion detection systems by sending overlapping
629 Packet normalization is invoked with the
634 has the following options:
639 bit from a matching IP packet.
640 Some operating systems are known to generate fragmented packets with the
643 This is particularly true with NFS.
645 will drop such fragmented
651 Unfortunately some operating systems also generate their
653 packets with a zero IP identification field.
656 bit on packets with a zero IP ID may cause deleterious results if an
657 upstream router later fragments the packet.
660 modifier (see below) is recommended in combination with the
662 modifier to ensure unique IP identifiers.
663 .It Ar min-ttl Aq Ar number
664 Enforces a minimum TTL for matching IP packets.
665 .It Ar max-mss Aq Ar number
666 Enforces a maximum MSS for matching TCP packets.
667 .It Xo Ar set-tos Aq Ar string
668 .No \*(Ba Aq Ar number
672 for matching IP packets.
682 or one of the DiffServ Code Points:
684 .Ar af11 No ... Ar af43 ,
685 .Ar cs0 No ... Ar cs7 ;
686 or as either hex or decimal.
688 Replaces the IP identification field with random values to compensate
689 for predictable values generated by many hosts.
690 This option only applies to packets that are not fragmented
691 after the optional fragment reassembly.
692 .It Ar fragment reassemble
695 rules, fragments can be reassembled by normalization.
696 In this case, fragments are buffered until they form a complete
697 packet, and only the completed packet is passed on to the filter.
698 The advantage is that filter rules have to deal only with complete
699 packets, and can ignore fragments.
700 The drawback of caching fragments is the additional memory cost.
701 .It Ar reassemble tcp
702 Statefully normalizes TCP connections.
703 .Ar scrub reassemble tcp
704 rules may not have the direction (in/out) specified.
706 performs the following normalizations:
708 .Bl -tag -width timeout -compact
710 Neither side of the connection is allowed to reduce their IP TTL.
711 An attacker may send a packet such that it reaches the firewall, affects
712 the firewall state, and expires before reaching the destination host.
714 will raise the TTL of all packets back up to the highest value seen on
716 .It timestamp modulation
717 Modern TCP stacks will send a timestamp on every TCP packet and echo
718 the other endpoint's timestamp back to them.
719 Many operating systems will merely start the timestamp at zero when
720 first booted, and increment it several times a second.
721 The uptime of the host can be deduced by reading the timestamp and multiplying
723 Also observing several different timestamps can be used to count hosts
725 And spoofing TCP packets into a connection requires knowing or guessing
727 Timestamps merely need to be monotonically increasing and not derived off a
732 to modulate the TCP timestamps with a random number.
733 .It extended PAWS checks
734 There is a problem with TCP on long fat pipes, in that a packet might get
735 delayed for longer than it takes the connection to wrap its 32-bit sequence
737 In such an occurrence, the old packet would be indistinguishable from a
738 new packet and would be accepted as such.
739 The solution to this is called PAWS: Protection Against Wrapped Sequence
741 It protects against it by making sure the timestamp on each packet does
744 also makes sure the timestamp on the packet does not go forward more
748 artificially extends the security of TCP sequence numbers by 10 to 18
749 bits when the host uses appropriately randomized timestamps, since a
750 blind attacker would have to guess the timestamp as well.
755 .Bd -literal -offset indent
756 scrub in on $ext_if all fragment reassemble
761 option prefixed to a scrub rule causes matching packets to remain unscrubbed,
762 much in the same way as
764 works in the packet filter (see below).
765 This mechanism should be used when it is necessary to exclude specific packets
766 from broader scrub rules.
768 The ALTQ system is currently not available in the GENERIC kernel nor as
770 In order to use the herein after called queueing options one has to use a
774 to learn about the related kernel options.
776 Packets can be assigned to queues for the purpose of bandwidth
778 At least two declarations are required to configure queues, and later
779 any packet filtering rule can reference the defined queues by name.
780 During the filtering component of
784 name is where any packets from
786 rules will be queued, while for
788 rules it specifies where any resulting ICMP or TCP RST
789 packets should be queued.
792 defines the algorithm used to decide which packets get delayed, dropped, or
793 sent out immediately.
799 Class Based Queueing.
801 attached to an interface build a tree, thus each
803 can have further child
805 Each queue can have a
811 mainly controls the time packets take to get sent out, while
813 has primarily effects on throughput.
815 achieves both partitioning and sharing of link bandwidth
816 by hierarchically structured classes.
817 Each class has its own
819 and is assigned its share of
821 A child class can borrow bandwidth from its parent class
822 as long as excess bandwidth is available
829 are flat attached to the interface, thus,
831 cannot have further child
837 assigned, ranging from 0 to 15.
844 Hierarchical Fair Service Curve.
846 attached to an interface build a tree, thus each
848 can have further child
850 Each queue can have a
856 mainly controls the time packets take to get sent out, while
858 primarily affects throughput.
860 supports both link-sharing and guaranteed real-time services.
861 It employs a service curve based QoS model,
862 and its unique feature is an ability to decouple
869 The interfaces on which queueing should be activated are declared using
874 has the following keywords:
877 Queueing is enabled on the named interface.
879 Specifies which queueing scheduler to use.
880 Currently supported values
883 for Class Based Queueing,
885 for Priority Queueing and
887 for the Hierarchical Fair Service Curve scheduler.
888 .It Ar bandwidth Aq Ar bw
889 The maximum bitrate for all queues on an
890 interface may be specified using the
893 The value can be specified as an absolute value or as a
894 percentage of the interface bandwidth.
895 When using an absolute value, the suffixes
901 are used to represent bits, kilobits, megabits, and
902 gigabits per second, respectively.
903 The value must not exceed the interface bandwidth.
906 is not specified, the interface bandwidth is used
907 (but take note that some interfaces do not know their bandwidth,
908 or can adapt their bandwidth rates).
909 .It Ar qlimit Aq Ar limit
910 The maximum number of packets held in the queue.
912 .It Ar tbrsize Aq Ar size
913 Adjusts the size, in bytes, of the token bucket regulator.
914 If not specified, heuristics based on the
915 interface bandwidth are used to determine the size.
916 .It Ar queue Aq Ar list
917 Defines a list of subqueues to create on an interface.
920 In the following example, the interface dc0
921 should queue up to 5Mbps in four second-level queues using
922 Class Based Queueing.
923 Those four queues will be shown in a later example.
924 .Bd -literal -offset indent
925 altq on dc0 cbq bandwidth 5Mb queue { std, http, mail, ssh }
928 Once interfaces are activated for queueing using the
930 directive, a sequence of
932 directives may be defined.
933 The name associated with a
935 must match a queue defined in the
937 directive (e.g. mail), or, except for the
943 The following keywords can be used:
945 .It Ar on Aq Ar interface
946 Specifies the interface the queue operates on.
947 If not given, it operates on all matching interfaces.
948 .It Ar bandwidth Aq Ar bw
949 Specifies the maximum bitrate to be processed by the queue.
950 This value must not exceed the value of the parent
952 and can be specified as an absolute value or a percentage of the parent
954 If not specified, defaults to 100% of the parent queue's bandwidth.
957 scheduler does not support bandwidth specification.
958 .It Ar priority Aq Ar level
959 Between queues a priority level can be set.
964 the range is 0 to 7 and for
966 the range is 0 to 15.
967 The default for all is 1.
969 queues with a higher priority are always served first.
973 queues with a higher priority are preferred in the case of overload.
974 .It Ar qlimit Aq Ar limit
975 The maximum number of packets held in the queue.
981 can get additional parameters with
983 .Pf ( Aq Ar parameters ) .
985 Parameters are as follows:
988 Packets not matched by another queue are assigned to this one.
989 Exactly one default queue is required.
991 Enable RED (Random Early Detection) on this queue.
992 RED drops packets with a probability proportional to the average
995 Enables RIO on this queue.
996 RIO is RED with IN/OUT, thus running
997 RED two times more than RIO would achieve the same effect.
998 RIO is currently not supported in the GENERIC kernel.
1000 Enables ECN (Explicit Congestion Notification) on this queue.
1007 supports an additional option:
1010 The queue can borrow bandwidth from the parent.
1016 supports some additional options:
1018 .It Ar realtime Aq Ar sc
1019 The minimum required bandwidth for the queue.
1020 .It Ar upperlimit Aq Ar sc
1021 The maximum allowed bandwidth for the queue.
1022 .It Ar linkshare Aq Ar sc
1023 The bandwidth share of a backlogged queue.
1030 The format for service curve specifications is
1031 .Ar ( m1 , d , m2 ) .
1033 controls the bandwidth assigned to the queue.
1037 are optional and can be used to control the initial bandwidth assignment.
1040 milliseconds the queue gets the bandwidth given as
1042 afterwards the value given in
1049 child queues can be specified as in an
1051 declaration, thus building a tree of queues using a part of
1052 their parent's bandwidth.
1054 Packets can be assigned to queues based on filter rules by using the
1059 is specified; when a second one is specified it will instead be used for
1060 packets which have a
1064 and for TCP ACKs with no data payload.
1066 To continue the previous example, the examples below would specify the
1068 queues, plus a few child queues.
1071 sessions get priority over bulk transfers like
1075 The queues may then be referenced by filtering rules (see
1076 .Sx PACKET FILTERING
1079 queue std bandwidth 10% cbq(default)
1080 queue http bandwidth 60% priority 2 cbq(borrow red) \e
1081 { employees, developers }
1082 queue developers bandwidth 75% cbq(borrow)
1083 queue employees bandwidth 15%
1084 queue mail bandwidth 10% priority 0 cbq(borrow ecn)
1085 queue ssh bandwidth 20% cbq(borrow) { ssh_interactive, ssh_bulk }
1086 queue ssh_interactive bandwidth 50% priority 7 cbq(borrow)
1087 queue ssh_bulk bandwidth 50% priority 0 cbq(borrow)
1089 block return out on dc0 inet all queue std
1090 pass out on dc0 inet proto tcp from $developerhosts to any port 80 \e
1092 pass out on dc0 inet proto tcp from $employeehosts to any port 80 \e
1094 pass out on dc0 inet proto tcp from any to any port 22 \e
1095 queue(ssh_bulk, ssh_interactive)
1096 pass out on dc0 inet proto tcp from any to any port 25 \e
1100 Translation rules modify either the source or destination address of the
1101 packets associated with a stateful connection.
1102 A stateful connection is automatically created to track packets matching
1103 such a rule as long as they are not blocked by the filtering section of
1105 The translation engine modifies the specified address and/or port in the
1106 packet, recalculates IP, TCP and UDP checksums as necessary, and passes it to
1107 the packet filter for evaluation.
1109 Since translation occurs before filtering the filter
1110 engine will see packets as they look after any
1111 addresses and ports have been translated.
1112 Filter rules will therefore have to filter based on the translated
1113 address and port number.
1114 Packets that match a translation rule are only automatically passed if
1117 modifier is given, otherwise they are
1124 The state entry created permits
1126 to keep track of the original address for traffic associated with that state
1127 and correctly direct return traffic for that connection.
1129 Various types of translation are possible with pf:
1130 .Bl -tag -width xxxx
1134 rule specifies a bidirectional mapping between an external IP netblock
1135 and an internal IP netblock.
1139 rule specifies that IP addresses are to be changed as the packet
1140 traverses the given interface.
1141 This technique allows one or more IP addresses
1142 on the translating host to support network traffic for a larger range of
1143 machines on an "inside" network.
1144 Although in theory any IP address can be used on the inside, it is strongly
1145 recommended that one of the address ranges defined by RFC 1918 be used.
1146 These netblocks are:
1148 10.0.0.0 - 10.255.255.255 (all of net 10, i.e., 10/8)
1149 172.16.0.0 - 172.31.255.255 (i.e., 172.16/12)
1150 192.168.0.0 - 192.168.255.255 (i.e., 192.168/16)
1153 The packet is redirected to another destination and possibly a
1156 rules can optionally specify port ranges instead of single ports.
1157 rdr ... port 2000:2999 -\*(Gt ... port 4000
1158 redirects ports 2000 to 2999 (inclusive) to port 4000.
1159 rdr ... port 2000:2999 -\*(Gt ... port 4000:*
1160 redirects port 2000 to 4000, 2001 to 4001, ..., 2999 to 4999.
1163 In addition to modifying the address, some translation rules may modify
1164 source or destination ports for
1168 connections; implicitly in the case of
1170 rules and explicitly in the case of
1173 Port numbers are never translated with a
1177 Evaluation order of the translation rules is dependent on the type
1178 of the translation rules and of the direction of a packet.
1180 rules are always evaluated first.
1183 rules are evaluated on an inbound packet or the
1185 rules on an outbound packet.
1186 Rules of the same type are evaluated in the same order in which they
1187 appear in the ruleset.
1188 The first matching rule decides what action is taken.
1192 option prefixed to a translation rule causes packets to remain untranslated,
1193 much in the same way as
1195 works in the packet filter (see below).
1196 If no rule matches the packet it is passed to the filter engine unmodified.
1198 Translation rules apply only to packets that pass through
1199 the specified interface, and if no interface is specified,
1200 translation is applied to packets on all interfaces.
1201 For instance, redirecting port 80 on an external interface to an internal
1202 web server will only work for connections originating from the outside.
1203 Connections to the address of the external interface from local hosts will
1204 not be redirected, since such packets do not actually pass through the
1206 Redirections cannot reflect packets back through the interface they arrive
1207 on, they can only be redirected to hosts connected to different interfaces
1208 or to the firewall itself.
1210 Note that redirecting external incoming connections to the loopback
1212 .Bd -literal -offset indent
1213 rdr on ne3 inet proto tcp to port smtp -\*(Gt 127.0.0.1 port spamd
1216 will effectively allow an external host to connect to daemons
1217 bound solely to the loopback address, circumventing the traditional
1218 blocking of such connections on a real interface.
1219 Unless this effect is desired, any of the local non-loopback addresses
1220 should be used as redirection target instead, which allows external
1221 connections only to daemons bound to this address or not bound to
1225 .Sx TRANSLATION EXAMPLES
1227 .Sh PACKET FILTERING
1233 packets based on attributes of their layer 3 (see
1243 In addition, packets may also be
1244 assigned to queues for the purpose of bandwidth control.
1246 For each packet processed by the packet filter, the filter rules are
1247 evaluated in sequential order, from first to last.
1248 The last matching rule decides what action is taken.
1249 If no rule matches the packet, the default action is to pass
1252 The following actions can be used in the filter:
1253 .Bl -tag -width xxxx
1255 The packet is blocked.
1256 There are a number of ways in which a
1258 rule can behave when blocking a packet.
1259 The default behaviour is to
1261 packets silently, however this can be overridden or made
1262 explicit either globally, by setting the
1264 option, or on a per-rule basis with one of the following options:
1266 .Bl -tag -width xxxx -compact
1268 The packet is silently dropped.
1270 This applies only to
1272 packets, and issues a TCP RST which closes the
1276 This causes ICMP messages to be returned for packets which match the rule.
1277 By default this is an ICMP UNREACHABLE message, however this
1278 can be overridden by specifying a message as a code or number.
1280 This causes a TCP RST to be returned for
1282 packets and an ICMP UNREACHABLE for UDP and other packets.
1285 Options returning ICMP packets currently have no effect if
1289 as the code to support this feature has not yet been implemented.
1291 The simplest mechanism to block everything by default and only pass
1292 packets that match explicit rules is specify a first filter rule of:
1293 .Bd -literal -offset indent
1297 The packet is passed;
1298 state is created unless the
1300 option is specified.
1305 filters packets statefully; the first time a packet matches a
1307 rule, a state entry is created; for subsequent packets the filter checks
1308 whether the packet matches any state.
1309 If it does, the packet is passed without evaluation of any rules.
1310 After the connection is closed or times out, the state entry is automatically
1313 This has several advantages.
1314 For TCP connections, comparing a packet to a state involves checking
1315 its sequence numbers, as well as TCP timestamps if a
1316 .Ar scrub reassemble tcp
1317 rule applies to the connection.
1318 If these values are outside the narrow windows of expected
1319 values, the packet is dropped.
1320 This prevents spoofing attacks, such as when an attacker sends packets with
1321 a fake source address/port but does not know the connection's sequence
1325 knows how to match ICMP replies to states.
1327 .Bd -literal -offset indent
1328 pass out inet proto icmp all icmp-type echoreq
1331 allows echo requests (such as those created by
1333 out statefully, and matches incoming echo replies correctly to states.
1335 Also, looking up states is usually faster than evaluating rules.
1336 If there are 50 rules, all of them are evaluated sequentially in O(n).
1337 Even with 50000 states, only 16 comparisons are needed to match a
1338 state, since states are stored in a binary search tree that allows
1339 searches in O(log2 n).
1341 Furthermore, correct handling of ICMP error messages is critical to
1342 many protocols, particularly TCP.
1344 matches ICMP error messages to the correct connection, checks them against
1345 connection parameters, and passes them if appropriate.
1346 For example if an ICMP source quench message referring to a stateful TCP
1347 connection arrives, it will be matched to the state and get passed.
1349 Finally, state tracking is required for
1350 .Ar nat , binat No and Ar rdr
1351 rules, in order to track address and port translations and reverse the
1352 translation on returning packets.
1355 will also create state for other protocols which are effectively stateless by
1357 UDP packets are matched to states using only host addresses and ports,
1358 and other protocols are matched to states using only the host addresses.
1360 If stateless filtering of individual packets is desired,
1363 keyword can be used to specify that state will not be created
1364 if this is the last matching rule.
1365 A number of parameters can also be set to affect how
1367 handles state tracking.
1369 .Sx STATEFUL TRACKING OPTIONS
1370 below for further details.
1372 The rule parameters specify the packets to which a rule applies.
1373 A packet always comes in on, or goes out through, one interface.
1374 Most parameters are optional.
1375 If a parameter is specified, the rule only applies to packets with
1376 matching attributes.
1377 Certain parameters can be expressed as lists, in which case
1379 generates all needed rule combinations.
1380 .Bl -tag -width xxxx
1381 .It Ar in No or Ar out
1382 This rule applies to incoming or outgoing packets.
1387 are specified, the rule will match packets in both directions.
1389 In addition to the action specified, a log message is generated.
1390 Only the packet that establishes the state is logged,
1393 option is specified.
1394 The logged packets are sent to a
1396 interface, by default
1398 This interface is monitored by the
1400 logging daemon, which dumps the logged packets to the file
1406 Used to force logging of all packets for a connection.
1407 This is not necessary when
1409 is explicitly specified.
1412 packets are logged to
1417 user ID of the user that owns the socket and the PID of the process that
1418 has the socket open where the packet is sourced from or destined to
1419 (depending on which socket is local).
1420 This is in addition to the normal information logged.
1422 Only the first packet
1425 will have the user credentials logged when using stateful matching.
1426 .It Ar log (to Aq Ar interface )
1427 Send logs to the specified
1429 interface instead of
1432 If a packet matches a rule which has the
1434 option set, this rule
1435 is considered the last matching rule, and evaluation of subsequent rules
1437 .It Ar on Aq Ar interface
1438 This rule applies only to packets coming in on, or going out through, this
1439 particular interface or interface group.
1440 For more information on interface groups,
1446 This rule applies only to packets of this address family.
1447 Supported values are
1451 .It Ar proto Aq Ar protocol
1452 This rule applies only to packets of this protocol.
1453 Common protocols are
1459 For a list of all the protocol name to number mappings used by
1462 .Pa /etc/protocols .
1464 .Ar from Aq Ar source
1465 .Ar port Aq Ar source
1470 This rule applies only to packets with the specified source and destination
1471 addresses and ports.
1473 Addresses can be specified in CIDR notation (matching netblocks), as
1474 symbolic host names, interface names or interface group names, or as any
1475 of the following keywords:
1477 .Bl -tag -width xxxxxxxxxxxxxx -compact
1481 Any address which is not currently routable.
1483 Any source address that fails a unicast reverse path forwarding (URPF)
1484 check, i.e. packets coming in on an interface other than that which holds
1485 the route back to the packet's source address.
1487 Any address that matches the given table.
1490 Ranges of addresses are specified by using the
1494 .Dq 10.1.1.10 - 10.1.1.12
1495 means all addresses from 10.1.1.10 to 10.1.1.12,
1496 hence addresses 10.1.1.10, 10.1.1.11, and 10.1.1.12.
1498 Interface names and interface group names can have modifiers appended:
1500 .Bl -tag -width xxxxxxxxxxxx -compact
1502 Translates to the network(s) attached to the interface.
1504 Translates to the interface's broadcast address(es).
1506 Translates to the point-to-point interface's peer address(es).
1508 Do not include interface aliases.
1511 Host names may also have the
1513 option appended to restrict the name resolution to the first of each
1514 v4 and non-link-local v6 address found.
1516 Host name resolution and interface to address translation are done at
1518 When the address of an interface (or host name) changes (under DHCP or PPP,
1519 for instance), the ruleset must be reloaded for the change to be reflected
1521 Surrounding the interface name (and optional modifiers) in parentheses
1522 changes this behaviour.
1523 When the interface name is surrounded by parentheses, the rule is
1524 automatically updated whenever the interface changes its address.
1525 The ruleset does not need to be reloaded.
1526 This is especially useful with
1529 Ports can be specified either by number or by name.
1530 For example, port 80 can be specified as
1532 For a list of all port name to number mappings used by
1537 Ports and ranges of ports are specified by using these operators:
1538 .Bd -literal -offset indent
1542 \*(Le (less than or equal)
1543 \*(Gt (greater than)
1544 \*(Ge (greater than or equal)
1545 : (range including boundaries)
1546 \*(Gt\*(Lt (range excluding boundaries)
1547 \*(Lt\*(Gt (except range)
1554 are binary operators (they take two arguments).
1557 .It Ar port 2000:2004
1559 .Sq all ports \*(Ge 2000 and \*(Le 2004 ,
1560 hence ports 2000, 2001, 2002, 2003 and 2004.
1561 .It Ar port 2000 \*(Gt\*(Lt 2004
1563 .Sq all ports \*(Gt 2000 and \*(Lt 2004 ,
1564 hence ports 2001, 2002 and 2003.
1565 .It Ar port 2000 \*(Lt\*(Gt 2004
1567 .Sq all ports \*(Lt 2000 or \*(Gt 2004 ,
1568 hence ports 1-1999 and 2005-65535.
1571 The operating system of the source host can be specified in the case of TCP
1576 .Sx OPERATING SYSTEM FINGERPRINTING
1577 section for more information.
1579 The host, port and OS specifications are optional, as in the following examples:
1580 .Bd -literal -offset indent
1582 pass in from any to any
1583 pass in proto tcp from any port \*(Le 1024 to any
1584 pass in proto tcp from any to any port 25
1585 pass in proto tcp from 10.0.0.0/8 port \*(Gt 1024 \e
1586 to ! 10.1.2.3 port != ssh
1587 pass in proto tcp from any os "OpenBSD"
1590 This is equivalent to "from any to any".
1591 .It Ar group Aq Ar group
1594 this rule only applies to packets of sockets owned by the specified group.
1595 .It Ar user Aq Ar user
1596 This rule only applies to packets of sockets owned by the specified user.
1597 For outgoing connections initiated from the firewall, this is the user
1598 that opened the connection.
1599 For incoming connections to the firewall itself, this is the user that
1600 listens on the destination port.
1601 For forwarded connections, where the firewall is not a connection endpoint,
1602 the user and group are
1605 All packets, both outgoing and incoming, of one connection are associated
1606 with the same user and group.
1607 Only TCP and UDP packets can be associated with users; for other protocols
1608 these parameters are ignored.
1610 User and group refer to the effective (as opposed to the real) IDs, in
1611 case the socket is created by a setuid/setgid process.
1612 User and group IDs are stored when a socket is created;
1613 when a process creates a listening socket as root (for instance, by
1614 binding to a privileged port) and subsequently changes to another
1615 user ID (to drop privileges), the credentials will remain root.
1617 User and group IDs can be specified as either numbers or names.
1618 The syntax is similar to the one for ports.
1621 matches packets of forwarded connections.
1623 can only be used with the operators
1627 Other constructs like
1628 .Cm user \*(Ge unknown
1630 Forwarded packets with unknown user and group ID match only rules
1631 that explicitly compare against
1639 does not match forwarded packets.
1640 The following example allows only selected users to open outgoing
1642 .Bd -literal -offset indent
1643 block out proto { tcp, udp } all
1644 pass out proto { tcp, udp } all user { \*(Lt 1000, dhartmei }
1646 .It Xo Ar flags Aq Ar a
1648 .No \*(Ba / Ns Aq Ar b
1651 This rule only applies to TCP packets that have the flags
1655 Flags not specified in
1658 For stateful connections, the default is
1660 To indicate that flags should not be checked at all, specify
1662 The flags are: (F)IN, (S)YN, (R)ST, (P)USH, (A)CK, (U)RG, (E)CE, and C(W)R.
1666 The other flags are ignored.
1668 This is the default setting for stateful connections.
1669 Out of SYN and ACK, exactly SYN may be set.
1670 SYN, SYN+PSH and SYN+RST match, but SYN+ACK, ACK and ACK+RST do not.
1671 This is more restrictive than the previous example.
1673 If the first set is not specified, it defaults to none.
1674 All of SYN, FIN, RST and ACK must be unset.
1679 is applied by default (unless
1681 is specified), only the initial SYN packet of a TCP handshake will create
1682 a state for a TCP connection.
1683 It is possible to be less restrictive, and allow state creation from
1686 packets, by specifying
1690 to synchronize to existing connections, for instance
1691 if one flushes the state table.
1692 However, states created from such intermediate packets may be missing
1693 connection details such as the TCP window scaling factor.
1694 States which modify the packet flow, such as those affected by
1695 .Ar nat , binat No or Ar rdr
1697 .Ar modulate No or Ar synproxy state
1698 options, or scrubbed with
1700 will also not be recoverable from intermediate packets.
1701 Such connections will stall and time out.
1702 .It Xo Ar icmp-type Aq Ar type
1705 .It Xo Ar icmp6-type Aq Ar type
1708 This rule only applies to ICMP or ICMPv6 packets with the specified type
1710 Text names for ICMP types and codes are listed in
1714 This parameter is only valid for rules that cover protocols ICMP or
1716 The protocol and the ICMP type indicator
1723 .It Xo Ar tos Aq Ar string
1724 .No \*(Ba Aq Ar number
1726 This rule applies to packets with the specified
1738 or one of the DiffServ Code Points:
1740 .Ar af11 No ... Ar af43 ,
1741 .Ar cs0 No ... Ar cs7 ;
1742 or as either hex or decimal.
1744 For example, the following rules are identical:
1745 .Bd -literal -offset indent
1746 pass all tos lowdelay
1751 By default, IPv4 packets with IP options or IPv6 packets with routing
1752 extension headers are blocked.
1757 rule, packets that pass the filter based on that rule (last matching)
1758 do so even if they contain IP options or routing extension headers.
1759 For packets that match state, the rule that initially created the
1763 rule that is used when a packet does not match any rules does not
1765 .It Ar label Aq Ar string
1766 Adds a label (name) to the rule, which can be used to identify the rule.
1769 shows per-rule statistics for rules that have labels.
1771 The following macros can be used in labels:
1773 .Bl -tag -width $srcaddr -compact -offset indent
1777 The source IP address.
1779 The destination IP address.
1781 The source port specification.
1783 The destination port specification.
1791 .Bd -literal -offset indent
1792 ips = \&"{ 1.2.3.4, 1.2.3.5 }\&"
1793 pass in proto tcp from any to $ips \e
1794 port \*(Gt 1023 label \&"$dstaddr:$dstport\&"
1798 .Bd -literal -offset indent
1799 pass in inet proto tcp from any to 1.2.3.4 \e
1800 port \*(Gt 1023 label \&"1.2.3.4:\*(Gt1023\&"
1801 pass in inet proto tcp from any to 1.2.3.5 \e
1802 port \*(Gt 1023 label \&"1.2.3.5:\*(Gt1023\&"
1805 The macro expansion for the
1807 directive occurs only at configuration file parse time, not during runtime.
1808 .It Xo Ar queue Aq Ar queue
1809 .No \*(Ba ( Aq Ar queue ,
1812 Packets matching this rule will be assigned to the specified queue.
1813 If two queues are given, packets which have a
1817 and TCP ACKs with no data payload will be assigned to the second one.
1823 .Bd -literal -offset indent
1824 pass in proto tcp to port 25 queue mail
1825 pass in proto tcp to port 22 queue(ssh_bulk, ssh_prio)
1828 .It Cm set prio Ar priority | Pq Ar priority , priority
1829 Packets matching this rule will be assigned a specific queueing priority.
1830 Priorities are assigned as integers 0 through 7.
1831 If the packet is transmitted on a
1833 interface, the queueing priority will be written as the priority
1834 code point in the 802.1Q VLAN header.
1835 If two priorities are given, packets which have a TOS of
1837 and TCP ACKs with no data payload will be assigned to the second one.
1840 .Bd -literal -offset indent
1841 pass in proto tcp to port 25 set prio 2
1842 pass in proto tcp to port 22 set prio (2, 5)
1845 .It Ar tag Aq Ar string
1846 Packets matching this rule will be tagged with the
1848 The tag acts as an internal marker that can be used to
1849 identify these packets later on.
1850 This can be used, for example, to provide trust between
1851 interfaces and to determine if packets have been
1852 processed by translation rules.
1855 meaning that the packet will be tagged even if the rule
1856 is not the last matching rule.
1857 Further matching rules can replace the tag with a
1858 new one but will not remove a previously applied tag.
1859 A packet is only ever assigned one tag at a time.
1860 Packet tagging can be done during
1865 rules in addition to filter rules.
1866 Tags take the same macros as labels (see above).
1867 .It Ar tagged Aq Ar string
1868 Used with filter, translation or scrub rules
1869 to specify that packets must already
1870 be tagged with the given tag in order to match the rule.
1871 Inverse tag matching can also be done
1877 .It Ar rtable Aq Ar number
1878 Used to select an alternate routing table for the routing lookup.
1879 Only effective before the route lookup happened, i.e. when filtering inbound.
1880 .It Xo Ar divert-to Aq Ar host
1883 Used to redirect packets to a local socket bound to
1887 The packets will not be modified, so
1889 on the socket will return the original destination address of the packet.
1891 Used to receive replies for sockets that are bound to addresses
1892 which are not local to the machine.
1895 for information on how to bind these sockets.
1896 .It Ar probability Aq Ar number
1897 A probability attribute can be attached to a rule, with a value set between
1898 0 and 1, bounds not included.
1899 In that case, the rule will be honoured using the given probability value
1901 For example, the following rule will drop 20% of incoming ICMP packets:
1902 .Bd -literal -offset indent
1903 block in proto icmp probability 20%
1905 .It Ar prio Aq Ar number
1906 Only match packets which have the given queueing priority assigned.
1910 If a packet matches a rule with a route option set, the packet filter will
1911 route the packet according to the type of route option.
1912 When such a rule creates state, the route option is also applied to all
1913 packets matching the same connection.
1914 .Bl -tag -width xxxx
1918 option routes the packet to the specified interface with an optional address
1922 rule creates state, only packets that pass in the same direction as the
1923 filter rule specifies will be routed in this way.
1924 Packets passing in the opposite direction (replies) are not affected
1925 and are routed normally.
1929 option is similar to
1931 but routes packets that pass in the opposite direction (replies) to the
1932 specified interface.
1933 Opposite direction is only defined in the context of a state entry, and
1935 is useful only in rules that create state.
1936 It can be used on systems with multiple external connections to
1937 route all outgoing packets of a connection through the interface
1938 the incoming connection arrived through (symmetric routing enforcement).
1942 option creates a duplicate of the packet and routes it like
1944 The original packet gets routed as it normally would.
1951 rules, (as well as for the
1956 rule options) for which there is a single redirection address which has a
1957 subnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP
1958 address), a variety of different methods for assigning this address can be
1960 .Bl -tag -width xxxx
1964 option applies the network portion of the redirection address to the address
1965 to be modified (source with
1972 option selects an address at random within the defined block of addresses.
1976 option uses a hash of the source address to determine the redirection address,
1977 ensuring that the redirection address is always the same for a given source.
1978 An optional key can be specified after this keyword either in hex or as a
1981 randomly generates a key for source-hash every time the
1982 ruleset is reloaded.
1986 option loops through the redirection address(es).
1988 When more than one redirection address is specified,
1990 is the only permitted pool type.
1998 from modifying the source port on TCP and UDP packets.
2003 option can be specified to help ensure that multiple connections from the
2004 same source are mapped to the same redirection address.
2005 This option can be used with the
2010 Note that by default these associations are destroyed as soon as there are
2011 no longer states which refer to them; in order to make the mappings last
2012 beyond the lifetime of the states, increase the global options with
2013 .Ar set timeout src.track .
2015 .Sx STATEFUL TRACKING OPTIONS
2016 for more ways to control the source tracking.
2017 .Sh STATE MODULATION
2018 Much of the security derived from TCP is attributable to how well the
2019 initial sequence numbers (ISNs) are chosen.
2020 Some popular stack implementations choose
2022 poor ISNs and thus are normally susceptible to ISN prediction exploits.
2025 rule to a TCP connection,
2027 will create a high quality random sequence number for each connection
2032 directive implicitly keeps state on the rule and is
2033 only applicable to TCP connections.
2036 .Bd -literal -offset indent
2038 pass out proto tcp from any to any modulate state
2039 pass in proto tcp from any to any port 25 flags S/SFRA modulate state
2042 Note that modulated connections will not recover when the state table
2043 is lost (firewall reboot, flushing the state table, etc...).
2045 will not be able to infer a connection again after the state table flushes
2046 the connection's modulator.
2047 When the state is lost, the connection may be left dangling until the
2048 respective endpoints time out the connection.
2049 It is possible on a fast local network for the endpoints to start an ACK
2050 storm while trying to resynchronize after the loss of the modulator.
2053 settings (or a more strict equivalent) should be used on
2055 rules to prevent ACK storms.
2057 Note that alternative methods are available
2058 to prevent loss of the state table
2059 and allow for firewall failover.
2064 for further information.
2068 passes packets that are part of a
2070 handshake between the endpoints.
2073 option can be used to cause
2075 itself to complete the handshake with the active endpoint, perform a handshake
2076 with the passive endpoint, and then forward packets between the endpoints.
2078 No packets are sent to the passive endpoint before the active endpoint has
2079 completed the handshake, hence so-called SYN floods with spoofed source
2080 addresses will not reach the passive endpoint, as the sender can't complete the
2083 The proxy is transparent to both endpoints, they each see a single
2084 connection from/to the other endpoint.
2086 chooses random initial sequence numbers for both handshakes.
2087 Once the handshakes are completed, the sequence number modulators
2088 (see previous section) are used to translate further packets of the
2092 .Ar modulate state .
2102 .Bd -literal -offset indent
2103 pass in proto tcp from any to any port www synproxy state
2105 .Sh STATEFUL TRACKING OPTIONS
2106 A number of options related to stateful tracking can be applied on a
2112 support these options, and
2114 must be specified explicitly to apply options to a rule.
2116 .Bl -tag -width xxxx -compact
2117 .It Ar max Aq Ar number
2118 Limits the number of concurrent states the rule may create.
2119 When this limit is reached, further packets that would create
2120 state will not match this rule until existing states time out.
2122 Prevent state changes for states created by this rule from appearing on the
2125 .It Xo Aq Ar timeout
2128 Changes the timeout values used for states created by this rule.
2129 For a list of all valid timeout names, see
2133 Uses a sloppy TCP connection tracker that does not check sequence
2134 numbers at all, which makes insertion and ICMP teardown attacks way
2136 This is intended to be used in situations where one does not see all
2137 packets of a connection, e.g. in asymmetric routing situations.
2138 Cannot be used with modulate or synproxy state.
2141 Multiple options can be specified, separated by commas:
2142 .Bd -literal -offset indent
2143 pass in proto tcp from any to any \e
2144 port www keep state \e
2145 (max 100, source-track rule, max-src-nodes 75, \e
2146 max-src-states 3, tcp.established 60, tcp.closing 5)
2151 keyword is specified, the number of states per source IP is tracked.
2153 .Bl -tag -width xxxx -compact
2154 .It Ar source-track rule
2155 The maximum number of states created by this rule is limited by the rule's
2160 Only state entries created by this particular rule count toward the rule's
2162 .It Ar source-track global
2163 The number of states created by all rules that use this option is limited.
2164 Each rule can specify different
2168 options, however state entries created by any participating rule count towards
2169 each individual rule's limits.
2172 The following limits can be set:
2174 .Bl -tag -width xxxx -compact
2175 .It Ar max-src-nodes Aq Ar number
2176 Limits the maximum number of source addresses which can simultaneously
2177 have state table entries.
2178 .It Ar max-src-states Aq Ar number
2179 Limits the maximum number of simultaneous state entries that a single
2180 source address can create with this rule.
2183 For stateful TCP connections, limits on established connections (connections
2184 which have completed the TCP 3-way handshake) can also be enforced
2187 .Bl -tag -width xxxx -compact
2188 .It Ar max-src-conn Aq Ar number
2189 Limits the maximum number of simultaneous TCP connections which have
2190 completed the 3-way handshake that a single host can make.
2191 .It Xo Ar max-src-conn-rate Aq Ar number
2194 Limit the rate of new connections over a time interval.
2195 The connection rate is an approximation calculated as a moving average.
2198 Because the 3-way handshake ensures that the source address is not being
2199 spoofed, more aggressive action can be taken based on these limits.
2201 .Ar overload Aq Ar table
2202 state option, source IP addresses which hit either of the limits on
2203 established connections will be added to the named table.
2204 This table can be used in the ruleset to block further activity from
2205 the offending host, redirect it to a tarpit process, or restrict its
2210 keyword kills all states created by the matching rule which originate
2211 from the host which exceeds these limits.
2214 modifier to the flush command kills all states originating from the
2215 offending host, regardless of which rule created the state.
2217 For example, the following rules will protect the webserver against
2218 hosts making more than 100 connections in 10 seconds.
2219 Any host which connects faster than this rate will have its address added
2222 table and have all states originating from it flushed.
2223 Any new packets arriving from this host will be dropped unconditionally
2225 .Bd -literal -offset indent
2226 block quick from \*(Ltbad_hosts\*(Gt
2227 pass in on $ext_if proto tcp to $webserver port www keep state \e
2228 (max-src-conn-rate 100/10, overload \*(Ltbad_hosts\*(Gt flush global)
2230 .Sh OPERATING SYSTEM FINGERPRINTING
2231 Passive OS Fingerprinting is a mechanism to inspect nuances of a TCP
2232 connection's initial SYN packet and guess at the host's operating system.
2233 Unfortunately these nuances are easily spoofed by an attacker so the
2234 fingerprint is not useful in making security decisions.
2235 But the fingerprint is typically accurate enough to make policy decisions
2238 The fingerprints may be specified by operating system class, by
2239 version, or by subtype/patchlevel.
2240 The class of an operating system is typically the vendor or genre
2246 The version of the oldest available
2248 release on the main FTP site
2249 would be 2.6 and the fingerprint would be written
2251 .Dl \&"OpenBSD 2.6\&"
2253 The subtype of an operating system is typically used to describe the
2254 patchlevel if that patch led to changes in the TCP stack behavior.
2257 the only subtype is for a fingerprint that was
2260 scrub option and would be specified as
2262 .Dl \&"OpenBSD 3.3 no-df\&"
2264 Fingerprints for most popular operating systems are provided by
2268 is running, a complete list of known operating system fingerprints may
2269 be listed by running:
2273 Filter rules can enforce policy at any level of operating system specification
2274 assuming a fingerprint is present.
2275 Policy could limit traffic to approved operating systems or even ban traffic
2276 from hosts that aren't at the latest service pack.
2280 class can also be used as the fingerprint which will match packets for
2281 which no operating system fingerprint is known.
2284 .Bd -literal -offset indent
2285 pass out proto tcp from any os OpenBSD
2286 block out proto tcp from any os Doors
2287 block out proto tcp from any os "Doors PT"
2288 block out proto tcp from any os "Doors PT SP3"
2289 block out from any os "unknown"
2290 pass on lo0 proto tcp from any os "OpenBSD 3.3 lo0"
2293 Operating system fingerprinting is limited only to the TCP SYN packet.
2294 This means that it will not work on other protocols and will not match
2295 a currently established connection.
2297 Caveat: operating system fingerprints are occasionally wrong.
2298 There are three problems: an attacker can trivially craft his packets to
2299 appear as any operating system he chooses;
2300 an operating system patch could change the stack behavior and no fingerprints
2301 will match it until the database is updated;
2302 and multiple operating systems may have the same fingerprint.
2303 .Sh BLOCKING SPOOFED TRAFFIC
2304 "Spoofing" is the faking of IP addresses, typically for malicious
2308 directive expands to a set of filter rules which will block all
2309 traffic with a source IP from the network(s) directly connected
2310 to the specified interface(s) from entering the system through
2311 any other interface.
2313 For example, the line
2314 .Bd -literal -offset indent
2319 .Bd -literal -offset indent
2320 block drop in on ! lo0 inet from 127.0.0.1/8 to any
2321 block drop in on ! lo0 inet6 from ::1 to any
2324 For non-loopback interfaces, there are additional rules to block incoming
2325 packets with a source IP address identical to the interface's IP(s).
2326 For example, assuming the interface wi0 had an IP address of 10.0.0.1 and a
2327 netmask of 255.255.255.0,
2329 .Bd -literal -offset indent
2330 antispoof for wi0 inet
2334 .Bd -literal -offset indent
2335 block drop in on ! wi0 inet from 10.0.0.0/24 to any
2336 block drop in inet from 10.0.0.1 to any
2339 Caveat: Rules created by the
2341 directive interfere with packets sent over loopback interfaces
2343 One should pass these explicitly.
2344 .Sh FRAGMENT HANDLING
2345 The size of IP datagrams (packets) can be significantly larger than the
2346 maximum transmission unit (MTU) of the network.
2347 In cases when it is necessary or more efficient to send such large packets,
2348 the large packet will be fragmented into many smaller packets that will each
2350 Unfortunately for a firewalling device, only the first logical fragment will
2351 contain the necessary header information for the subprotocol that allows
2353 to filter on things such as TCP ports or to perform NAT.
2357 rules as described in
2358 .Sx TRAFFIC NORMALIZATION
2359 above, there are three options for handling fragments in the packet filter.
2361 One alternative is to filter individual fragments with filter rules.
2364 rule applies to a fragment, it is passed to the filter.
2365 Filter rules with matching IP header parameters decide whether the
2366 fragment is passed or blocked, in the same way as complete packets
2368 Without reassembly, fragments can only be filtered based on IP header
2369 fields (source/destination address, protocol), since subprotocol header
2370 fields are not available (TCP/UDP port numbers, ICMP code/type).
2373 option can be used to restrict filter rules to apply only to
2374 fragments, but not complete packets.
2375 Filter rules without the
2377 option still apply to fragments, if they only specify IP header fields.
2378 For instance, the rule
2379 .Bd -literal -offset indent
2380 pass in proto tcp from any to any port 80
2383 never applies to a fragment, even if the fragment is part of a TCP
2384 packet with destination port 80, because without reassembly this information
2385 is not available for each fragment.
2386 This also means that fragments cannot create new or match existing
2387 state table entries, which makes stateful filtering and address
2388 translation (NAT, redirection) for fragments impossible.
2390 It's also possible to reassemble only certain fragments by specifying
2391 source or destination addresses or protocols as parameters in
2395 In most cases, the benefits of reassembly outweigh the additional
2396 memory cost, and it's recommended to use
2399 all fragments via the
2400 .Ar fragment reassemble
2403 The memory allocated for fragment caching can be limited using
2405 Once this limit is reached, fragments that would have to be cached
2406 are dropped until other entries time out.
2407 The timeout value can also be adjusted.
2409 When forwarding reassembled IPv6 packets, pf refragments them with
2410 the original maximum fragment size.
2411 This allows the sender to determine the optimal fragment size by
2414 Besides the main ruleset,
2416 can load rulesets into
2421 is a container that can hold rules, address tables, and other anchors.
2425 has a name which specifies the path where
2427 can be used to access the anchor to perform operations on it, such as
2428 attaching child anchors to it or loading rules into it.
2429 Anchors may be nested, with components separated by
2431 characters, similar to how file system hierarchies are laid out.
2432 The main ruleset is actually the default anchor, so filter and
2433 translation rules, for example, may also be contained in any anchor.
2435 An anchor can reference another
2438 using the following kinds
2440 .Bl -tag -width xxxx
2441 .It Ar nat-anchor Aq Ar name
2444 rules in the specified
2446 .It Ar rdr-anchor Aq Ar name
2449 rules in the specified
2451 .It Ar binat-anchor Aq Ar name
2454 rules in the specified
2456 .It Ar anchor Aq Ar name
2457 Evaluates the filter rules in the specified
2459 .It Xo Ar load anchor
2463 Loads the rules from the specified file into the
2468 When evaluation of the main ruleset reaches an
2472 will proceed to evaluate all rules specified in that anchor.
2474 Matching filter and translation rules marked with the
2476 option are final and abort the evaluation of the rules in other
2477 anchors and the main ruleset.
2480 itself is marked with the
2483 ruleset evaluation will terminate when the anchor is exited if the packet is
2484 matched by any rule within the anchor.
2487 rules are evaluated relative to the anchor in which they are contained.
2490 rules specified in the main ruleset will reference anchor
2491 attachment points underneath the main ruleset, and
2493 rules specified in a file loaded from a
2495 rule will be attached under that anchor point.
2497 Rules may be contained in
2499 attachment points which do not contain any rules when the main ruleset
2500 is loaded, and later such anchors can be manipulated through
2502 without reloading the main ruleset or other anchors.
2504 .Bd -literal -offset indent
2506 block on $ext_if all
2508 pass out on $ext_if all
2509 pass in on $ext_if proto tcp from any \e
2510 to $ext_if port smtp
2513 blocks all packets on the external interface by default, then evaluates
2516 named "spam", and finally passes all outgoing connections and
2517 incoming connections to port 25.
2518 .Bd -literal -offset indent
2519 # echo \&"block in quick from 1.2.3.4 to any\&" \&| \e
2523 This loads a single rule into the
2525 which blocks all packets from a specific address.
2527 The anchor can also be populated by adding a
2532 .Bd -literal -offset indent
2534 load anchor spam from "/etc/pf-spam.conf"
2541 it will also load all the rules from the file
2542 .Pa /etc/pf-spam.conf
2547 rules can specify packet filtering parameters using the same syntax as
2549 When parameters are used, the
2551 rule is only evaluated for matching packets.
2552 This allows conditional evaluation of anchors, like:
2553 .Bd -literal -offset indent
2554 block on $ext_if all
2555 anchor spam proto tcp from any to any port smtp
2556 pass out on $ext_if all
2557 pass in on $ext_if proto tcp from any to $ext_if port smtp
2562 spam are only evaluated for
2564 packets with destination port 25.
2566 .Bd -literal -offset indent
2567 # echo \&"block in quick from 1.2.3.4 to any" \&| \e
2571 will only block connections from 1.2.3.4 to port 25.
2573 Anchors may end with the asterisk
2575 character, which signifies that all anchors attached at that point
2576 should be evaluated in the alphabetical ordering of their anchor name.
2578 .Bd -literal -offset indent
2582 will evaluate each rule in each anchor attached to the
2585 Note that it will only evaluate anchors that are directly attached to the
2587 anchor, and will not descend to evaluate anchors recursively.
2589 Since anchors are evaluated relative to the anchor in which they are
2590 contained, there is a mechanism for accessing the parent and ancestor
2591 anchors of a given anchor.
2592 Similar to file system path name resolution, if the sequence
2594 appears as an anchor path component, the parent anchor of the current
2595 anchor in the path evaluation at that point will become the new current
2597 As an example, consider the following:
2598 .Bd -literal -offset indent
2599 # echo ' anchor "spam/allowed" ' | pfctl -f -
2600 # echo -e ' anchor "../banned" \en pass' | \e
2601 pfctl -a spam/allowed -f -
2604 Evaluation of the main ruleset will lead into the
2606 anchor, which will evaluate the rules in the
2608 anchor, if any, before finally evaluating the
2614 can also be loaded inline in the ruleset within a brace ('{' '}') delimited
2616 Brace delimited blocks may contain rules or other brace-delimited blocks.
2617 When anchors are loaded this way the anchor name becomes optional.
2618 .Bd -literal -offset indent
2619 anchor "external" on $ext_if {
2622 pass proto tcp from any to port { 25, 80, 443 }
2624 pass in proto tcp to any port 22
2628 Since the parser specification for anchor names is a string, any
2629 reference to an anchor name containing
2631 characters will require double quote
2633 characters around the anchor name.
2634 .Sh TRANSLATION EXAMPLES
2635 This example maps incoming requests on port 80 to port 8080, on
2636 which a daemon is running (because, for example, it is not run as root,
2637 and therefore lacks permission to bind to port 80).
2639 # use a macro for the interface name, so it can be changed easily
2642 # map daemon on 8080 to appear to be on 80
2643 rdr on $ext_if proto tcp from any to any port 80 -\*(Gt 127.0.0.1 port 8080
2648 modifier is given, packets matching the translation rule are passed without
2649 inspecting the filter rules:
2651 rdr pass on $ext_if proto tcp from any to any port 80 -\*(Gt 127.0.0.1 \e
2655 In the example below, vlan12 is configured as 192.168.168.1;
2656 the machine translates all packets coming from 192.168.168.0/24 to 204.92.77.111
2657 when they are going out any interface except vlan12.
2658 This has the net effect of making traffic from the 192.168.168.0/24
2659 network appear as though it is the Internet routable address
2660 204.92.77.111 to nodes behind any interface on the router except
2661 for the nodes on vlan12.
2662 (Thus, 192.168.168.1 can talk to the 192.168.168.0/24 nodes.)
2664 nat on ! vlan12 from 192.168.168.0/24 to any -\*(Gt 204.92.77.111
2667 In the example below, the machine sits between a fake internal 144.19.74.*
2668 network, and a routable external IP of 204.92.77.100.
2671 rule excludes protocol AH from being translated.
2674 no nat on $ext_if proto ah from 144.19.74.0/24 to any
2675 nat on $ext_if from 144.19.74.0/24 to any -\*(Gt 204.92.77.100
2678 In the example below, packets bound for one specific server, as well as those
2679 generated by the sysadmins are not proxied; all other connections are.
2682 no rdr on $int_if proto { tcp, udp } from any to $server port 80
2683 no rdr on $int_if proto { tcp, udp } from $sysadmins to any port 80
2684 rdr on $int_if proto { tcp, udp } from any to any port 80 -\*(Gt 127.0.0.1 \e
2688 This longer example uses both a NAT and a redirection.
2689 The external interface has the address 157.161.48.183.
2690 On localhost, we are running
2692 waiting for FTP sessions to be redirected to it.
2693 The three mandatory anchors for
2695 are omitted from this example; see the
2700 # Translate outgoing packets' source addresses (any protocol).
2701 # In this case, any address but the gateway's external address is mapped.
2702 nat on $ext_if inet from ! ($ext_if) to any -\*(Gt ($ext_if)
2705 # Map outgoing packets' source port to an assigned proxy port instead of
2706 # an arbitrary port.
2707 # In this case, proxy outgoing isakmp with port 500 on the gateway.
2708 nat on $ext_if inet proto udp from any port = isakmp to any -\*(Gt ($ext_if) \e
2712 # Translate outgoing packets' source address (any protocol).
2713 # Translate incoming packets' destination address to an internal machine
2715 binat on $ext_if from 10.1.2.150 to any -\*(Gt $ext_if
2718 # Translate incoming packets' destination addresses.
2719 # As an example, redirect a TCP and UDP port to an internal machine.
2720 rdr on $ext_if inet proto tcp from any to ($ext_if) port 8080 \e
2721 -\*(Gt 10.1.2.151 port 22
2722 rdr on $ext_if inet proto udp from any to ($ext_if) port 8080 \e
2723 -\*(Gt 10.1.2.151 port 53
2726 # Translate outgoing ftp control connections to send them to localhost
2727 # for proxying with ftp-proxy(8) running on port 8021.
2728 rdr on $int_if proto tcp from any to any port 21 -\*(Gt 127.0.0.1 port 8021
2731 In this example, a NAT gateway is set up to translate internal addresses
2732 using a pool of public addresses (192.0.2.16/28) and to redirect
2733 incoming web server connections to a group of web servers on the internal
2737 # Translate outgoing packets' source addresses using an address pool.
2738 # A given source address is always translated to the same pool address by
2739 # using the source-hash keyword.
2740 nat on $ext_if inet from any to any -\*(Gt 192.0.2.16/28 source-hash
2743 # Translate incoming web server connections to a group of web servers on
2744 # the internal network.
2745 rdr on $ext_if proto tcp from any to any port 80 \e
2746 -\*(Gt { 10.1.2.155, 10.1.2.160, 10.1.2.161 } round-robin
2750 # The external interface is kue0
2751 # (157.161.48.183, the only routable address)
2752 # and the private network is 10.0.0.0/8, for which we are doing NAT.
2754 # use a macro for the interface name, so it can be changed easily
2757 # normalize all incoming traffic
2758 scrub in on $ext_if all fragment reassemble
2760 # block and log everything by default
2761 block return log on $ext_if all
2763 # block anything coming from source we have no back routes for
2764 block in from no-route to any
2766 # block packets whose ingress interface does not match the one in
2767 # the route back to their source address
2768 block in from urpf-failed to any
2770 # block and log outgoing packets that do not have our address as source,
2771 # they are either spoofed or something is misconfigured (NAT disabled,
2772 # for instance), we want to be nice and do not send out garbage.
2773 block out log quick on $ext_if from ! 157.161.48.183 to any
2775 # silently drop broadcasts (cable modem noise)
2776 block in quick on $ext_if from any to 255.255.255.255
2778 # block and log incoming packets from reserved address space and invalid
2779 # addresses, they are either spoofed or misconfigured, we cannot reply to
2780 # them anyway (hence, no return-rst).
2781 block in log quick on $ext_if from { 10.0.0.0/8, 172.16.0.0/12, \e
2782 192.168.0.0/16, 255.255.255.255/32 } to any
2786 # pass out/in certain ICMP queries and keep state (ping)
2787 # state matching is done on host addresses and ICMP id (not type/code),
2788 # so replies (like 0/0 for 8/0) will match queries
2789 # ICMP error messages (which always refer to a TCP/UDP packet) are
2790 # handled by the TCP/UDP states
2791 pass on $ext_if inet proto icmp all icmp-type 8 code 0
2795 # pass out all UDP connections and keep state
2796 pass out on $ext_if proto udp all
2798 # pass in certain UDP connections and keep state (DNS)
2799 pass in on $ext_if proto udp from any to any port domain
2803 # pass out all TCP connections and modulate state
2804 pass out on $ext_if proto tcp all modulate state
2806 # pass in certain TCP connections and keep state (SSH, SMTP, DNS, IDENT)
2807 pass in on $ext_if proto tcp from any to any port { ssh, smtp, domain, \e
2810 # Do not allow Windows 9x SMTP connections since they are typically
2811 # a viral worm. Alternately we could limit these OSes to 1 connection each.
2812 block in on $ext_if proto tcp from any os {"Windows 95", "Windows 98"} \e
2816 # pass in/out all IPv6 traffic: note that we have to enable this in two
2817 # different ways, on both our physical interface and our tunnel
2818 pass quick on gif0 inet6
2819 pass quick on $ext_if proto ipv6
2823 # three interfaces: $int_if, $ext_if, and $wifi_if (wireless). NAT is
2824 # being done on $ext_if for all outgoing packets. tag packets in on
2825 # $int_if and pass those tagged packets out on $ext_if. all other
2826 # outgoing packets (i.e., packets from the wireless network) are only
2827 # permitted to access port 80.
2829 pass in on $int_if from any to any tag INTNET
2830 pass in on $wifi_if from any to any
2832 block out on $ext_if from any to any
2833 pass out quick on $ext_if tagged INTNET
2834 pass out on $ext_if proto tcp from any to any port 80
2836 # tag incoming packets as they are redirected to spamd(8). use the tag
2837 # to pass those packets through the packet filter.
2839 rdr on $ext_if inet proto tcp from \*(Ltspammers\*(Gt to port smtp \e
2840 tag SPAMD -\*(Gt 127.0.0.1 port spamd
2843 pass in on $ext_if inet proto tcp tagged SPAMD
2850 line = ( option | pf-rule | nat-rule | binat-rule | rdr-rule |
2851 antispoof-rule | altq-rule | queue-rule | trans-anchors |
2852 anchor-rule | anchor-close | load-anchor | table-rule |
2855 option = "set" ( [ "timeout" ( timeout | "{" timeout-list "}" ) ] |
2856 [ "ruleset-optimization" [ "none" | "basic" | "profile" ]] |
2857 [ "optimization" [ "default" | "normal" |
2858 "high-latency" | "satellite" |
2859 "aggressive" | "conservative" ] ]
2860 [ "limit" ( limit-item | "{" limit-list "}" ) ] |
2861 [ "loginterface" ( interface-name | "none" ) ] |
2862 [ "block-policy" ( "drop" | "return" ) ] |
2863 [ "state-policy" ( "if-bound" | "floating" ) ]
2864 [ "state-defaults" state-opts ]
2865 [ "require-order" ( "yes" | "no" ) ]
2866 [ "fingerprints" filename ] |
2867 [ "skip on" ifspec ] |
2868 [ "debug" ( "none" | "urgent" | "misc" | "loud" ) ] )
2870 pf-rule = action [ ( "in" | "out" ) ]
2871 [ "log" [ "(" logopts ")"] ] [ "quick" ]
2872 [ "on" ifspec ] [ route ] [ af ] [ protospec ]
2873 hosts [ filteropt-list ]
2875 logopts = logopt [ "," logopts ]
2876 logopt = "all" | "user" | "to" interface-name
2878 filteropt-list = filteropt-list filteropt | filteropt
2879 filteropt = user | group | flags | icmp-type | icmp6-type | "tos" tos |
2880 ( "no" | "keep" | "modulate" | "synproxy" ) "state"
2881 [ "(" state-opts ")" ] |
2882 "fragment" | "no-df" | "min-ttl" number | "set-tos" tos |
2883 "max-mss" number | "random-id" | "reassemble tcp" |
2884 fragmentation | "allow-opts" |
2885 "label" string | "tag" string | [ ! ] "tagged" string |
2886 "set prio" ( number | "(" number [ [ "," ] number ] ")" ) |
2887 "queue" ( string | "(" string [ [ "," ] string ] ")" ) |
2888 "rtable" number | "probability" number"%" | "prio" number
2890 nat-rule = [ "no" ] "nat" [ "pass" [ "log" [ "(" logopts ")" ] ] ]
2891 [ "on" ifspec ] [ af ]
2892 [ protospec ] hosts [ "tag" string ] [ "tagged" string ]
2893 [ "-\*(Gt" ( redirhost | "{" redirhost-list "}" )
2894 [ portspec ] [ pooltype ] [ "static-port" ] ]
2896 binat-rule = [ "no" ] "binat" [ "pass" [ "log" [ "(" logopts ")" ] ] ]
2897 [ "on" interface-name ] [ af ]
2898 [ "proto" ( proto-name | proto-number ) ]
2899 "from" address [ "/" mask-bits ] "to" ipspec
2900 [ "tag" string ] [ "tagged" string ]
2901 [ "-\*(Gt" address [ "/" mask-bits ] ]
2903 rdr-rule = [ "no" ] "rdr" [ "pass" [ "log" [ "(" logopts ")" ] ] ]
2904 [ "on" ifspec ] [ af ]
2905 [ protospec ] hosts [ "tag" string ] [ "tagged" string ]
2906 [ "-\*(Gt" ( redirhost | "{" redirhost-list "}" )
2907 [ portspec ] [ pooltype ] ]
2909 antispoof-rule = "antispoof" [ "log" ] [ "quick" ]
2910 "for" ifspec [ af ] [ "label" string ]
2912 table-rule = "table" "\*(Lt" string "\*(Gt" [ tableopts-list ]
2913 tableopts-list = tableopts-list tableopts | tableopts
2914 tableopts = "persist" | "const" | "counters" | "file" string |
2915 "{" [ tableaddr-list ] "}"
2916 tableaddr-list = tableaddr-list [ "," ] tableaddr-spec | tableaddr-spec
2917 tableaddr-spec = [ "!" ] tableaddr [ "/" mask-bits ]
2918 tableaddr = hostname | ifspec | "self" |
2919 ipv4-dotted-quad | ipv6-coloned-hex
2921 altq-rule = "altq on" interface-name queueopts-list
2923 queue-rule = "queue" string [ "on" interface-name ] queueopts-list
2926 anchor-rule = "anchor" [ string ] [ ( "in" | "out" ) ] [ "on" ifspec ]
2927 [ af ] [ protospec ] [ hosts ] [ filteropt-list ] [ "{" ]
2931 trans-anchors = ( "nat-anchor" | "rdr-anchor" | "binat-anchor" ) string
2932 [ "on" ifspec ] [ af ] [ "proto" ] [ protospec ] [ hosts ]
2934 load-anchor = "load anchor" string "from" filename
2936 queueopts-list = queueopts-list queueopts | queueopts
2937 queueopts = [ "bandwidth" bandwidth-spec ] |
2938 [ "qlimit" number ] | [ "tbrsize" number ] |
2939 [ "priority" number ] | [ schedulers ]
2940 schedulers = ( cbq-def | priq-def | hfsc-def )
2941 bandwidth-spec = "number" ( "b" | "Kb" | "Mb" | "Gb" | "%" )
2943 action = "pass" | "block" [ return ] | [ "no" ] "scrub"
2944 return = "drop" | "return" | "return-rst" [ "( ttl" number ")" ] |
2945 "return-icmp" [ "(" icmpcode [ [ "," ] icmp6code ] ")" ] |
2946 "return-icmp6" [ "(" icmp6code ")" ]
2947 icmpcode = ( icmp-code-name | icmp-code-number )
2948 icmp6code = ( icmp6-code-name | icmp6-code-number )
2950 ifspec = ( [ "!" ] ( interface-name | interface-group ) ) |
2951 "{" interface-list "}"
2952 interface-list = [ "!" ] ( interface-name | interface-group )
2953 [ [ "," ] interface-list ]
2954 route = ( "route-to" | "reply-to" | "dup-to" )
2955 ( routehost | "{" routehost-list "}" )
2957 af = "inet" | "inet6"
2959 protospec = "proto" ( proto-name | proto-number |
2960 "{" proto-list "}" )
2961 proto-list = ( proto-name | proto-number ) [ [ "," ] proto-list ]
2964 "from" ( "any" | "no-route" | "urpf-failed" | "self" | host |
2965 "{" host-list "}" ) [ port ] [ os ]
2966 "to" ( "any" | "no-route" | "self" | host |
2967 "{" host-list "}" ) [ port ]
2969 ipspec = "any" | host | "{" host-list "}"
2970 host = [ "!" ] ( address [ "/" mask-bits ] | "\*(Lt" string "\*(Gt" )
2971 redirhost = address [ "/" mask-bits ]
2972 routehost = "(" interface-name [ address [ "/" mask-bits ] ] ")"
2973 address = ( interface-name | interface-group |
2974 "(" ( interface-name | interface-group ) ")" |
2975 hostname | ipv4-dotted-quad | ipv6-coloned-hex )
2976 host-list = host [ [ "," ] host-list ]
2977 redirhost-list = redirhost [ [ "," ] redirhost-list ]
2978 routehost-list = routehost [ [ "," ] routehost-list ]
2980 port = "port" ( unary-op | binary-op | "{" op-list "}" )
2981 portspec = "port" ( number | name ) [ ":" ( "*" | number | name ) ]
2982 os = "os" ( os-name | "{" os-list "}" )
2983 user = "user" ( unary-op | binary-op | "{" op-list "}" )
2984 group = "group" ( unary-op | binary-op | "{" op-list "}" )
2986 unary-op = [ "=" | "!=" | "\*(Lt" | "\*(Le" | "\*(Gt" | "\*(Ge" ]
2988 binary-op = number ( "\*(Lt\*(Gt" | "\*(Gt\*(Lt" | ":" ) number
2989 op-list = ( unary-op | binary-op ) [ [ "," ] op-list ]
2991 os-name = operating-system-name
2992 os-list = os-name [ [ "," ] os-list ]
2994 flags = "flags" ( [ flag-set ] "/" flag-set | "any" )
2995 flag-set = [ "F" ] [ "S" ] [ "R" ] [ "P" ] [ "A" ] [ "U" ] [ "E" ]
2998 icmp-type = "icmp-type" ( icmp-type-code | "{" icmp-list "}" )
2999 icmp6-type = "icmp6-type" ( icmp-type-code | "{" icmp-list "}" )
3000 icmp-type-code = ( icmp-type-name | icmp-type-number )
3001 [ "code" ( icmp-code-name | icmp-code-number ) ]
3002 icmp-list = icmp-type-code [ [ "," ] icmp-list ]
3004 tos = ( "lowdelay" | "throughput" | "reliability" |
3007 state-opts = state-opt [ [ "," ] state-opts ]
3008 state-opt = ( "max" number | "no-sync" | timeout | "sloppy" |
3009 "source-track" [ ( "rule" | "global" ) ] |
3010 "max-src-nodes" number | "max-src-states" number |
3011 "max-src-conn" number |
3012 "max-src-conn-rate" number "/" number |
3013 "overload" "\*(Lt" string "\*(Gt" [ "flush" ] |
3014 "if-bound" | "floating" )
3016 fragmentation = [ "fragment reassemble" ]
3018 timeout-list = timeout [ [ "," ] timeout-list ]
3019 timeout = ( "tcp.first" | "tcp.opening" | "tcp.established" |
3020 "tcp.closing" | "tcp.finwait" | "tcp.closed" |
3021 "udp.first" | "udp.single" | "udp.multiple" |
3022 "icmp.first" | "icmp.error" |
3023 "other.first" | "other.single" | "other.multiple" |
3024 "frag" | "interval" | "src.track" |
3025 "adaptive.start" | "adaptive.end" ) number
3027 limit-list = limit-item [ [ "," ] limit-list ]
3028 limit-item = ( "states" | "frags" | "src-nodes" ) number
3030 pooltype = ( "bitmask" | "random" |
3031 "source-hash" [ ( hex-key | string-key ) ] |
3032 "round-robin" ) [ sticky-address ]
3034 subqueue = string | "{" queue-list "}"
3035 queue-list = string [ [ "," ] string ]
3036 cbq-def = "cbq" [ "(" cbq-opt [ [ "," ] cbq-opt ] ")" ]
3037 priq-def = "priq" [ "(" priq-opt [ [ "," ] priq-opt ] ")" ]
3038 hfsc-def = "hfsc" [ "(" hfsc-opt [ [ "," ] hfsc-opt ] ")" ]
3039 cbq-opt = ( "default" | "borrow" | "red" | "ecn" | "rio" )
3040 priq-opt = ( "default" | "red" | "ecn" | "rio" )
3041 hfsc-opt = ( "default" | "red" | "ecn" | "rio" |
3042 linkshare-sc | realtime-sc | upperlimit-sc )
3043 linkshare-sc = "linkshare" sc-spec
3044 realtime-sc = "realtime" sc-spec
3045 upperlimit-sc = "upperlimit" sc-spec
3046 sc-spec = ( bandwidth-spec |
3047 "(" bandwidth-spec number bandwidth-spec ")" )
3048 include = "include" filename
3051 .Bl -tag -width "/etc/protocols" -compact
3055 Default location of the ruleset file.
3056 The file has to be created manually as it is not installed with a
3057 standard installation.
3059 Default location of OS fingerprints.
3060 .It Pa /etc/protocols
3061 Protocol name database.
3062 .It Pa /etc/services
3063 Service name database.
3086 file format first appeared in