1 .\" $OpenBSD: pf.conf.5,v 1.527 2013/04/25 16:53:11 sobrado Exp $
3 .\" Copyright (c) 2002, Daniel Hartmeier
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
10 .\" - Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" - Redistributions in binary form must reproduce the above
13 .\" copyright notice, this list of conditions and the following
14 .\" disclaimer in the documentation and/or other materials provided
15 .\" with the distribution.
17 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 .\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 .\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 .\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 .\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 .\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
30 .Dd $Mdocdate: April 25 2013 $
35 .Nd packet filter configuration file
39 packet filter modifies, drops, or passes packets according to rules or
40 definitions specified in
43 This is an overview of the sections in this manual page:
45 .It Sy Packet Filtering
46 Packet filtering, including network address translation (NAT).
48 Global options tune the behaviour of the packet filtering engine.
50 Queueing provides rule-based bandwidth control.
52 Tables provide a method for dealing with large numbers of addresses.
54 Anchors are containers for rules and tables.
55 .It Sy Stateful Filtering
56 Stateful filtering tracks packets by state.
57 .It Sy Traffic Normalisation
58 Including scrub, fragment handling, and blocking spoofed traffic.
59 .It Sy Operating System Fingerprinting
60 A method for detecting a host's operating system.
62 Some example rulesets.
65 The current line can be extended over multiple lines using a backslash
67 Comments can be put anywhere in the file using a hash mark
69 and extend to the end of the current line.
70 Care should be taken when commenting out multi-line text:
71 the comment is effective until the end of the entire block.
73 Argument names not beginning with a letter, digit, or underscore
76 Additional configuration files can be included with the
79 .Bd -literal -offset indent
80 include "/etc/pf/sub.filter.conf"
83 Macros can be defined that will later be expanded in context.
84 Macro names must start with a letter, digit, or underscore,
85 and may contain any of those characters.
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
106 packets based on attributes of their layer 3
108 Filter rules determine which of these actions are taken;
109 filter parameters specify the packets to which a rule applies.
111 For each packet processed by the packet filter, the filter rules are
112 evaluated in sequential order, from first to last.
117 the last matching rule decides what action is taken;
118 if no rule matches the packet, the default action is to pass
119 the packet without creating a state.
122 rules are evaluated every time they match;
123 the pass/block state of a packet remains unchanged.
125 Most parameters are optional.
126 If a parameter is specified, the rule only applies to packets with
128 Certain parameters can be expressed as lists, in which case
130 generates all needed rule combinations.
134 filters packets statefully:
135 the first time a packet matches a
137 rule, a state entry is created.
138 The packet filter examines each packet to see if it matches an existing state.
139 If it does, the packet is passed without evaluation of any rules.
140 After the connection is closed or times out, the state entry is automatically
143 The following actions can be used in the filter:
146 The packet is blocked.
147 There are a number of ways in which a
149 rule can behave when blocking a packet.
150 The default behaviour is to
152 packets silently, however this can be overridden or made
153 explicit either globally, by setting the
155 option, or on a per-rule basis with one of the following options:
157 .Bl -tag -width "return-icmp6XXX" -compact
159 The packet is silently dropped.
161 This causes a TCP RST to be returned for TCP packets
162 and an ICMP UNREACHABLE for other types of packets.
165 This causes ICMP messages to be returned for packets which match the rule.
166 By default this is an ICMP UNREACHABLE message, however this
167 can be overridden by specifying a message as a code or number.
169 This applies only to TCP packets,
170 and issues a TCP RST which closes the connection.
171 An optional parameter,
173 may be given with a TTL value.
176 Options returning ICMP packets currently have no effect if
180 as the code to support this feature has not yet been implemented.
182 The simplest mechanism to block everything by default and only pass
183 packets that match explicit rules is specify a first filter rule of:
187 The packet is matched.
188 This mechanism is used to provide fine grained filtering
189 without altering the block/pass state of a packet.
191 rules differ from block and pass rules in that
192 parameters are set every time a packet matches the rule,
193 not only on the last matching rule.
194 For the following parameters,
195 this means that the parameter effectively becomes
197 until explicitly overridden:
208 in that the action happens every time a rule matches
209 i.e. a single packet can get logged more than once.
211 The packet is passed;
212 state is created unless the
217 The following parameters can be used in the filter:
219 .It Ar in No or Ar out
220 A packet always comes in on, or goes out through, one interface.
224 apply to incoming and outgoing packets;
225 if neither are specified,
226 the rule will match packets in both directions.
228 In addition to the action specified, a log message is generated.
229 Only the packet that establishes the state is logged,
233 The logged packets are sent to a
235 interface, by default
237 This interface is monitored by the
239 logging daemon, which dumps the logged packets to the file
245 Used to force logging of all packets for a connection.
246 This is not necessary when
248 is explicitly specified.
251 packets are logged to
253 .It Ar log Pq Ar matches
254 Used to force logging of this packet on all subsequent matching rules.
255 .It Ar log Pq Ar user
256 Logs the UID and PID of the
257 socket on the local host used to send or receive a packet,
258 in addition to the normal information.
259 .It Ar log Pq Ar to Aq Ar interface
260 Send logs to the specified
265 If a packet matches a rule which has the
267 option set, this rule
268 is considered the last matching rule, and evaluation of subsequent rules
270 .It Ar on Aq Ar interface
271 This rule applies only to packets coming in on, or going out through, this
272 particular interface or interface group.
273 For more information on interface groups,
278 .It Ar on Ar rdomain Aq Ar number
279 This rule applies only to packets coming in on, or going out through, this
280 particular routing domain.
282 This rule applies only to packets of this address family.
287 .It Ar proto Aq Ar protocol
288 This rule applies only to packets of this protocol.
289 Common protocols are ICMP, ICMP6, TCP, and UDP.
290 For a list of all the protocol name to number mappings used by
295 .Ar from Aq Ar source
296 .Ar port Aq Ar source
301 This rule applies only to packets with the specified source and destination
304 Addresses can be specified in CIDR notation (matching netblocks), as
305 symbolic host names, interface names or interface group names, or as any
306 of the following keywords:
308 .Bl -tag -width xxxxxxxxxxxxxx -compact
312 Any address which is not currently routable.
313 .It Ar route Aq Ar label
314 Any address matching the given
318 Expands to all addresses assigned to all interfaces.
320 Any address matching the given table.
322 Any source address that fails a unicast reverse path forwarding (URPF)
323 check, i.e. packets coming in on an interface other than that which holds
324 the route back to the packet's source address.
327 Ranges of addresses are specified using the
331 .Dq 10.1.1.10 - 10.1.1.12
332 means all addresses from 10.1.1.10 to 10.1.1.12,
333 hence addresses 10.1.1.10, 10.1.1.11, and 10.1.1.12.
335 Interface names, interface group names, and
337 can have modifiers appended:
339 .Bl -tag -width xxxxxxxxxxxx -compact
341 Do not include interface aliases.
343 Translates to the interface's broadcast address(es).
345 Translates to the network(s) attached to the interface.
347 Translates to the point-to-point interface's peer address(es).
350 Host names may also have the
352 option appended to restrict the name resolution to the first of each
353 v4 and v6 address found.
355 Host name resolution and interface to address translation are done at
357 When the address of an interface (or host name) changes (under DHCP or PPP,
358 for instance), the ruleset must be reloaded for the change to be reflected
360 Surrounding the interface name (and optional modifiers) in parentheses
361 changes this behaviour.
362 When the interface name is surrounded by parentheses, the rule is
363 automatically updated whenever the interface changes its address.
364 The ruleset does not need to be reloaded.
365 This is especially useful with
368 Ports can be specified either by number or by name.
369 For example, port 80 can be specified as
371 For a list of all port name to number mappings used by
376 Ports and ranges of ports are specified using these operators:
377 .Bd -literal -offset indent
381 \*(Le (less than or equal)
383 \*(Ge (greater than or equal)
384 : (range including boundaries)
385 \*(Gt\*(Lt (range excluding boundaries)
386 \*(Lt\*(Gt (except range)
393 are binary operators (they take two arguments).
398 .Sq all ports \*(Ge 2000 and \*(Le 2004 ,
399 hence ports 2000, 2001, 2002, 2003, and 2004.
400 .It port 2000 \*(Gt\*(Lt 2004
402 .Sq all ports \*(Gt 2000 and \*(Lt 2004 ,
403 hence ports 2001, 2002, and 2003.
404 .It port 2000 \*(Lt\*(Gt 2004
406 .Sq all ports \*(Lt 2000 or \*(Gt 2004 ,
407 hence ports 1\(en1999 and 2005\(en65535.
410 The operating system of the source host can be specified in the case of TCP
415 .Sx OPERATING SYSTEM FINGERPRINTING
416 section for more information.
418 The host, port, and OS specifications are optional,
419 as in the following examples:
420 .Bd -literal -offset indent
422 pass in from any to any
423 pass in proto tcp from any port \*(Lt 1024 to any
424 pass in proto tcp from any to any port 25
425 pass in proto tcp from 10.0.0.0/8 port \*(Ge 1024 \e
426 to ! 10.1.2.3 port != ssh
427 pass in proto tcp from any os "OpenBSD"
428 pass in proto tcp from route "DTAG"
432 The following additional parameters can be used in the filter:
434 .Bl -tag -width Ds -compact
436 This is equivalent to "from any to any".
439 By default, IPv4 packets with IP options or IPv6 packets with routing
440 extension headers are blocked.
445 rule, packets that pass the filter based on that rule (last matching)
446 do so even if they contain IP options or routing extension headers.
447 For packets that match state, the rule that initially created the
451 rule that is used when a packet does not match any rules does not
454 .It Ar divert-packet Ar port Aq Ar port
455 Used to send matching packets to
457 sockets bound to port
459 If the default option of fragment reassembly is enabled, scrubbing with
466 Used to receive replies for sockets that are bound to addresses
467 which are not local to the machine.
470 for information on how to bind these sockets.
472 .It Xo Ar divert-to Aq Ar host
475 Used to redirect packets to a local socket bound to
479 The packets will not be modified, so
481 on the socket will return the original destination address of the packet.
483 .It Xo Ar flags Aq Ar a
487 This rule only applies to TCP packets that have the flags
491 Flags not specified in
494 For stateful connections, the default is
496 To indicate that flags should not be checked at all, specify
498 The flags are: (F)IN, (S)YN, (R)ST, (P)USH, (A)CK, (U)RG, (E)CE, and C(W)R.
502 The other flags are ignored.
504 This is the default setting for stateful connections.
505 Out of SYN and ACK, exactly SYN may be set.
506 SYN, SYN+PSH, and SYN+RST match, but SYN+ACK, ACK, and ACK+RST do not.
507 This is more restrictive than the previous example.
509 If the first set is not specified, it defaults to none.
510 All of SYN, FIN, RST, and ACK must be unset.
515 is applied by default (unless
517 is specified), only the initial SYN packet of a TCP handshake will create
518 a state for a TCP connection.
519 It is possible to be less restrictive, and allow state creation from
522 packets, by specifying
526 to synchronize to existing connections, for instance
527 if one flushes the state table.
528 However, states created from such intermediate packets may be missing
529 connection details such as the TCP window scaling factor.
530 States which modify the packet flow, such as those affected by
537 options, or scrubbed with
539 will also not be recoverable from intermediate packets.
540 Such connections will stall and time out.
542 .It Ar group Aq Ar group
545 this rule only applies to packets of sockets owned by the specified group.
547 .It Xo Ar icmp-type Aq Ar type
550 .It Xo Ar icmp6-type Aq Ar type
553 This rule only applies to ICMP or ICMP6 packets with the specified type
555 Text names for ICMP types and codes are listed in
559 The protocol and the ICMP type indicator
567 .It Ar label Aq Ar string
568 Adds a label to the rule, which can be used to identify the rule.
571 shows per-rule statistics for rules that have labels.
573 The following macros can be used in labels:
575 .Bl -tag -width "$srcaddrXXX" -compact -offset indent
577 The destination IP address.
579 The destination port specification.
587 The source IP address.
589 The source port specification.
593 .Bd -literal -offset indent -compact
594 ips = "{ 1.2.3.4, 1.2.3.5 }"
595 pass in proto tcp from any to $ips \e
596 port \*(Gt 1023 label "$dstaddr:$dstport"
600 .Bd -literal -offset indent -compact
601 pass in inet proto tcp from any to 1.2.3.4 \e
602 port \*(Gt 1023 label "1.2.3.4:\*(Gt1023"
603 pass in inet proto tcp from any to 1.2.3.5 \e
604 port \*(Gt 1023 label "1.2.3.5:\*(Gt1023"
607 The macro expansion for the
609 directive occurs only at configuration file parse time, not during runtime.
612 Creates a one shot rule that will remove itself from an active ruleset after
614 In case this is the only rule in the anchor, the anchor will be destroyed
615 automatically after the rule is matched.
617 .It Ar probability Aq Ar number
618 A probability attribute can be attached to a rule,
619 with a value set between 0 and 100%,
620 in which case the rule is honoured using the given probability value.
621 For example, the following rule will drop 20% of incoming ICMP packets:
623 .Dl block in proto icmp probability 20%
625 .It Ar received-on Aq Ar interface
626 Only match packets which were received on the specified
628 (or interface group).
630 .It Ar rtable Aq Ar number
631 Used to select an alternate routing table for the routing lookup.
632 Only effective before the route lookup happened, i.e. when filtering inbound.
634 .It Xo Ar set prio Aq Ar priority
635 .No \*(Ba ( Aq Ar priority ,
638 Packets matching this rule will be assigned a specific queueing priority.
639 Priorities are assigned as integers 0 through 7,
640 with a default priority of 3.
641 If the packet is transmitted on a
643 interface, the queueing priority will also be written as the priority
644 code point in the 802.1Q VLAN header.
645 If two priorities are given, packets which have a TOS of
647 and TCP ACKs with no data payload will be assigned to the second one.
650 .Bd -literal -offset indent
651 pass in proto tcp to port 25 set prio 2
652 pass in proto tcp to port 22 set prio (2, 5)
655 The interface priority queues accessed by the
657 keyword are always enabled and do not require any additional
658 configuration, unlike the queues described below and in the
662 .It Xo Ar set queue Aq Ar queue
663 .No \*(Ba ( Aq Ar queue ,
666 Packets matching this rule will be assigned to the specified queue.
667 If two queues are given, packets which have a TOS of
669 and TCP ACKs with no data payload will be assigned to the second one.
675 .Bd -literal -offset indent
676 pass in proto tcp to port 25 set queue mail
677 pass in proto tcp to port 22 set queue(ssh_bulk, ssh_prio)
680 .It Xo Ar set tos Aq Ar string
681 .No \*(Ba Aq Ar number
683 Enforces a TOS for matching packets.
692 or one of the DiffServ Code Points:
697 may be either a hex or decimal number.
699 .It Ar tag Aq Ar string
700 Packets matching this rule will be tagged with the
702 The tag acts as an internal marker that can be used to
703 identify these packets later on.
704 This can be used, for example, to provide trust between
705 interfaces and to determine if packets have been
706 processed by translation rules.
709 meaning that the packet will be tagged even if the rule
710 is not the last matching rule.
711 Further matching rules can replace the tag with a
712 new one but will not remove a previously applied tag.
713 A packet is only ever assigned one tag at a time.
714 Tags take the same macros as labels (see above).
716 .It Ar tagged Aq Ar string
717 Used with filter or translation rules
718 to specify that packets must already
719 be tagged with the given tag in order to match the rule.
720 Inverse tag matching can also be done
727 .It Xo Ar tos Aq Ar string
728 .No \*(Ba Aq Ar number
730 This rule applies to packets with the specified TOS bits set.
739 or one of the DiffServ Code Points:
744 may be either a hex or decimal number.
746 For example, the following rules are identical:
747 .Bd -literal -offset indent
748 pass all tos lowdelay
753 .It Ar user Aq Ar user
754 This rule only applies to packets of sockets owned by the specified user.
755 For outgoing connections initiated from the firewall, this is the user
756 that opened the connection.
757 For incoming connections to the firewall itself, this is the user that
758 listens on the destination port.
759 For forwarded connections, where the firewall is not a connection endpoint,
760 the user and group are
763 All packets, both outgoing and incoming, of one connection are associated
764 with the same user and group.
765 Only TCP and UDP packets can be associated with users.
767 User and group refer to the effective (as opposed to the real) IDs, in
768 case the socket is created by a setuid/setgid process.
769 User and group IDs are stored when a socket is created;
770 when a process creates a listening socket as root (for instance, by
771 binding to a privileged port) and subsequently changes to another
772 user ID (to drop privileges), the credentials will remain root.
774 User and group IDs can be specified as either numbers or names.
775 The syntax is similar to the one for ports.
778 matches packets of forwarded connections.
780 can only be used with the operators
784 Other constructs like
785 .Cm user \*(Ge unknown
787 Forwarded packets with unknown user and group ID match only rules
788 that explicitly compare
796 does not match forwarded packets.
797 The following example allows only selected users to open outgoing
799 .Bd -literal -offset indent
800 block out proto { tcp, udp } all
801 pass out proto { tcp, udp } all user { \*(Lt 1000, dhartmei }
805 Translation options modify either the source or destination address and
806 port of the packets associated with a stateful connection.
808 modifies the specified address and/or port in the packet and recalculates
809 IP, TCP, and UDP checksums as necessary.
811 Subsequent rules will see packets as they look
812 after any addresses and ports have been translated.
813 These rules will therefore have to filter based on the translated
814 address and port number.
816 The state entry created permits
818 to keep track of the original address for traffic associated with that state
819 and correctly direct return traffic for that connection.
821 Different types of translation are possible with pf:
822 .Bl -tag -width xxxxxxxx
824 Translation between different address families (NAT64) is handled
828 Because address family translation overrides the routing table, it's
831 on inbound rules, and a source address for the resulting translation
832 must always be specified.
834 The optional second argument is the host or subnet the original
835 addresses are translated into for the destination.
836 The lowest bits of the original destination address form the host
837 part of the new destination address according to the specified subnet.
838 It is possible to embed a complete IPv4 address into an IPv6 address
839 using a network prefix of /96 or smaller.
841 When a destination address is not specified it is assumed that the host
843 For IPv6 to IPv4 translation this would mean using only the lower 32
844 bits of the original IPv6 destination address.
845 For IPv4 to IPv6 translation the destination subnet defaults to the
846 subnet of the new IPv6 source address with a prefix length of /96.
847 See RFC 6052 Section 2.2 for details on how the prefix determines the
848 destination address encoding.
850 For example, the following rules are identical:
851 .Bd -literal -offset indent
852 pass in inet af-to inet6 from 2001:db8::1 to 2001:db8::/96
853 pass in inet af-to inet6 from 2001:db8::1
856 In the above example the matching IPv4 packets will be modified to
857 have a source address of 2001:db8::1 and a destination address will
858 get prefixed with 2001:db8::/96, e.g. 198.51.100.100 will be
859 translated to 2001:db8::c633:6464.
861 In the reverse case the following rules are identical:
862 .Bd -literal -offset indent
863 pass in inet6 af-to inet from 198.51.100.1 to 0.0.0.0/0
864 pass in inet6 af-to inet from 198.51.100.1
867 The destination IPv4 address is assumed to be embedded inside the
868 original IPv6 destination address, e.g. 64:ff9b::c633:6464 will be
869 translated to 198.51.100.100.
871 The current implementation will only extract IPv4 addresses from the
872 IPv6 addresses with a prefix length of /96 and greater.
876 rule specifies a bidirectional mapping between an external IP
877 netblock and an internal IP netblock.
878 It expands to an outbound
886 option specifies that IP addresses are to be changed as the packet
887 traverses the given interface.
888 This technique allows one or more IP addresses
889 on the translating host to support network traffic for a larger range of
890 machines on an "inside" network.
891 Although in theory any IP address can be used on the inside, it is strongly
892 recommended that one of the address ranges defined by RFC 1918 be used.
894 .Bd -literal -offset indent
895 10.0.0.0 \(en 10.255.255.255 (all of net 10, i.e. 10/8)
896 172.16.0.0 \(en 172.31.255.255 (i.e. 172.16/12)
897 192.168.0.0 \(en 192.168.255.255 (i.e. 192.168/16)
901 is usually applied outbound.
902 If applied inbound, nat-to to a local IP address is not supported.
904 The packet is redirected to another destination and possibly a
907 can optionally specify port ranges instead of single ports.
910 .It match in ... port 2000:2999 rdr-to ... port 4000
911 redirects ports 2000 to 2999 (inclusive) to port 4000.
912 .It match in ... port 2000:2999 rdr-to ... port 4000:*
913 redirects port 2000 to 4000, port 2001 to 4001, ..., port 2999 to 4999.
917 is usually applied inbound.
918 If applied outbound, rdr-to to a local IP address is not supported.
921 In addition to modifying the address, some translation rules may modify
922 source or destination ports for TCP or UDP connections;
923 implicitly in the case of
925 options and explicitly in the case of
928 Port numbers are never translated with a
932 Translation options apply only to packets that pass through the specified
933 interface, and if no interface is specified, translation is applied
934 to packets on all interfaces.
935 For instance, redirecting port 80 on an external interface to an internal
936 web server will only work for connections originating from the outside.
937 Connections to the address of the external interface from local hosts will
938 not be redirected, since such packets do not actually pass through the
940 Redirections cannot reflect packets back through the interface they arrive
941 on, they can only be redirected to hosts connected to different interfaces
942 or to the firewall itself.
944 However packets may be redirected to hosts connected to the interface the
945 packet arrived on by using redirection with NAT.
947 .Bd -literal -offset indent
948 pass in on $int_if proto tcp from $int_net to $ext_if port 80 \e
950 pass out on $int_if proto tcp to $server port 80 \e
951 received-on $int_if nat-to $int_if
954 Note that redirecting external incoming connections to the loopback address
955 will effectively allow an external host to connect to daemons
956 bound solely to the loopback address, circumventing the traditional
957 blocking of such connections on a real interface.
959 .Bd -literal -offset indent
960 pass in on egress proto tcp from any to any port smtp \e
961 rdr-to 127.0.0.1 port spamd
964 Unless this effect is desired, any of the local non-loopback addresses
965 should be used instead as the redirection target, which allows external
966 connections only to daemons bound to this address or not bound to
974 options for which there is a single redirection address which has a
975 subnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP
976 address), a variety of different methods for assigning this address can be
982 option applies the network portion of the redirection address to the address
983 to be modified (source with
987 .It Ar least-states Op Ar sticky-address
990 option selects the address with the least active states from
991 a given address pool and considers given weights
992 associated with address(es).
993 Weights can be specified between 1 and 65535.
994 Addresses with higher weights are selected more often.
997 can be specified to ensure that multiple connections from the
998 same source are mapped to the same redirection address.
999 Associations are destroyed as soon as there are
1000 no longer states which refer to them;
1001 in order to make the mappings last
1002 beyond the lifetime of the states,
1003 increase the global options with
1004 .Ar set timeout src.track .
1005 .It Ar random Op Ar sticky-address
1008 option selects an address at random within the defined block of addresses.
1010 is as described above.
1011 .It Ar round-robin Op Ar sticky-address
1014 option loops through the redirection address(es) and considers given weights
1015 associated with address(es).
1016 Weights can be specified between 1 and 65535.
1017 Addresses with higher weights are selected more often.
1019 is as described above.
1020 .It Ar source-hash Op Ar key
1023 option uses a hash of the source address to determine the redirection address,
1024 ensuring that the redirection address is always the same for a given source.
1027 can be specified after this keyword either in hex or as a string;
1030 randomly generates a key for source-hash every time the
1031 ruleset is reloaded.
1039 from modifying the source port on TCP and UDP packets.
1042 When more than one redirection address or a table is specified,
1046 are the only permitted pool types.
1048 If a packet matches a rule with one of the following route options set,
1049 the packet filter will route the packet according to the type of route option.
1050 When such a rule creates state, the route option is also applied to all
1051 packets matching the same connection.
1052 .Bl -tag -width xxxx
1056 option creates a duplicate of the packet and routes it like
1058 The original packet gets routed as it normally would.
1062 option is similar to
1064 but routes packets that pass in the opposite direction (replies) to the
1065 specified interface.
1066 Opposite direction is only defined in the context of a state entry, and
1068 is useful only in rules that create state.
1069 It can be used on systems with multiple external connections to
1070 route all outgoing packets of a connection through the interface
1071 the incoming connection arrived through (symmetric routing enforcement).
1075 option routes the packet to the specified interface with an optional address
1079 rule creates state, only packets that pass in the same direction as the
1080 filter rule specifies will be routed in this way.
1081 Packets passing in the opposite direction (replies) are not affected
1082 and are routed normally.
1091 for which there is a single redirection address which has a
1092 subnet mask smaller than 32 for IPv4 or 128 for IPv6 (more than one IP
1104 may be tuned for various situations using the
1108 .It Ar set block-policy
1111 option sets the default behaviour for the packet
1115 .Bl -tag -width xxxxxxxx -compact
1117 Packet is silently dropped.
1119 A TCP RST is returned for blocked TCP packets,
1120 an ICMP UNREACHABLE is returned for blocked UDP packets,
1121 and all other packets are silently dropped.
1126 which limits the severity of log messages printed by
1128 This should be a keyword from the following ordered list
1129 (highest to lowest):
1139 These keywords correspond to the similar (LOG_) values specified to the
1142 .It Ar set fingerprints
1143 Load fingerprints of known operating systems from the given filename.
1144 By default fingerprints of known operating systems are automatically
1147 but can be overridden via this option.
1148 Setting this option may leave a small period of time where the fingerprints
1149 referenced by the currently active ruleset are inconsistent until the new
1150 ruleset finishes loading.
1154 identifies this firewall's state table entries to other firewalls
1158 By default the hostid is set to a pseudo-random value, however it may be
1159 desirable to manually configure it, for example to more easily identify the
1160 source of state table entries.
1161 The hostid may be specified in either decimal or hexadecimal.
1163 Sets hard limits on the memory pools used by the packet filter.
1166 for an explanation of memory pools.
1169 to set the maximum number of entries in the memory pool used by state table
1170 entries (generated by
1172 rules which do not specify
1176 .Dl set limit states 20000
1178 To set the maximum number of entries in the memory pool used for fragment
1181 .Dl set limit frags 2000
1183 This maximum may not exceed, and should be well below, the maximum number
1185 .Pq sysctl kern.maxclusters
1188 To set the maximum number of entries in the memory pool used for tracking
1189 source IP addresses (generated by the
1195 .Dl set limit src-nodes 2000
1197 To set limits on the memory pools used by tables:
1198 .Bd -literal -offset indent
1199 set limit tables 1000
1200 set limit table-entries 100000
1203 The first limits the number of tables that can exist to 1000.
1204 The second limits the overall number of addresses that can be stored
1205 in tables to 100000.
1207 Various limits can be combined on a single line:
1208 .Bd -literal -offset indent
1209 set limit { states 20000, frags 2000, src-nodes 2000 }
1211 .It Ar set loginterface
1212 Enable collection of packet and byte count statistics for the given
1213 interface or interface group.
1214 These statistics can be viewed using:
1220 collects statistics on the interface named dc0:
1222 .Dl set loginterface dc0
1224 One can disable the loginterface using:
1226 .Dl set loginterface none
1227 .It Ar set optimization
1228 Optimize state timeouts for one of the following network environments:
1230 .Bl -tag -width Ds -compact
1232 Aggressively expire connections.
1233 This can greatly reduce the memory usage of the firewall at the cost of
1234 dropping idle connections early.
1236 Extremely conservative settings.
1237 Avoid dropping legitimate connections at the
1238 expense of greater memory utilization (possibly much greater on a busy
1239 network) and slightly increased processor utilization.
1241 A high-latency environment (such as a satellite connection).
1243 A normal network environment.
1244 Suitable for almost all networks.
1249 .It Ar set reassemble
1252 option is used to enable or disable the reassembly of fragmented packets,
1259 is also specified, fragments with the
1261 bit set are reassembled too,
1262 instead of being dropped;
1263 the reassembled packet will have the
1266 .It Ar set ruleset-optimization
1267 .Bl -tag -width xxxxxxxx -compact
1269 Enable basic ruleset optimization.
1270 This is the default behaviour.
1271 Basic ruleset optimization does four things to improve the
1272 performance of ruleset evaluations:
1276 remove duplicate rules
1278 remove rules that are a subset of another rule
1280 combine multiple rules into a table when advantageous
1282 re-order the rules to improve evaluation performance
1285 Disable the ruleset optimizer.
1287 Uses the currently loaded ruleset as a feedback profile to tailor the
1288 ordering of quick rules to actual network traffic.
1291 It is important to note that the ruleset optimizer will modify the ruleset
1292 to improve performance.
1293 A side effect of the ruleset modification is that per-rule accounting
1294 statistics will have different meanings than before.
1295 If per-rule accounting is important for billing purposes or whatnot,
1296 either the ruleset optimizer should not be used or a label field should
1297 be added to all of the accounting rules to act as optimization barriers.
1299 Optimization can also be set as a command-line argument to
1301 overriding the settings in
1303 .It Ar set skip on Aq Ar ifspec
1304 List interfaces for which packets should not be filtered.
1305 Packets passing in or out on such interfaces are passed as if pf was
1306 disabled, i.e. pf does not process them in any way.
1307 This can be useful on loopback and other virtual interfaces, when
1308 packet filtering is not desired and can have unexpected effects.
1310 is only evaluated when the ruleset is loaded; interfaces created
1311 later will not be skipped.
1312 .It Ar set state-defaults
1315 option sets the state options for states created from rules
1320 .Dl set state-defaults pflow, no-sync
1321 .It Ar set state-policy
1324 option sets the default behaviour for states:
1326 .Bl -tag -width if-bound -compact
1328 States are bound to an interface.
1330 States can match packets on any interfaces (the default).
1333 .Bl -tag -width "src.track" -compact
1335 Seconds before an unassembled fragment is expired.
1337 Interval between purging expired states and fragments.
1339 Length of time to retain a source tracking entry after the last state
1343 When a packet matches a stateful connection, the seconds to live for the
1344 connection will be updated to that of the
1345 protocol and modifier
1346 which corresponds to the connection state.
1347 Each packet which matches this state will reset the TTL.
1348 Tuning these values may improve the performance of the
1349 firewall at the risk of dropping valid idle connections.
1351 .Bl -tag -width Ds -compact
1353 The state after one endpoint sends an RST.
1355 The state after the first FIN has been sent.
1356 .It Ar tcp.established
1357 The fully established state.
1359 The state after both FINs have been exchanged and the connection is closed.
1360 Some hosts (notably web servers on Solaris) send TCP packets even after closing
1366 can prevent blocking of such packets.
1368 The state after the first packet.
1370 The state after the second packet but before both endpoints have
1371 acknowledged the connection.
1374 ICMP and UDP are handled in a fashion similar to TCP, but with a much more
1375 limited set of states:
1377 .Bl -tag -width Ds -compact
1379 The state after an ICMP error came back in response to an ICMP packet.
1381 The state after the first packet.
1383 The state after the first packet.
1385 The state if both hosts have sent packets.
1387 The state if the source host sends more than one packet but the destination
1388 host has never sent one back.
1391 Other protocols are handled similarly to UDP:
1393 .Bl -tag -width xxxx -compact
1395 .It Ar other.multiple
1399 Timeout values can be reduced adaptively as the number of state table
1402 .Bl -tag -width Ds -compact
1404 When reaching this number of state entries, all timeout values become
1405 zero, effectively purging all state entries immediately.
1406 This value is used to define the scale factor; it should not actually
1407 be reached (set a lower state limit, see below).
1408 .It Ar adaptive.start
1409 When the number of state entries exceeds this value, adaptive scaling
1411 All timeout values are scaled linearly with factor
1412 (adaptive.end \- number of states) / (adaptive.end \- adaptive.start).
1415 Adaptive timeouts are enabled by default, with an adaptive.start value
1416 equal to 60% of the state limit, and an adaptive.end value equal to
1417 120% of the state limit.
1418 They can be disabled by setting both adaptive.start and adaptive.end to 0.
1420 The adaptive timeout values can be defined both globally and for each rule.
1421 When used on a per-rule basis, the values relate to the number of
1422 states created by the rule, otherwise to the total number of
1426 .Bd -literal -offset indent
1427 set timeout tcp.first 120
1428 set timeout tcp.established 86400
1429 set timeout { adaptive.start 6000, adaptive.end 12000 }
1430 set limit states 10000
1433 With 9000 state table entries, the timeout values are scaled to 50%
1434 (tcp.first 60, tcp.established 43200).
1437 Packets can be assigned to queues for the purpose of bandwidth
1439 At least two declarations are required to configure queues, and later
1440 any packet filtering rule can reference the defined queues by name.
1441 During the filtering component of
1445 name is where any packets from
1447 rules will be queued, while for
1449 rules it specifies where any resulting ICMP or TCP RST
1450 packets should be queued.
1453 defines the algorithm used to decide which packets get delayed, dropped, or
1454 sent out immediately.
1455 There are three schedulers currently supported:
1456 .Bl -tag -width xxxx
1458 Class Based Queueing.
1459 Queues attached to an interface build a tree,
1460 thus each queue can have further child queues.
1461 Each queue can have a
1466 Priority mainly controls the time packets take to get sent out,
1467 while bandwidth has primarily effects on throughput.
1469 achieves both partitioning and sharing of link bandwidth
1470 by hierarchically structured classes.
1471 Each class has its own queue
1472 and is assigned its share of bandwidth.
1473 A child class can borrow bandwidth from its parent class
1474 as long as excess bandwidth is available
1479 Hierarchical Fair Service Curve.
1480 Queues attached to an interface build a tree,
1481 thus each queue can have further child queues.
1482 Each queue can have a
1487 Priority mainly controls the time packets take to get sent out,
1488 while bandwidth primarily affects throughput.
1490 supports both link-sharing and guaranteed real-time services.
1491 It employs a service curve based QoS model,
1492 and its unique feature is an ability to decouple
1493 delay and bandwidth allocation.
1496 Queues are flat attached to the interface,
1497 thus queues cannot have further child queues.
1498 Each queue has a unique
1500 assigned, ranging from 0 to 15.
1501 Packets in the queue with the highest priority are processed first.
1504 The interfaces on which queueing should be activated are declared using
1509 has the following keywords:
1510 .Bl -tag -width xxxx
1512 Queueing is enabled on the named interface.
1514 Specifies which queueing scheduler to use.
1515 .It Ar bandwidth Aq Ar bw
1516 The maximum bitrate for all queues on an
1517 interface may be specified using the
1520 The value can be specified as an absolute value or as a
1521 percentage of the interface bandwidth.
1522 When using an absolute value, the suffixes
1528 are used to represent bits, kilobits, megabits, and
1529 gigabits per second, respectively.
1530 The value must not exceed the interface bandwidth.
1533 is not specified, the interface bandwidth is used
1534 (but take note that some interfaces do not know their bandwidth,
1535 or can adapt their bandwidth rates).
1536 .It Ar qlimit Aq Ar limit
1537 The maximum number of packets held in the queue.
1539 .It Ar tbrsize Aq Ar size
1540 Adjusts the size, in bytes, of the token bucket regulator.
1541 If not specified, heuristics based on the
1542 interface bandwidth are used to determine the size.
1543 .It Ar queue Aq Ar list
1544 Defines a list of subqueues to create on an interface.
1547 In the following example, the interface dc0
1548 should queue up to 5Mbps in four second-level queues using
1549 Class Based Queueing.
1550 Those four queues will be shown in a later example.
1551 .Bd -literal -offset indent
1552 altq on dc0 cbq bandwidth 5Mb queue { std, http, mail, ssh }
1555 Once interfaces are activated for queueing using the
1557 directive, a sequence of
1559 directives may be defined.
1560 The name associated with a queue
1561 must match a queue defined in the altq
1562 directive or, except for the
1564 scheduler, in a parent queue declaration.
1565 The following keywords can be used:
1566 .Bl -tag -width xxxx
1567 .It Ar on Aq Ar interface
1568 Specifies the interface the queue operates on.
1569 If not given, it operates on all matching interfaces.
1570 .It Ar bandwidth Aq Ar bw
1571 Specifies the maximum bitrate to be processed by the queue.
1572 This value must not exceed the value of the parent
1574 and can be specified as an absolute value or a percentage of the parent
1576 If not specified, defaults to 100% of the parent queue's bandwidth.
1579 scheduler does not support bandwidth specification.
1580 .It Ar priority Aq Ar level
1581 Between queues a priority level can be set.
1586 the range is 0 to 7 and for
1588 the range is 0 to 15.
1589 The default for all is 1.
1591 queues with a higher priority are always served first.
1595 queues with a higher priority are preferred in the case of overload.
1596 .It Ar qlimit Aq Ar limit
1597 The maximum number of packets held in the queue.
1601 The scheduler can specify additional parameters using the format
1602 .Ar scheduler Ns Pq Ar parameters .
1606 Packets not matched by another queue are assigned to this one.
1607 Exactly one default queue is required.
1609 Enables Explicit Congestion Notification (ECN) on this queue.
1612 Enables Random Early Detection (RED) on this queue.
1613 RED drops packets with a probability proportional to the average
1619 scheduler supports an additional option:
1621 .Bl -tag -width "upperlimit XXXXXXX" -compact -offset 3n
1623 The queue can borrow bandwidth from the parent.
1628 scheduler supports some additional options:
1630 .Bl -tag -width "upperlimit XXXXXXX" -compact -offset 3n
1631 .It Ar linkshare Aq Ar sc
1632 The bandwidth share of a backlogged queue.
1633 .It Ar realtime Aq Ar sc
1634 The minimum required bandwidth for the queue.
1635 .It Ar upperlimit Aq Ar sc
1636 The maximum allowed bandwidth for the queue.
1640 is an abbreviation for
1643 The format for service curve specifications is
1644 .Ar ( m1 , d , m2 ) .
1646 controls the bandwidth assigned to the queue.
1650 are optional and can be used to control the initial bandwidth assignment.
1653 milliseconds the queue gets the bandwidth given as
1655 afterwards the value given in
1662 child queues can be specified as in an
1664 declaration, thus building a tree of queues using a part of
1665 their parent's bandwidth.
1667 Packets can be assigned to queues based on filter rules by using the
1672 is specified; when a second one is specified it will instead be used for
1673 packets which have a TOS of
1675 and for TCP ACKs with no data payload.
1677 To continue the previous example, the examples below would specify the
1679 queues, plus a few child queues.
1682 sessions get priority over bulk transfers like
1686 The queues may then be referenced by filtering rules (see
1687 .Sx PACKET FILTERING ,
1689 .Bd -literal -offset 4n
1690 queue std bandwidth 10% cbq(default)
1691 queue http bandwidth 60% priority 2 cbq(borrow red) \e
1692 { employees, developers }
1693 queue developers bandwidth 75% cbq(borrow)
1694 queue employees bandwidth 15%
1695 queue mail bandwidth 10% priority 0 cbq(borrow ecn)
1696 queue ssh bandwidth 20% cbq(borrow) { ssh_interactive, ssh_bulk }
1697 queue ssh_interactive bandwidth 50% priority 7 cbq(borrow)
1698 queue ssh_bulk bandwidth 50% priority 0 cbq(borrow)
1700 block return out on dc0 inet all set queue std
1701 pass out on dc0 inet proto tcp from $developerhosts to any port 80 \e
1702 set queue developers
1703 pass out on dc0 inet proto tcp from $employeehosts to any port 80 \e
1705 pass out on dc0 inet proto tcp from any to any port 22 \e
1706 set queue(ssh_bulk, ssh_interactive)
1707 pass out on dc0 inet proto tcp from any to any port 25 \e
1711 Tables are named structures which can hold a collection of addresses and
1713 Lookups against tables in
1715 are relatively fast, making a single rule with tables much more efficient,
1717 processor usage and memory consumption, than a large number of rules which
1718 differ only in IP address (either created explicitly or automatically by rule
1721 Tables can be used as the source or destination of filter
1722 or translation rules.
1723 They can also be used for the redirect address of
1727 and in the routing options of filter rules, but only for
1733 Tables can be defined with any of the following
1736 As with macros, reserved words may not be used as table names.
1737 .Bl -tag -width "manually"
1739 Persistent tables can be manually created with the
1745 before or after the ruleset has been loaded.
1747 Table definitions can be placed directly in this file and loaded at the
1748 same time as other rules are loaded, atomically.
1749 Table definitions inside
1753 statement, and are especially useful to define non-persistent tables.
1754 The contents of a pre-existing table defined without a list of addresses
1755 to initialize it is not altered when
1758 A table initialized with the empty list,
1760 will be cleared on load.
1763 Tables may be defined with the following attributes:
1764 .Bl -tag -width persist
1768 flag prevents the user from altering the contents of the table once it
1772 can be used to add or remove addresses from the table at any time, even
1779 flag enables per-address packet and byte counters, which can be displayed with
1784 flag forces the kernel to keep the table even when no rules refer to it.
1785 If the flag is not set, the kernel will automatically remove the table
1786 when the last rule referring to it is flushed.
1790 creates a table called private,
1791 to hold RFC 1918 private network blocks,
1792 and a table called badhosts,
1793 which is initially empty.
1794 A filter rule is set up to block all traffic coming from addresses listed in
1796 .Bd -literal -offset indent
1797 table \*(Ltprivate\*(Gt const { 10/8, 172.16/12, 192.168/16 }
1798 table \*(Ltbadhosts\*(Gt persist
1799 block on fxp0 from { \*(Ltprivate\*(Gt, \*(Ltbadhosts\*(Gt } to any
1802 The private table cannot have its contents changed and the badhosts table
1803 will exist even when no active filter rules reference it.
1804 Addresses may later be added to the badhosts table, so that traffic from
1805 these hosts can be blocked by using the following:
1807 .Dl # pfctl -t badhosts -Tadd 204.92.77.111
1809 A table can also be initialized with an address list specified in one or more
1810 external files, using the following syntax:
1811 .Bd -literal -offset indent
1812 table \*(Ltspam\*(Gt persist file "/etc/spammers" file "/etc/openrelays"
1813 block on fxp0 from \*(Ltspam\*(Gt to any
1820 list IP addresses, one per line.
1821 Any lines beginning with a
1823 are treated as comments and ignored.
1824 In addition to being specified by IP address, hosts may also be
1825 specified by their hostname.
1826 When the resolver is called to add a hostname to a table,
1828 resulting IPv4 and IPv6 addresses are placed into the table.
1829 IP addresses can also be entered in a table by specifying a valid interface
1830 name, a valid interface group, or the
1832 keyword, in which case all addresses assigned to the interface(s) will be
1835 Besides the main ruleset,
1840 An anchor is a container that can hold rules,
1841 address tables, and other anchors.
1842 When evaluation of the main ruleset reaches an
1846 will proceed to evaluate all rules specified in that anchor.
1848 The following example blocks all packets on the external interface by default,
1849 then evaluates all rules in the anchor named "spam",
1850 and finally passes all outgoing connections and
1851 incoming connections to port 25:
1852 .Bd -literal -offset indent
1854 block on $ext_if all
1856 pass out on $ext_if all
1857 pass in on $ext_if proto tcp from any to $ext_if port smtp
1860 Anchors can be manipulated through
1862 without reloading the main ruleset or other anchors.
1863 This loads a single rule into the anchor,
1864 which blocks all packets from a specific address:
1865 .Bd -literal -offset indent
1866 # echo "block in quick from 1.2.3.4 to any" | pfctl -a spam -f -
1869 The anchor can also be populated by adding a
1871 rule after the anchor rule.
1876 it will also load all the rules from the file
1877 .Pa /etc/pf-spam.conf
1879 .Bd -literal -offset indent
1881 load anchor spam from "/etc/pf-spam.conf"
1884 Filter rule anchors can also be loaded inline in the ruleset
1885 within a brace-delimited block.
1886 Brace delimited blocks may contain rules or other brace-delimited blocks.
1887 When anchors are loaded this way the anchor name becomes optional.
1888 Since the parser specification for anchor names is a string,
1889 double quote characters
1891 should be placed around the anchor name.
1892 .Bd -literal -offset indent
1893 anchor "external" on egress {
1896 pass proto tcp from any to port { 25, 80, 443 }
1898 pass in proto tcp to any port 22
1902 Anchor rules can also specify packet filtering parameters
1903 using the same syntax as filter rules.
1904 When parameters are used,
1905 the anchor rule is only evaluated for matching packets.
1906 This allows conditional evaluation of anchors, like:
1907 .Bd -literal -offset indent
1908 block on $ext_if all
1909 anchor spam proto tcp from any to any port smtp
1910 pass out on $ext_if all
1911 pass in on $ext_if proto tcp from any to $ext_if port smtp
1914 The rules inside anchor "spam" are only evaluated
1915 for TCP packets with destination port 25.
1916 Hence, the following
1917 will only block connections from 1.2.3.4 to port 25:
1918 .Bd -literal -offset indent
1919 # echo "block in quick from 1.2.3.4 to any" | pfctl -a spam -f -
1922 Matching filter and translation rules marked with the
1924 option are final and abort the evaluation of the rules in other
1925 anchors and the main ruleset.
1926 If the anchor itself is marked with the
1929 ruleset evaluation will terminate when the anchor is exited if the packet is
1930 matched by any rule within the anchor.
1932 An anchor references other anchor attachment points
1933 using the following syntax:
1934 .Bl -tag -width xxxx
1935 .It Ar anchor Aq Ar name
1936 Evaluates the filter rules in the specified anchor.
1939 An anchor has a name which specifies the path where
1941 can be used to access the anchor to perform operations on it, such as
1942 attaching child anchors to it or loading rules into it.
1943 Anchors may be nested, with components separated by
1945 characters, similar to how file system hierarchies are laid out.
1946 The main ruleset is actually the default anchor, so filter and
1947 translation rules, for example, may also be contained in any anchor.
1949 Anchor rules are evaluated relative to the anchor in which they are contained.
1951 all anchor rules specified in the main ruleset will reference
1952 anchor attachment points underneath the main ruleset,
1953 and anchor rules specified in a file loaded from a
1955 rule will be attached under that anchor point.
1957 Anchors may end with the asterisk
1959 character, which signifies that all anchors attached at that point
1960 should be evaluated in the alphabetical ordering of their anchor name.
1963 will evaluate each rule in each anchor attached to the "spam" anchor:
1964 .Bd -literal -offset indent
1968 Note that it will only evaluate anchors that are directly attached to the
1969 "spam" anchor, and will not descend to evaluate anchors recursively.
1971 Since anchors are evaluated relative to the anchor in which they are
1972 contained, there is a mechanism for accessing the parent and ancestor
1973 anchors of a given anchor.
1974 Similar to file system path name resolution, if the sequence
1976 appears as an anchor path component, the parent anchor of the current
1977 anchor in the path evaluation at that point will become the new current
1979 As an example, consider the following:
1980 .Bd -literal -offset indent
1981 # printf 'anchor "spam/allowed"\en' | pfctl -f -
1982 # printf 'anchor "../banned"\enpass\en' | pfctl -a spam/allowed -f -
1985 Evaluation of the main ruleset will lead into the
1986 spam/allowed anchor, which will evaluate the rules in the
1987 spam/banned anchor, if any, before finally evaluating the
1990 .Sh STATEFUL FILTERING
1992 filters packets statefully,
1993 which has several advantages.
1994 For TCP connections, comparing a packet to a state involves checking
1995 its sequence numbers, as well as TCP timestamps if a rule using the
1997 parameter applies to the connection.
1998 If these values are outside the narrow windows of expected
1999 values, the packet is dropped.
2000 This prevents spoofing attacks, such as when an attacker sends packets with
2001 a fake source address/port but does not know the connection's sequence
2005 knows how to match ICMP replies to states.
2007 to allow echo requests (such as those created by
2009 out statefully and match incoming echo replies correctly to states:
2011 .Dl pass out inet proto icmp all icmp-type echoreq
2013 Also, looking up states is usually faster than evaluating rules.
2014 If there are 50 rules, all of them are evaluated sequentially in O(n).
2015 Even with 50000 states, only 16 comparisons are needed to match a
2016 state, since states are stored in a binary search tree that allows
2017 searches in O(log2 n).
2019 Furthermore, correct handling of ICMP error messages is critical to
2020 many protocols, particularly TCP.
2022 matches ICMP error messages to the correct connection, checks them against
2023 connection parameters, and passes them if appropriate.
2024 For example if an ICMP source quench message referring to a stateful TCP
2025 connection arrives, it will be matched to the state and get passed.
2027 Finally, state tracking is required for
2031 options, in order to track address and port translations and reverse the
2032 translation on returning packets.
2035 will also create state for other protocols which are effectively stateless by
2037 UDP packets are matched to states using only host addresses and ports,
2038 and other protocols are matched to states using only the host addresses.
2040 If stateless filtering of individual packets is desired,
2043 keyword can be used to specify that state will not be created
2044 if this is the last matching rule.
2045 Note that packets which match neither block nor pass rules,
2046 and thus are passed by default,
2047 are effectively passed as if
2051 A number of parameters can also be set to affect how
2053 handles state tracking,
2055 .Ss State Modulation
2056 Much of the security derived from TCP is attributable to how well the
2057 initial sequence numbers (ISNs) are chosen.
2058 Some popular stack implementations choose
2060 poor ISNs and thus are normally susceptible to ISN prediction exploits.
2063 rule to a TCP connection,
2065 will create a high quality random sequence number for each connection
2070 directive implicitly keeps state on the rule and is
2071 only applicable to TCP connections.
2074 .Bd -literal -offset indent
2076 pass out proto tcp from any to any modulate state
2077 pass in proto tcp from any to any port 25 flags S/SFRA \e
2081 Note that modulated connections will not recover when the state table
2082 is lost (firewall reboot, flushing the state table, etc.).
2084 will not be able to infer a connection again after the state table flushes
2085 the connection's modulator.
2086 When the state is lost, the connection may be left dangling until the
2087 respective endpoints time out the connection.
2088 It is possible on a fast local network for the endpoints to start an ACK
2089 storm while trying to resynchronize after the loss of the modulator.
2092 settings (or a more strict equivalent) should be used on
2094 rules to prevent ACK storms.
2096 Note that alternative methods are available
2097 to prevent loss of the state table
2098 and allow for firewall failover.
2103 for further information.
2107 passes packets that are part of a
2108 TCP handshake between the endpoints.
2111 option can be used to cause
2113 itself to complete the handshake with the active endpoint, perform a handshake
2114 with the passive endpoint, and then forward packets between the endpoints.
2116 No packets are sent to the passive endpoint before the active endpoint has
2117 completed the handshake, hence so-called SYN floods with spoofed source
2118 addresses will not reach the passive endpoint, as the sender can't complete the
2121 The proxy is transparent to both endpoints; they each see a single
2122 connection from/to the other endpoint.
2124 chooses random initial sequence numbers for both handshakes.
2125 Once the handshakes are completed, the sequence number modulators
2126 (see previous section) are used to translate further packets of the
2130 .Ar modulate state .
2140 .Bd -literal -offset indent
2141 pass in proto tcp from any to any port www synproxy state
2143 .Ss Stateful Tracking Options
2144 A number of options related to stateful tracking can be applied on a
2148 .Ar modulate state ,
2151 must be specified explicitly to apply these options to a rule.
2153 .Bl -tag -width xxxx -compact
2155 States can match packets on any interfaces
2158 This is the default.
2160 States are bound to an interface
2163 .It Ar max Aq Ar number
2164 Limits the number of concurrent states the rule may create.
2165 When this limit is reached, further packets that would create
2166 state are dropped until existing states time out.
2168 Prevent state changes for states created by this rule from appearing on the
2172 States created by this rule are exported on the
2176 Uses a sloppy TCP connection tracker that does not check sequence
2177 numbers at all, which makes insertion and ICMP teardown attacks way
2179 This is intended to be used in situations where one does not see all
2180 packets of a connection, e.g. in asymmetric routing situations.
2181 It cannot be used with
2184 .Ar synproxy state .
2185 .It Xo Aq Ar timeout
2188 Changes the timeout values used for states created by this rule.
2189 For a list of all valid timeout names, see
2194 Multiple options can be specified, separated by commas:
2195 .Bd -literal -offset indent
2196 pass in proto tcp from any to any \e
2197 port www keep state \e
2198 (max 100, source-track rule, max-src-nodes 75, \e
2199 max-src-states 3, tcp.established 60, tcp.closing 5)
2204 keyword is specified, the number of states per source IP is tracked.
2206 .Bl -tag -width xxxx -compact
2207 .It Ar source-track global
2208 The number of states created by all rules that use this option is limited.
2209 Each rule can specify different
2213 options, however state entries created by any participating rule count towards
2214 each individual rule's limits.
2215 .It Ar source-track rule
2216 The maximum number of states created by this rule is limited by the rule's
2221 Only state entries created by this particular rule count toward the rule's
2225 The following limits can be set:
2227 .Bl -tag -width xxxx -compact
2228 .It Ar max-src-nodes Aq Ar number
2229 Limits the maximum number of source addresses which can simultaneously
2230 have state table entries.
2231 .It Ar max-src-states Aq Ar number
2232 Limits the maximum number of simultaneous state entries that a single
2233 source address can create with this rule.
2236 For stateful TCP connections, limits on established connections (connections
2237 which have completed the TCP 3-way handshake) can also be enforced
2240 .Bl -tag -width xxxx -compact
2241 .It Ar max-src-conn Aq Ar number
2242 Limits the maximum number of simultaneous TCP connections which have
2243 completed the 3-way handshake that a single host can make.
2244 .It Xo Ar max-src-conn-rate Aq Ar number
2247 Limit the rate of new connections over a time interval.
2248 The connection rate is an approximation calculated as a moving average.
2251 When one of these limits is reached, further packets that would create
2252 state are dropped until existing states time out.
2254 Because the 3-way handshake ensures that the source address is not being
2255 spoofed, more aggressive action can be taken based on these limits.
2257 .Ar overload Aq Ar table
2258 state option, source IP addresses which hit either of the limits on
2259 established connections will be added to the named table.
2260 This table can be used in the ruleset to block further activity from
2261 the offending host, redirect it to a tarpit process, or restrict its
2266 keyword kills all states created by the matching rule which originate
2267 from the host which exceeds these limits.
2270 modifier to the flush command kills all states originating from the
2271 offending host, regardless of which rule created the state.
2273 For example, the following rules will protect the webserver against
2274 hosts making more than 100 connections in 10 seconds.
2275 Any host which connects faster than this rate will have its address added
2278 table and have all states originating from it flushed.
2279 Any new packets arriving from this host will be dropped unconditionally
2281 .Bd -literal -offset indent
2282 block quick from \*(Ltbad_hosts\*(Gt
2283 pass in on $ext_if proto tcp to $webserver port www keep state \e
2284 (max-src-conn-rate 100/10, overload \*(Ltbad_hosts\*(Gt flush global)
2286 .Sh TRAFFIC NORMALISATION
2287 Traffic normalisation is a broad umbrella term
2288 for aspects of the packet filter which deal with
2289 verifying packets, packet fragments, spoof traffic,
2290 and other irregularities.
2292 Scrub involves sanitising packet content in such a way
2293 that there are no ambiguities in packet interpretation on the receiving side.
2294 It is invoked with the
2296 option, added to regular rules.
2298 Parameters are specified enclosed in parentheses.
2299 At least one of the following parameters must be specified:
2300 .Bl -tag -width xxxx
2301 .It Ar max-mss Aq Ar number
2302 Enforces a maximum segment size (MSS) for matching TCP packets.
2303 .It Ar min-ttl Aq Ar number
2304 Enforces a minimum TTL for matching IP packets.
2308 bit from a matching IPv4 packet.
2309 Some operating systems have NFS implementations
2310 which are known to generate fragmented packets with the
2314 will drop such fragmented
2320 Unfortunately some operating systems also generate their
2322 packets with a zero IP identification field.
2325 bit on packets with a zero IP ID may cause deleterious results if an
2326 upstream router later fragments the packet.
2329 is recommended in combination with
2331 to ensure unique IP identifiers.
2333 Replaces the IPv4 identification field with random values to compensate
2334 for predictable values generated by many hosts.
2335 This option only applies to packets that are not fragmented
2336 after the optional fragment reassembly.
2337 .It Ar reassemble tcp
2338 Statefully normalises TCP connections.
2340 performs the following normalisations:
2343 Neither side of the connection is allowed to reduce their IP TTL.
2344 An attacker may send a packet such that it reaches the firewall, affects
2345 the firewall state, and expires before reaching the destination host.
2347 will raise the TTL of all packets back up to the highest value seen on
2349 .It Timestamp Modulation
2350 Modern TCP stacks will send a timestamp on every TCP packet and echo
2351 the other endpoint's timestamp back to them.
2352 Many operating systems will merely start the timestamp at zero when
2353 first booted, and increment it several times a second.
2354 The uptime of the host can be deduced by reading the timestamp and multiplying
2356 Also observing several different timestamps can be used to count hosts
2357 behind a NAT device.
2358 And spoofing TCP packets into a connection requires knowing or guessing
2360 Timestamps merely need to be monotonically increasing and not derived off a
2361 guessable base time.
2365 to modulate the TCP timestamps with a random number.
2366 .It Extended PAWS Checks
2367 There is a problem with TCP on long fat pipes, in that a packet might get
2368 delayed for longer than it takes the connection to wrap its 32-bit sequence
2370 In such an occurrence, the old packet would be indistinguishable from a
2371 new packet and would be accepted as such.
2372 The solution to this is called PAWS: Protection Against Wrapped Sequence
2374 It protects against it by making sure the timestamp on each packet does
2377 also makes sure the timestamp on the packet does not go forward more
2378 than the RFC allows.
2381 artificially extends the security of TCP sequence numbers by 10 to 18
2382 bits when the host uses appropriately randomized timestamps, since a
2383 blind attacker would have to guess the timestamp as well.
2389 .Dl match in all scrub (no-df max-mss 1440)
2390 .Ss Fragment Handling
2391 The size of IP datagrams (packets) can be significantly larger than the
2392 maximum transmission unit (MTU) of the network.
2393 In cases when it is necessary or more efficient to send such large packets,
2394 the large packet will be fragmented into many smaller packets that will each
2396 Unfortunately for a firewalling device, only the first logical fragment will
2397 contain the necessary header information for the subprotocol that allows
2399 to filter on things such as TCP ports or to perform NAT.
2401 One alternative is to filter individual fragments with filter rules.
2402 If packet reassembly is turned off, it is passed to the filter.
2403 Filter rules with matching IP header parameters decide whether the
2404 fragment is passed or blocked, in the same way as complete packets
2406 Without reassembly, fragments can only be filtered based on IP header
2407 fields (source/destination address, protocol), since subprotocol header
2408 fields are not available (TCP/UDP port numbers, ICMP code/type).
2411 option can be used to restrict filter rules to apply only to
2412 fragments, but not complete packets.
2413 Filter rules without the
2415 option still apply to fragments, if they only specify IP header fields.
2417 .Bd -literal -offset indent
2418 pass in proto tcp from any to any port 80
2421 The rule above never applies to a fragment,
2422 even if the fragment is part of a TCP packet with destination port 80,
2423 because without reassembly this information
2424 is not available for each fragment.
2425 This also means that fragments cannot create new or match existing
2426 state table entries, which makes stateful filtering and address
2427 translation (NAT, redirection) for fragments impossible.
2429 In most cases, the benefits of reassembly outweigh the additional
2431 so reassembly is on by default.
2433 The memory allocated for fragment caching can be limited using
2435 Once this limit is reached, fragments that would have to be cached
2436 are dropped until other entries time out.
2437 The timeout value can also be adjusted.
2439 When forwarding reassembled IPv6 packets, pf refragments them with
2440 the original maximum fragment size.
2441 This allows the sender to determine the optimal fragment size by
2443 .Ss Blocking Spoofed Traffic
2444 Spoofing is the faking of IP addresses,
2445 typically for malicious purposes.
2448 directive expands to a set of filter rules which will block all
2449 traffic with a source IP from the network(s) directly connected
2450 to the specified interface(s) from entering the system through
2451 any other interface.
2454 .Dl antispoof for lo0
2457 .Bd -literal -offset indent -compact
2458 block drop in on ! lo0 inet from 127.0.0.1/8 to any
2459 block drop in on ! lo0 inet6 from ::1 to any
2462 For non-loopback interfaces, there are additional rules to block incoming
2463 packets with a source IP address identical to the interface's IP(s).
2464 For example, assuming the interface wi0 had an IP address of 10.0.0.1 and a
2465 netmask of 255.255.255.0:
2467 .Dl antispoof for wi0 inet
2470 .Bd -literal -offset indent -compact
2471 block drop in on ! wi0 inet from 10.0.0.0/24 to any
2472 block drop in inet from 10.0.0.1 to any
2475 Caveat: Rules created by the
2477 directive interfere with packets sent over loopback interfaces
2479 One should pass these explicitly.
2480 .Sh OPERATING SYSTEM FINGERPRINTING
2481 Passive OS fingerprinting is a mechanism to inspect nuances of a TCP
2482 connection's initial SYN packet and guess at the host's operating system.
2483 Unfortunately these nuances are easily spoofed by an attacker so the
2484 fingerprint is not useful in making security decisions.
2485 But the fingerprint is typically accurate enough to make policy decisions
2488 The fingerprints may be specified by operating system class, by
2489 version, or by subtype/patchlevel.
2490 The class of an operating system is typically the vendor or genre
2496 The version of the oldest available
2498 release on the main FTP site
2499 would be 2.6 and the fingerprint would be written as:
2501 .Dl \&"OpenBSD 2.6\&"
2503 The subtype of an operating system is typically used to describe the
2504 patchlevel if that patch led to changes in the TCP stack behavior.
2507 the only subtype is for a fingerprint that was
2510 scrub option and would be specified as:
2512 .Dl \&"OpenBSD 3.3 no-df\&"
2514 Fingerprints for most popular operating systems are provided by
2518 is running, a complete list of known operating system fingerprints may
2519 be listed by running:
2523 Filter rules can enforce policy at any level of operating system specification
2524 assuming a fingerprint is present.
2525 Policy could limit traffic to approved operating systems or even ban traffic
2526 from hosts that aren't at the latest service pack.
2530 class can also be used as the fingerprint which will match packets for
2531 which no operating system fingerprint is known.
2534 .Bd -literal -offset indent
2535 pass out proto tcp from any os OpenBSD
2536 block out proto tcp from any os Doors
2537 block out proto tcp from any os "Doors PT"
2538 block out proto tcp from any os "Doors PT SP3"
2539 block out from any os "unknown"
2540 pass on lo0 proto tcp from any os "OpenBSD 3.3 lo0"
2543 Operating system fingerprinting is limited only to the TCP SYN packet.
2544 This means that it will not work on other protocols and will not match
2545 a currently established connection.
2547 Caveat: operating system fingerprints are occasionally wrong.
2548 There are three problems: an attacker can trivially craft his packets to
2549 appear as any operating system he chooses;
2550 an operating system patch could change the stack behavior and no fingerprints
2551 will match it until the database is updated;
2552 and multiple operating systems may have the same fingerprint.
2555 the external interface is kue0.
2556 We use a macro for the interface name, so it can be changed easily.
2557 All incoming traffic is "normalised",
2558 and everything is blocked and logged by default.
2559 .Bd -literal -offset 4n
2561 match in all scrub (no-df max-mss 1440)
2562 block return log on $ext_if all
2565 Here we specifically block packets we don't want:
2566 anything coming from source we have no back routes for;
2567 packets whose ingress interface does not match the one in
2568 the route back to their source address;
2569 anything that does not have our address (157.161.48.183) as source;
2570 broadcasts (cable modem noise);
2571 and anything from reserved address space or invalid addresses.
2572 .Bd -literal -offset 4n
2573 block in from no-route to any
2574 block in from urpf-failed to any
2575 block out log quick on $ext_if from ! 157.161.48.183 to any
2576 block in quick on $ext_if from any to 255.255.255.255
2577 block in log quick on $ext_if from { 10.0.0.0/8, 172.16.0.0/12, \e
2578 192.168.0.0/16, 255.255.255.255/32 } to any
2582 pass out/in ping queries.
2583 State matching is done on host addresses and ICMP ID (not type/code),
2584 so replies (like 0/0 for 8/0) will match queries.
2585 ICMP error messages (which always refer to a TCP/UDP packet)
2586 are handled by the TCP/UDP states.
2587 .Bd -literal -offset 4n
2588 pass on $ext_if inet proto icmp all icmp-type 8 code 0
2592 pass out all UDP connections.
2593 DNS connections are passed in.
2594 .Bd -literal -offset 4n
2595 pass out on $ext_if proto udp all
2596 pass in on $ext_if proto udp from any to any port domain
2600 pass out all TCP connections and modulate state.
2601 SSH, SMTP, DNS, and IDENT connections are passed in.
2602 We do not allow Windows 9x SMTP connections since they are typically
2604 .Bd -literal -offset 4n
2605 pass out on $ext_if proto tcp all modulate state
2606 pass in on $ext_if proto tcp from any to any \e
2607 port { ssh, smtp, domain, auth }
2608 block in on $ext_if proto tcp from any \e
2609 os { "Windows 95", "Windows 98" } to any port smtp
2612 Here we pass in/out all IPv6 traffic:
2613 note that we have to enable this in two different ways,
2614 on both our physical interface and our tunnel.
2615 .Bd -literal -offset 4n
2616 pass quick on gif0 inet6
2617 pass quick on $ext_if proto ipv6
2620 This example illustrates packet tagging.
2621 There are three interfaces: $int_if, $ext_if, and $wifi_if (wireless).
2622 NAT is being done on $ext_if for all outgoing packets.
2623 Packets in on $int_if are tagged and passed out on $ext_if.
2624 All other outgoing packets
2625 (i.e. packets from the wireless network)
2626 are only permitted to access port 80.
2627 .Bd -literal -offset 4n
2628 pass in on $int_if from any to any tag INTNET
2629 pass in on $wifi_if from any to any
2631 block out on $ext_if from any to any
2632 pass out quick on $ext_if tagged INTNET
2633 pass out on $ext_if proto tcp from any to any port 80
2637 we tag incoming packets as they are redirected to spamd(8).
2638 The tag is used to pass those packets through the packet filter.
2639 .Bd -literal -offset 4n
2640 match in on $ext_if inet proto tcp from \*(Ltspammers\*(Gt to port smtp \e
2641 tag SPAMD rdr-to 127.0.0.1 port spamd
2644 pass in on $ext_if inet proto tcp tagged SPAMD
2647 This example maps incoming requests on port 80 to port 8080, on
2648 which a daemon is running (because, for example, it is not run as root,
2649 and therefore lacks permission to bind to port 80).
2650 .Bd -literal -offset 4n
2651 match in on $ext_if proto tcp from any to any port 80 \e
2652 rdr-to 127.0.0.1 port 8080
2657 rule is used with the
2659 modifier, packets matching the translation rule are passed without
2660 inspecting subsequent filter rules.
2661 .Bd -literal -offset 4n
2662 pass in quick on $ext_if proto tcp from any to any port 80 \e
2663 rdr-to 127.0.0.1 port 8080
2666 In the example below, vlan12 is configured as 192.168.168.1;
2667 the machine translates all packets coming from 192.168.168.0/24 to 204.92.77.111
2668 when they are going out any interface except vlan12.
2669 This has the net effect of making traffic from the 192.168.168.0/24
2670 network appear as though it is the Internet routable address
2671 204.92.77.111 to nodes behind any interface on the router except
2672 for the nodes on vlan12.
2673 Thus, 192.168.168.1 can talk to the 192.168.168.0/24 nodes.
2674 .Bd -literal -offset 4n
2675 match out on ! vlan12 from 192.168.168.0/24 to any nat-to 204.92.77.111
2678 In the example below, the machine sits between a fake internal
2679 144.19.74.* network, and a routable external IP of 204.92.77.100.
2680 The last rule excludes protocol AH from being translated.
2681 .Bd -literal -offset 4n
2682 pass out on $ext_if from 144.19.74.0/24 nat-to 204.92.77.100
2683 pass out on $ext_if proto ah from 144.19.74.0/24
2686 In the example below, packets bound for one specific server, as well as those
2687 generated by the sysadmins are not proxied; all other connections are.
2688 .Bd -literal -offset 4n
2689 pass in on $int_if proto { tcp, udp } from any to any port 80 \e
2690 rdr-to 127.0.0.1 port 80
2691 pass in on $int_if proto { tcp, udp } from any to $server port 80
2692 pass in on $int_if proto { tcp, udp } from $sysadmins to any port 80
2695 This example maps outgoing packets' source port
2696 to an assigned proxy port instead of an arbitrary port.
2697 In this case, proxy outgoing isakmp with port 500 on the gateway.
2698 .Bd -literal -offset 4n
2699 match out on $ext_if inet proto udp from any port isakmp to any \e
2700 nat-to ($ext_if) port 500
2703 One more example uses
2705 to redirect a TCP and UDP port to an internal machine.
2706 .Bd -literal -offset 4n
2707 match in on $ext_if inet proto tcp from any to ($ext_if) port 8080 \e
2708 rdr-to 10.1.2.151 port 22
2709 match in on $ext_if inet proto udp from any to ($ext_if) port 8080 \e
2710 rdr-to 10.1.2.151 port 53
2713 In this example, a NAT gateway is set up to translate internal addresses
2714 using a pool of public addresses (192.0.2.16/28).
2715 A given source address is always translated to the same pool address by
2716 using the source-hash keyword.
2717 The gateway also translates incoming web server connections
2718 to a group of web servers on the internal network.
2719 .Bd -literal -offset 4n
2720 match out on $ext_if inet from any to any nat-to 192.0.2.16/28 \e
2722 match in on $ext_if proto tcp from any to any port 80 \e
2723 rdr-to { 10.1.2.155 weight 2, 10.1.2.160 weight 1, \e
2724 10.1.2.161 weight 8 } round-robin
2727 The bidirectional address translation example uses a single
2729 rule that expands to a
2734 .Bd -literal -offset 4n
2735 pass on $ext_if from 10.1.2.120 to any binat-to 192.0.2.17
2738 The previous example is identical to the following set of rules:
2739 .Bd -literal -offset 4n
2740 pass out on $ext_if inet from 10.1.2.120 to any \e
2741 nat-to 192.0.2.17 static-port
2742 pass in on $ext_if inet from any to 192.0.2.17 rdr-to 10.1.2.120
2745 In the example below, a router handling both address families
2746 translates an internal IPv4 subnet to IPv6 using the well-known
2747 64:ff9b::/96 prefix:
2748 .Bd -literal -offset 4n
2749 pass in on $v4_if inet af-to inet6 from ($v6_if) to 64:ff9b::/96
2752 Paired with the example above, the example below can be used on
2753 another router handling both address families to translate back
2755 .Bd -literal -offset 4n
2756 pass in on $v6_if inet6 to 64:ff9b::/96 af-to inet from ($v4_if)
2763 line = ( option | pf-rule |
2764 antispoof-rule | altq-rule | queue-rule | anchor-rule |
2765 anchor-close | load-anchor | table-rule | include )
2767 option = "set" ( [ "timeout" ( timeout | "{" timeout-list "}" ) ] |
2768 [ "ruleset-optimization" [ "none" | "basic" |
2770 [ "optimization" [ "default" | "normal" | "high-latency" |
2771 "satellite" | "aggressive" | "conservative" ] ]
2772 [ "limit" ( limit-item | "{" limit-list "}" ) ] |
2773 [ "loginterface" ( interface-name | "none" ) ] |
2774 [ "block-policy" ( "drop" | "return" ) ] |
2775 [ "state-policy" ( "if-bound" | "floating" ) ]
2776 [ "state-defaults" state-opts ]
2777 [ "fingerprints" filename ] |
2778 [ "skip on" ifspec ] |
2779 [ "debug" ( "none" | "urgent" | "misc" | "loud" ) ] |
2780 [ "reassemble" ( "yes" | "no" ) [ "no-df" ] ] )
2782 pf-rule = action [ ( "in" | "out" ) ]
2783 [ "log" [ "(" logopts ")"] ] [ "quick" ]
2784 [ "on" ( ifspec | "rdomain" number ) ] [ af ]
2785 [ protospec ] hosts [ filteropts ]
2787 logopts = logopt [ [ "," ] logopts ]
2788 logopt = "all" | "matches" | "user" | "to" interface-name
2790 filteropts = filteropt [ [ "," ] filteropts ]
2791 filteropt = user | group | flags | icmp-type | icmp6-type |
2793 ( "no" | "keep" | "modulate" | "synproxy" ) "state"
2794 [ "(" state-opts ")" ] | "scrub" "(" scrubopts ")" |
2795 "fragment" | "allow-opts" | "once" |
2796 "divert-packet" "port" port | "divert-reply" |
2797 "divert-to" host "port" port |
2798 "label" string | "tag" string | [ ! ] "tagged" string |
2799 "set prio" ( number | "(" number [ [ "," ] number ] ")" ) |
2800 "set queue" ( string | "(" string [ [ "," ] string ] ")" ) |
2801 "rtable" number | "probability" number"%" |
2802 "af-to" af "from" ( redirhost | "{" redirhost-list "}" )
2803 [ "to" ( redirhost | "{" redirhost-list "}" ) ] |
2804 "binat-to" ( redirhost | "{" redirhost-list "}" )
2805 [ portspec ] [ pooltype ] |
2806 "rdr-to" ( redirhost | "{" redirhost-list "}" )
2807 [ portspec ] [ pooltype ] |
2808 "nat-to" ( redirhost | "{" redirhost-list "}" )
2809 [ portspec ] [ pooltype ] [ "static-port" ] |
2810 [ route ] | [ "set tos" tos ] |
2811 [ "received-on" ( interface-name | interface-group ) ]
2813 scrubopts = scrubopt [ [ "," ] scrubopts ]
2814 scrubopt = "no-df" | "min-ttl" number | "max-mss" number |
2815 "reassemble tcp" | "random-id"
2817 antispoof-rule = "antispoof" [ "log" ] [ "quick" ]
2818 "for" ifspec [ af ] [ "label" string ]
2820 table-rule = "table" "\*(Lt" string "\*(Gt" [ tableopts ]
2821 tableopts = tableopt [ tableopts ]
2822 tableopt = "persist" | "const" | "counters" |
2823 "file" string | "{" [ tableaddrs ] "}"
2824 tableaddrs = tableaddr-spec [ [ "," ] tableaddrs ]
2825 tableaddr-spec = [ "!" ] tableaddr [ "/" mask-bits ]
2826 tableaddr = hostname | ifspec | "self" |
2827 ipv4-dotted-quad | ipv6-coloned-hex
2829 altq-rule = "altq on" interface-name queueopts-list
2831 queue-rule = "queue" string [ "on" interface-name ] queueopts-list
2834 anchor-rule = "anchor" [ string ] [ ( "in" | "out" ) ] [ "on" ifspec ]
2835 [ af ] [ protospec ] [ hosts ] [ filteropt-list ] [ "{" ]
2839 load-anchor = "load anchor" string "from" filename
2841 queueopts-list = queueopts-list queueopts | queueopts
2842 queueopts = [ "bandwidth" bandwidth-spec ] |
2843 [ "qlimit" number ] | [ "tbrsize" number ] |
2844 [ "priority" number ] | [ schedulers ]
2845 schedulers = ( cbq-def | priq-def | hfsc-def )
2846 bandwidth-spec = "number" ( "b" | "Kb" | "Mb" | "Gb" | "%" )
2848 action = "pass" | "match" | "block" [ return ]
2849 return = "drop" | "return" |
2850 "return-rst" [ "(" "ttl" number ")" ] |
2851 "return-icmp" [ "(" icmpcode [ [ "," ] icmp6code ] ")" ] |
2852 "return-icmp6" [ "(" icmp6code ")" ]
2853 icmpcode = ( icmp-code-name | icmp-code-number )
2854 icmp6code = ( icmp6-code-name | icmp6-code-number )
2856 ifspec = ( [ "!" ] ( interface-name | interface-group ) ) |
2857 "{" interface-list "}"
2858 interface-list = [ "!" ] ( interface-name | interface-group )
2859 [ [ "," ] interface-list ]
2860 route = ( "route-to" | "reply-to" | "dup-to" )
2861 ( routehost | "{" routehost-list "}" )
2863 af = "inet" | "inet6"
2865 protospec = "proto" ( proto-name | proto-number |
2866 "{" proto-list "}" )
2867 proto-list = ( proto-name | proto-number ) [ [ "," ] proto-list ]
2870 "from" ( "any" | "no-route" | "urpf-failed" | "self" |
2871 host | "{" host-list "}" | "route" string ) [ port ]
2873 "to" ( "any" | "no-route" | "self" | host |
2874 "{" host-list "}" | "route" string ) [ port ]
2876 ipspec = "any" | host | "{" host-list "}"
2877 host = [ "!" ] ( address [ "weight" number ] |
2878 address [ "/" mask-bits ] [ "weight" number ] |
2879 "\*(Lt" string "\*(Gt" )
2880 redirhost = address [ "/" mask-bits ]
2881 routehost = host | host "@" interface-name |
2882 "(" interface-name [ address [ "/" mask-bits ] ] ")"
2883 address = ( interface-name | interface-group |
2884 "(" ( interface-name | interface-group ) ")" |
2885 hostname | ipv4-dotted-quad | ipv6-coloned-hex )
2886 host-list = host [ [ "," ] host-list ]
2887 redirhost-list = redirhost [ [ "," ] redirhost-list ]
2888 routehost-list = routehost [ [ "," ] routehost-list ]
2890 port = "port" ( unary-op | binary-op | "{" op-list "}" )
2891 portspec = "port" ( number | name ) [ ":" ( "*" | number | name ) ]
2892 os = "os" ( os-name | "{" os-list "}" )
2893 user = "user" ( unary-op | binary-op | "{" op-list "}" )
2894 group = "group" ( unary-op | binary-op | "{" op-list "}" )
2896 unary-op = [ "=" | "!=" | "\*(Lt" | "\*(Le" | "\*(Gt" | "\*(Ge" ]
2898 binary-op = number ( "\*(Lt\*(Gt" | "\*(Gt\*(Lt" | ":" ) number
2899 op-list = ( unary-op | binary-op ) [ [ "," ] op-list ]
2901 os-name = operating-system-name
2902 os-list = os-name [ [ "," ] os-list ]
2904 flags = "flags" ( [ flag-set ] "/" flag-set | "any" )
2905 flag-set = [ "F" ] [ "S" ] [ "R" ] [ "P" ] [ "A" ] [ "U" ] [ "E" ]
2908 icmp-type = "icmp-type" ( icmp-type-code | "{" icmp-list "}" )
2909 icmp6-type = "icmp6-type" ( icmp-type-code | "{" icmp-list "}" )
2910 icmp-type-code = ( icmp-type-name | icmp-type-number )
2911 [ "code" ( icmp-code-name | icmp-code-number ) ]
2912 icmp-list = icmp-type-code [ [ "," ] icmp-list ]
2914 tos = ( "lowdelay" | "throughput" | "reliability" |
2917 state-opts = state-opt [ [ "," ] state-opts ]
2918 state-opt = ( "max" number | "no-sync" | timeout | "sloppy" |
2919 "pflow" | "source-track" [ ( "rule" | "global" ) ] |
2920 "max-src-nodes" number | "max-src-states" number |
2921 "max-src-conn" number |
2922 "max-src-conn-rate" number "/" number |
2923 "overload" "\*(Lt" string "\*(Gt" [ "flush" [ "global" ] ] |
2924 "if-bound" | "floating" )
2926 timeout-list = timeout [ [ "," ] timeout-list ]
2927 timeout = ( "tcp.first" | "tcp.opening" | "tcp.established" |
2928 "tcp.closing" | "tcp.finwait" | "tcp.closed" |
2929 "udp.first" | "udp.single" | "udp.multiple" |
2930 "icmp.first" | "icmp.error" |
2931 "other.first" | "other.single" | "other.multiple" |
2932 "frag" | "interval" | "src.track" |
2933 "adaptive.start" | "adaptive.end" ) number
2935 limit-list = limit-item [ [ "," ] limit-list ]
2936 limit-item = ( "states" | "frags" | "src-nodes" | "tables" |
2937 "table-entries" ) number
2939 pooltype = ( "bitmask" | "least-states" |
2940 "random" | "round-robin" |
2941 "source-hash" [ ( hex-key | string-key ) ] )
2944 subqueue = string | "{" queue-list "}"
2945 queue-list = string [ [ "," ] string ]
2946 cbq-def = "cbq" [ "(" cbq-opt [ [ "," ] cbq-opt ] ")" ]
2947 priq-def = "priq" [ "(" priq-opt [ [ "," ] priq-opt ] ")" ]
2948 hfsc-def = "hfsc" [ "(" hfsc-opt [ [ "," ] hfsc-opt ] ")" ]
2949 cbq-opt = ( "default" | "borrow" | "red" | "ecn" )
2950 priq-opt = ( "default" | "red" | "ecn" )
2951 hfsc-opt = ( "default" | "red" | "ecn" |
2952 linkshare-sc | realtime-sc | upperlimit-sc )
2953 linkshare-sc = "linkshare" sc-spec
2954 realtime-sc = "realtime" sc-spec
2955 upperlimit-sc = "upperlimit" sc-spec
2956 sc-spec = ( bandwidth-spec |
2957 "(" bandwidth-spec number bandwidth-spec ")" )
2958 include = "include" filename
2961 .Bl -tag -width "/etc/protocolsXXX" -compact
2965 Default location of the ruleset file.
2967 Default location of OS fingerprints.
2968 .It Pa /etc/protocols
2969 Protocol name database.
2970 .It Pa /etc/services
2971 Service name database.
2983 file format first appeared in