2 .\" $FreeBSD: src/sbin/ipfw/ipfw.8,v 1.63.2.33 2003/02/04 01:36:02 brueffer Exp $
3 .\" $DragonFly: src/sbin/ipfw/ipfw.8,v 1.20 2008/11/23 21:55:52 swildner Exp $
10 .Nd IP firewall and traffic shaper control program
25 .Brq Cm delete | zero | resetlog
30 .Brq Cm firewall | one_pass | debug | verbose | dyn_keepalive
33 .Brq Cm firewall | one_pass | debug | verbose | dyn_keepalive
36 .Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
40 .Ar number Cm to Ar number
42 .Cm set swap Ar number number
54 .Brq Cm delete | list | show
59 .Cm table Ar number Cm create
97 .Ar macro Ns Op = Ns Ar value
105 utility is the user interface for controlling the
111 .Bd -ragged -offset XXXX
113 this manual page documents the newer version of
117 CURRENT in July 2002, also known as
120 is a superset of the old firewall,
122 The differences between the two are listed in Section
123 .Sx IPFW2 ENHANCEMENTS ,
124 which you are encouraged to read to revise older rulesets and possibly
125 write them more efficiently.
134 numbered from 1 to 65535.
135 Packets are passed to
137 from a number of different places in the protocol stack
138 (depending on the source and destination of the packet,
141 is invoked multiple times on the same packet).
142 The packet passed to the firewall is compared
143 against each of the rules in the firewall
145 When a match is found, the action corresponding to the
146 matching rule is performed.
148 Depending on the action and certain system settings, packets
149 can be reinjected into the firewall at some rule after the
150 matching one for further processing.
154 ruleset always includes a
156 rule (numbered 65535) which cannot be modified,
157 and matches all packets.
158 The action associated with the
164 depending on how the kernel is configured.
166 If the ruleset includes one or more rules with the
174 behaviour, i.e. upon a match it will create states matching
175 the exact parameters (addresses and ports) of the matching packet.
177 These states, which have a limited lifetime, are checked
178 at the first occurrence of a
183 rule, and are typically used to open the firewall on-demand to
184 legitimate traffic only.
186 .Sx STATEFUL FIREWALL
189 Sections below for more information on the stateful behaviour of
192 All rules (including states) have a few associated counters:
193 a packet count, a byte count, a log count and a timestamp
194 indicating the time of the last match.
195 Counters can be displayed or reset with
199 Rules can be added with the
201 command; deleted individually or in groups with the
203 command, and globally with the
205 command; displayed, optionally with the content of the
211 Finally, counters can be reset with the
217 Also, each rule belongs to one of 32 different
221 commands to atomically manipulate sets, such as enable,
222 disable, swap sets, move all rules in a set to another
223 one, delete all rules in a set. These can be useful to
224 install temporary configurations, or to test them.
227 for more information on
230 The following options are available:
231 .Bl -tag -width indent
233 While listing, show counter values.
236 command just implies this option.
238 When entering or showing rules, print them in compact form,
239 i.e. without the optional "ip from any to any" string
240 when this does not carry any additional information.
242 While listing, show states and tracks in addition to static ones.
244 While listing, if the
246 option was specified, also show expired states and tracks.
248 Don't ask for confirmation for commands that can cause problems
251 If there is no tty associated with the process, this is implied.
253 Try to resolve addresses and service names in output.
261 be quiet about actions
264 This is useful for adjusting rules by executing multiple
268 .Ql sh\ /etc/rc.firewall ) ,
269 or by processing a file of many
271 rules across a remote login session.
274 is performed in normal (verbose) mode (with the default kernel
275 configuration), it prints a message.
276 Because all rules are flushed, the message might not be delivered
277 to the login session, causing the remote login session to be closed
278 and the remainder of the ruleset to not be processed.
279 Access to the console would then be required to recover.
281 While listing rules, show the
283 each rule belongs to.
284 If this flag is not specified, disabled rules will not be
287 While listing pipes, sort according to one of the four
288 counters (total or current packets or bytes).
290 While listing, show last match timestamp.
293 To ease configuration, rules can be put into a file which is
296 as shown in the last synopsis line.
300 The file will be read line by line and applied as arguments to the
304 Optionally, a preprocessor can be specified using
308 is to be piped through.
309 Useful preprocessors include
315 doesn't start with a slash
317 as its first character, the usual
319 name search is performed.
320 Care should be taken with this in environments where not all
321 file systems are mounted (yet) by the time
323 is being run (e.g. when they are mounted over NFS).
326 has been specified, optional
330 specifications can follow and will be passed on to the preprocessor.
331 This allows for flexible configuration files (like conditionalizing
332 them on the local hostname) and the use of macros to centralize
333 frequently required arguments like IP addresses.
340 commands are used to configure the traffic shaper, as shown in the
341 .Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
344 If the world and the kernel get out of sync the
346 ABI may break, preventing you from being able to add any rules. This can
347 adversely affect the booting process. You can use
351 to temporarily disable the firewall to regain access to the network,
352 allowing you to fix the problem.
354 A packet is checked against the active ruleset in multiple places
355 in the protocol stack, under control of several sysctl variables.
356 These places and variables are shown below, and it is important to
357 have this picture in mind in order to design a correct ruleset.
358 .Bd -literal -offset indent
361 +------------>------------+
363 [ip_input] [ip_output] net.inet.ip.fw.enable=1
366 [ether_demux_oncpu] [ether_output_frame] net.link.ether.ipfw=1
371 As can be noted from the above picture, the number of
372 times the same packet goes through the firewall can
373 vary between 0 and 4 depending on packet source and
374 destination, and system configuration.
376 Note that as packets flow through the stack, headers can be
377 stripped or added to it, and so they may or may not be available
379 E.g., incoming packets will include the MAC header when
382 .Fn ether_demux_oncpu ,
383 but the same packets will have the MAC header stripped off when
388 Also note that each packet is always checked against the complete ruleset,
389 irrespective of the place where the check occurs, or the source of the packet.
390 If a rule contains some match patterns or actions which are not valid
391 for the place of invocation (e.g. trying to match a MAC header within
393 the match pattern will not match, but a
395 operator in front of such patterns
399 match on those packets.
400 It is thus the responsibility of
401 the programmer, if necessary, to write a suitable ruleset to
402 differentiate among the possible places.
404 rules can be useful here, as an example:
405 .Bd -literal -offset indent
406 # packets from ether_demux_oncpu
407 ipfw add 10 skipto 1000 all from any to any layer2 in
408 # packets from ip_input
409 ipfw add 10 skipto 2000 all from any to any not layer2 in
410 # packets from ip_output
411 ipfw add 10 skipto 3000 all from any to any not layer2 out
412 # packets from ether_output_frame
413 ipfw add 10 skipto 4000 all from any to any layer2 out
418 rules is the following:
419 .Bd -ragged -offset indent
421 .Op Cm set Ar set_number
422 .Op Cm prob Ar match_probability
425 .Op Cm log Op Cm logamount Ar number
429 where the body of the rule specifies which information is used
430 for filtering packets, among the following:
432 .Bl -tag -width "Source and dest. addresses and ports" -offset XXX -compact
433 .It Layer-2 header fields
437 .It Source and dest. addresses and ports
441 .It Transmit and receive interface
443 .It Misc. IP header fields
444 Version, type of service, datagram length, identification,
448 .It Misc. TCP header fields
449 TCP flags (SYN, FIN, ACK, RST, etc.),
450 sequence number, acknowledgment number,
456 When the packet can be associated with a local socket.
459 Note that some of the above information, e.g. source MAC or IP addresses and
460 TCP/UDP ports, could easily be spoofed, so filtering on those fields
461 alone might not guarantee the desired results.
462 .Bl -tag -width indent
464 Each rule is associated with a
466 in the range 1..65535, with the latter reserved for the
469 Rules are checked sequentially by rule number.
470 Multiple rules can have the same number, in which case they are
471 checked (and listed) according to the order in which they have
473 If a rule is entered without specifying a number, the kernel will
474 assign one in such a way that the rule becomes the last one
478 Automatic rule numbers are assigned by incrementing the last
479 non-default rule number by the value of the sysctl variable
480 .Ar net.inet.ip.fw.autoinc_step
481 which defaults to 100.
482 If this is not possible (e.g. because we would go beyond the
483 maximum allowed rule number), the number of the last
484 non-default value is used instead.
485 .It Cm set Ar set_number
486 Each rule is associated with a
488 in the range 0..31, with the latter reserved for the
491 Sets can be individually disabled and enabled, so this parameter
492 is of fundamental importance for atomic ruleset manipulation.
493 It can be also used to simplify deletion of groups of rules.
494 If a rule is entered without specifying a set number,
496 .It Cm prob Ar match_probability
497 A match is only declared with the specified probability
498 (floating point number between 0 and 1).
499 This can be useful for a number of applications such as
500 random packet drop or
503 to simulate the effect of multiple paths leading to out-of-order
505 .It Cm log Op Cm logamount Ar number
506 When a packet matches a rule with the
508 keyword, a message will be
514 The logging only occurs if the sysctl variable
515 .Em net.inet.ip.fw.verbose
517 (which is the default when the kernel is compiled with
518 .Dv IPFIREWALL_VERBOSE )
519 and the number of packets logged so far for that
520 particular rule does not exceed the
525 is specified, the limit is taken from the sysctl variable
526 .Em net.inet.ip.fw.verbose_limit .
527 In both cases, a value of 0 removes the logging limit.
529 Once the limit is reached, logging can be re-enabled by
530 clearing the logging counter or the packet counter for that entry, see the
535 A rule can be associated with one of the following actions, which
536 will be executed when the packet matches the body of the rule.
537 .Bl -tag -width indent
538 .It Cm allow | accept | pass | permit
539 Allow packets that match rule.
540 The search terminates.
542 Checks the packet against the state table.
543 If a match is found, execute the action associated with
544 the rule which generated this state, otherwise
545 move to the next rule.
548 rules do not have a body.
551 rule is found, the state table is checked at the first
557 Update counters for all packets that match rule.
558 The search continues with the next rule.
560 Reassemble IP fragments.
561 If an IP packet was reassembled,
562 the reassembled IP packet would be passed to the next rule for further
564 This action only applies to IP fragments received by
566 The most common way to use this action is like this:
568 .Dl "ipfw add defrag ip from any to any"
570 It is recommended to reassemble IP fragments before
574 or any layer 4 protocols filtering,
581 Discard packets that match this rule.
582 The search terminates.
583 .It Cm divert Ar port
584 Divert packets that match this rule to the
588 The search terminates.
589 .It Cm fwd | forward Ar ipaddr Ns Op , Ns Ar port
590 Change the next-hop on matching packets to
592 which can be an IP address in dotted quad format or a host name.
593 The search terminates if this rule matches.
597 is a local address, then matching packets will be forwarded to
599 (or the port number in the packet if one is not specified in the rule)
600 on the local machine.
604 is not a local address, then the port number
605 (if specified) is ignored, and the packet will be
606 forwarded to the remote address, using the route as found in
607 the local routing table for that IP.
611 rule will not match layer-2 packets (those received
619 action does not change the contents of the packet at all.
620 In particular, the destination address remains unmodified, so
621 packets forwarded to another system will usually be rejected by that system
622 unless there is a matching rule on that system to capture them.
623 For packets forwarded locally,
624 the local address of the socket will be
625 set to the original destination address of the packet.
628 entry look rather weird but is intended for
629 use with transparent proxy servers.
630 .It Cm pipe Ar pipe_nr
634 (for bandwidth limitation, delay, etc.).
636 .Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
637 Section for further information.
638 The search terminates; however, on exit from the pipe and if
642 .Em net.inet.ip.fw.one_pass
643 is not set, the packet is passed again to the firewall code
644 starting from the next rule.
645 .It Cm queue Ar queue_nr
649 (for bandwidth limitation using WF2Q+).
655 Discard packets that match this rule, and if the
656 packet is a TCP packet, try to send a TCP reset (RST) notice.
657 The search terminates.
658 .It Cm skipto Ar number
659 Skip all subsequent rules numbered less than
661 The search continues with the first rule numbered
665 Send a copy of packets matching this rule to the
669 The search terminates and the original packet is accepted
673 .It Cm unreach Ar code
674 Discard packets that match this rule, and try to send an ICMP
675 unreachable notice with code
679 is a number from 0 to 255, or one of these aliases:
680 .Cm net , host , protocol , port ,
681 .Cm needfrag , srcfail , net-unknown , host-unknown ,
682 .Cm isolated , net-prohib , host-prohib , tosnet ,
683 .Cm toshost , filter-prohib , host-precedence
685 .Cm precedence-cutoff .
686 The search terminates.
689 The body of a rule contains zero or more patterns (such as
690 specific source and destination addresses or ports,
691 protocol options, incoming or outgoing interfaces, etc.)
692 that the packet must match in order to be recognised.
693 In general, the patterns are connected by (implicit)
695 operators -- i.e. all must match in order for the
697 Individual patterns can be prefixed by the
699 operator to reverse the result of the match, as in
701 .Dl "ipfw add 100 allow ip from not 1.2.3.4 to any"
703 Additionally, sets of alternative match patterns
705 can be constructed by putting the patterns in
706 lists enclosed between parentheses ( ) or braces { }, and
711 .Dl "ipfw add 100 allow ip from { x or not y or z } to any"
713 Only one level of parentheses is allowed.
714 Beware that most shells have special meanings for parentheses
715 or braces, so it is advisable to put a backslash \\ in front of them
716 to prevent such interpretations.
718 The body of a rule must in general include a source and destination
722 can be used in various places to specify that the content of
723 a required field is irrelevant.
725 The rule body has the following format:
726 .Bd -ragged -offset indent
727 .Op Ar proto Cm from Ar src Cm to Ar dst
731 The first part (protocol from src to dst) is for backward
736 any match pattern (including MAC headers, IPv4 protocols,
737 addresses and ports) can be specified in the
741 Rule fields have the following meaning:
742 .Bl -tag -width indent
743 .It Ar proto : protocol | Cm { Ar protocol Cm or ... }
744 An IPv4 protocol (or an
746 with multiple protocols) specified by number or name
747 (for a complete list see
748 .Pa /etc/protocols ) .
753 keywords mean any protocol will match.
754 .It Ar src No and Ar dst : ip-address | Cm { Ar ip-address Cm or ... } Op Ar ports
759 containing one or more of them,
760 optionally followed by
764 An address (or set of addresses) specified in one of the following
765 ways, optionally preceded by a
768 .Bl -tag -width indent
770 matches any IP address.
772 matches any IP address configured on an interface in the system.
773 The address list is evaluated at the time the packet is
775 .It Cm < Ns Ar number Ns Cm >
776 Matches any network or host addresses in the
780 .It Cm [ Ns Ar ifX Ns Cm ]
781 Matches the first IPv4 address assigned to the
783 It is intended to help matching the IPv4 address assigned to the
787 .It Cm [ Ns Ar ifX Ns Cm :net]
788 Matches the IPv4 network of the first IPv4 address assigned to the
790 It is intended to help matching the IPv4 network of the IPv4 address
795 .It Ar numeric-ip | hostname
796 Matches a single IPv4 address, specified as dotted-quad or a hostname.
797 Hostnames are resolved at the time the rule is added to the firewall list.
798 .It Ar addr Ns / Ns Ar masklen
799 Matches all addresses with base
801 (specified as a dotted quad or a hostname)
805 As an example, 1.2.3.4/25 will match
806 all IP numbers from 1.2.3.0 to 1.2.3.127 .
807 .It Ar addr Ns / Ns Ar masklen Ns Cm { Ns Ar num,num,... Ns Cm }
808 Matches all addresses with base address
810 (specified as a dotted quad or a hostname)
811 and whose last byte is in the list between braces { } .
812 Note that there must be no spaces between braces, commas and
816 field is used to limit the size of the set of addresses,
817 and can have any value between 24 and 32.
819 As an example, an address specified as 1.2.3.4/24{128,35,55,89}
820 will match the following IP addresses:
822 1.2.3.128 1.2.3.35 1.2.3.55 1.2.3.89 .
824 This format is particularly useful to handle sparse address sets
825 within a single rule. Because the matching occurs using a
826 bitmask, it takes constant time and dramatically reduces
827 the complexity of rulesets.
828 .It Ar addr Ns : Ns Ar mask
829 Matches all addresses with base
831 (specified as a dotted quad or a hostname)
834 specified as a dotted quad.
835 As an example, 1.2.3.4/255.0.255.0 will match
837 We suggest to use this form only for non-contiguous
838 masks, and resort to the
839 .Ar addr Ns / Ns Ar masklen
840 format for contiguous masks, which is more compact and less
843 .It Ar ports : Oo Cm not Oc Bro Ar port | port Ns \&- Ns Ar port Ns Brc Op , Ns Ar ...
844 For protocols which support port numbers (such as TCP and UDP), optional
846 may be specified as one or more ports or port ranges, separated
847 by commas but no spaces, and an optional
852 notation specifies a range of ports (including boundaries).
856 may be used instead of numeric port values.
857 The length of the port list is limited to 30 ports or ranges,
858 though one can specify larger ranges by using an
866 can be used to escape the dash
868 character in a service name (from a shell, the backslash must be
869 typed twice to avoid the shell itself interpreting it as an escape
872 .Dl "ipfw add count tcp from any ftp\e\e-data-ftp to any"
874 Fragmented packets which have a non-zero offset (i.e. not the first
875 fragment) will never match a rule which has one or more port
881 options for details on matching fragmented packets.
884 action for reassembling IP fragments.
886 .Ss RULE OPTIONS (MATCH PATTERNS)
887 Additional match patterns can be used within
888 rules. Zero or more of these so-called
890 can be present in a rule, optionally prefixed by the
892 operand, and possibly grouped into
895 The following match patterns can be used (listed in alphabetical order):
896 .Bl -tag -width indent
897 .It Cm dst-ip Ar ip-address
898 Matches IP packets whose destination IP is one of the address(es)
899 specified as argument.
900 .It Cm dst-port Ar ports
901 Matches IP packets whose destination port is one of the port(s)
902 specified as argument.
904 Matches TCP packets that have the RST or ACK bits set.
906 Matches packets that are fragments and not the first
907 fragment of an IP datagram.
908 Note that these packets will not have the next protocol header
909 (e.g. TCP, UDP) so options that look into these headers cannot match.
916 Matches all TCP or UDP packets sent by or received for a
920 may be specified by name or number.
921 .It Cm icmptypes Ar types
922 Matches ICMP packets whose ICMP type is in the list
924 The list may be specified as any combination of ranges or
925 individual types separated by commas.
926 The supported ICMP types are:
930 destination unreachable
942 time-to-live exceeded
956 and address mask reply
959 Matches incoming or outgoing packets, respectively.
963 are mutually exclusive (in fact,
969 even if it's the first fragment.
976 Matches IP packets whose
981 Matches IP packets whose total length, including header and data, is
984 .It Cm ipoptions Ar spec
985 Matches packets whose IP header contains the comma separated list of
988 The supported IP options are:
991 (strict source route),
993 (loose source route),
995 (record packet route) and
998 The absence of a particular option may be denoted
1001 .It Cm ipprecedence Ar precedence
1002 Matches IP packets whose precedence field is equal to
1004 .It Cm iptos Ar spec
1005 Matches IP packets whose
1007 field contains the comma separated list of
1008 service types specified in
1010 The supported IP types of service are:
1013 .Pq Dv IPTOS_LOWDELAY ,
1015 .Pq Dv IPTOS_THROUGHPUT ,
1017 .Pq Dv IPTOS_RELIABILITY ,
1019 .Pq Dv IPTOS_MINCOST ,
1022 The absence of a particular type may be denoted
1026 Matches IP packets whose time to live is
1028 .It Cm ipversion Ar ver
1029 Matches IP packets whose IP version field is
1032 Upon a match, the firewall will create a state, whose
1033 default behaviour is to match bidirectional traffic between
1034 source and destination IP/port using the same protocol.
1035 The rule has a limited lifetime (controlled by a set of
1037 variables), and the lifetime is refreshed every time a matching
1040 Matches only layer2 packets, i.e. those passed to
1043 .Fn ether_demux_oncpu
1045 .Fn ether_output_frame .
1046 .It Cm limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N
1047 The firewall will only allow
1049 connections with the same
1050 set of parameters as specified in the rule.
1052 of source and destination addresses and ports can be
1054 .It Cm { MAC | mac } Ar dst-mac src-mac
1055 Match packets with a given
1059 addresses, specified as the
1061 keyword (matching any MAC address), or six groups of hex digits
1062 separated by colons,
1063 and optionally followed by a mask indicating how many bits are
1066 .Dl "MAC 10:20:30:40:50:60/33 any"
1068 Note that the order of MAC addresses (destination first,
1070 the same as on the wire, but the opposite of the one used for
1072 .It Cm mac-type Ar mac-type
1073 Matches packets whose Ethernet Type field
1074 corresponds to one of those specified as argument.
1076 is specified in the same way as
1078 (i.e. one or more comma-separated single values or ranges).
1079 You can use symbolic names for known values such as
1080 .Em vlan , ipv4, ipv6 .
1081 Values can be entered as decimal or hexadecimal (if prefixed by 0x),
1082 and they are always printed as hexadecimal (unless the
1084 option is used, in which case symbolic resolution will be attempted).
1085 .It Cm proto Ar protocol
1086 Matches packets with the corresponding IPv4 protocol.
1087 .It Cm recv | xmit | via Brq Ar ifX | Ar if Ns Cm * | Ar ipno | Ar any
1088 Matches packets received, transmitted or going through,
1089 respectively, the interface specified by exact name
1093 by IP address, or through some interface.
1097 keyword causes the interface to always be checked.
1104 then only the receive or transmit interface (respectively)
1106 By specifying both, it is possible to match packets based on
1107 both receive and transmit interface, e.g.:
1109 .Dl "ipfw add deny ip from any to any out recv ed0 xmit ed1"
1113 interface can be tested on either incoming or outgoing packets,
1116 interface can only be tested on outgoing packets.
1121 is invalid) whenever
1125 A packet may not have a receive or transmit interface: packets
1126 originating from the local host have no receive interface,
1127 while packets destined for the local host have no transmit
1130 Matches TCP packets that have the SYN bit set but no ACK bit.
1131 This is the short form of
1132 .Dq Li tcpflags\ syn,!ack .
1133 .It Cm src-ip Ar ip-address
1134 Matches IP packets whose source IP is one of the address(es)
1135 specified as argument.
1136 .It Cm src-port Ar ports
1137 Matches IP packets whose source port is one of the port(s)
1138 specified as argument.
1139 .It Cm tcpack Ar ack
1141 Match if the TCP header acknowledgment number field is set to
1143 .It Cm tcpflags Ar spec
1145 Match if the TCP header contains the comma separated list of
1148 The supported TCP flags are:
1157 The absence of a particular flag may be denoted
1160 A rule which contains a
1162 specification can never match a fragmented packet which has
1168 options for details on matching fragmented packets.
1171 action for reassembling IP fragments.
1172 .It Cm tcpseq Ar seq
1174 Match if the TCP header sequence number field is set to
1176 .It Cm tcpwin Ar win
1178 Match if the TCP header window field is set to
1180 .It Cm tcpoptions Ar spec
1182 Match if the TCP header contains the comma separated list of
1183 options specified in
1185 The supported TCP options are:
1188 (maximum segment size),
1190 (tcp window advertisement),
1194 (rfc1323 timestamp) and
1196 (rfc1644 t/tcp connection count).
1197 The absence of a particular option may be denoted
1201 Match all TCP or UDP packets sent by or received for a
1205 may be matched by name or identification number.
1208 Each rule belongs to one of 32 different
1211 Set 31 is reserved for the default rule.
1213 By default, rules are put in set 0, unless you use the
1215 attribute when entering a new rule.
1216 Sets can be individually and atomically enabled or disabled,
1217 so this mechanism permits an easy way to store multiple configurations
1218 of the firewall and quickly (and atomically) switch between them.
1219 The command to enable/disable sets is
1220 .Bd -ragged -offset indent
1222 .Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
1229 sections can be specified.
1230 Command execution is atomic on all the sets specified in the command.
1231 By default, all sets are enabled.
1233 When you disable a set, its rules behave as if they do not exist
1234 in the firewall configuration, with only one exception:
1235 .Bd -ragged -offset indent
1236 states and tracks created from a rule before it had been disabled
1237 will still be active until they expire. In order to delete
1238 states and tracks you have to explicitly delete the parent rule
1239 which generated them.
1242 The set number of rules can be changed with the command
1243 .Bd -ragged -offset indent
1246 .Brq Cm rule Ar rule-number | old-set
1250 Also, you can atomically swap two rulesets with the command
1251 .Bd -ragged -offset indent
1253 .Cm set swap Ar first-set second-set
1258 Section on some possible uses of sets of rules.
1259 .Sh STATEFUL FIREWALL
1260 Stateful operation is a way for the firewall to dynamically
1261 create states and tracks for specific flows when packets that
1262 match a given pattern are detected. Support for stateful
1263 operation comes through the
1264 .Cm check-state , keep-state
1271 States are created when a packet matches a
1275 rule, causing the creation of a
1277 which will match all and only packets with
1281 .Em src-ip/src-port dst-ip/dst-port
1286 are used here only to denote the initial match addresses, but they
1287 are completely equivalent afterwards).
1289 tracks are created when a packet matches a
1292 States will be checked at the first
1293 .Cm check-state, keep-state
1296 occurrence, and the action performed upon a match will be the same
1297 as in the parent rule.
1299 Note that no additional attributes other than protocol and IP addresses
1300 and ports are checked on states.
1302 The typical use of states is to keep a closed firewall configuration,
1303 but let the first TCP SYN packet from the inside network install a
1304 state for the flow so that packets belonging to that session
1305 will be allowed through the firewall:
1307 .Dl "ipfw add check-state"
1308 .Dl "ipfw add allow tcp from my-subnet to any setup keep-state"
1309 .Dl "ipfw add deny tcp from any to any"
1311 A similar approach can be used for UDP, where an UDP packet coming
1312 from the inside will install a state to let the response through
1315 .Dl "ipfw add check-state"
1316 .Dl "ipfw add allow udp from my-subnet to any keep-state"
1317 .Dl "ipfw add deny udp from any to any"
1319 States and tracks expire after some time, which depends on the status
1320 of the flow and the setting of some
1324 .Sx SYSCTL VARIABLES
1326 For TCP sessions, states can be instructed to periodically
1327 send keepalive packets to refresh the state of the rule when it is
1332 for more examples on how to use states.
1333 .Sh TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
1335 is also the user interface for the
1340 operates by first using the firewall to classify packets and divide them into
1342 using any match pattern that can be used in
1345 Depending on local policies, a flow can contain packets for a single
1346 TCP connection, or from/to a given host, or entire subnet, or a
1349 Packets belonging to the same flow are then passed to either of two
1350 different objects, which implement the traffic regulation:
1351 .Bl -hang -offset XXXX
1353 A pipe emulates a link with given bandwidth, propagation delay,
1354 queue size and packet loss rate.
1355 Packets are queued in front of the pipe as they come out from the classifier,
1356 and then transferred to the pipe according to the pipe's parameters.
1359 is an abstraction used to implement the WF2Q+
1360 (Worst-case Fair Weighted Fair Queueing) policy, which is
1361 an efficient variant of the WFQ policy.
1363 The queue associates a
1365 and a reference pipe to each flow, and then all backlogged (i.e.,
1366 with packets queued) flows linked to the same pipe share the pipe's
1367 bandwidth proportionally to their weights.
1368 Note that weights are not priorities; a flow with a lower weight
1369 is still guaranteed to get its fraction of the bandwidth even if a
1370 flow with a higher weight is permanently backlogged.
1374 can be used to set hard limits to the bandwidth that a flow can use, whereas
1376 can be used to determine how different flow share the available bandwidth.
1382 configuration commands are the following:
1383 .Bd -ragged -offset indent
1384 .Cm pipe Ar number Cm config Ar pipe-configuration
1386 .Cm queue Ar number Cm config Ar queue-configuration
1389 The following parameters can be configured for a pipe:
1391 .Bl -tag -width indent -compact
1392 .It Cm bw Ar bandwidth
1393 Bandwidth, measured in
1396 .Brq Cm bit/s | Byte/s .
1399 A value of 0 (default) means unlimited bandwidth.
1400 The unit must immediately follow the number, as in
1402 .Dl "ipfw pipe 1 config bw 300Kbit/s"
1404 .It Cm delay Ar ms-delay
1405 Propagation delay, measured in milliseconds.
1406 The value is rounded to the next multiple of the clock tick
1407 (typically 10ms, but it is a good practice to run kernels
1409 .Cd "options HZ=1000"
1411 the granularity to 1ms or less).
1412 Default value is 0, meaning no delay.
1415 The following parameters can be configured for a queue:
1417 .Bl -tag -width indent -compact
1418 .It Cm pipe Ar pipe_nr
1419 Connects a queue to the specified pipe.
1420 Multiple queues (with the same or different weights) can be connected to
1421 the same pipe, which specifies the aggregate rate for the set of queues.
1423 .It Cm weight Ar weight
1424 Specifies the weight to be used for flows matching this queue.
1425 The weight must be in the range 1..100, and defaults to 1.
1428 Finally, the following parameters can be configured for both
1431 .Bl -tag -width XXXX -compact
1432 .It Cm buckets Ar hash-table-size
1433 Specifies the size of the hash table used for storing the
1435 Default value is 64 controlled by the
1438 .Em net.inet.ip.dummynet.hash_size ,
1439 allowed range is 16 to 65536.
1441 .It Cm mask Ar mask-specifier
1442 Packets sent to a given pipe or queue by an
1444 rule can be further classified into multiple flows, each of which is then
1448 A flow identifier is constructed by masking the IP addresses,
1449 ports and protocol types as specified with the
1451 options in the configuration of the pipe or queue.
1452 For each different flow identifier, a new pipe or queue is created
1453 with the same parameters as the original object, and matching packets
1458 are used, each flow will get the same bandwidth as defined by the pipe,
1461 are used, each flow will share the parent's pipe bandwidth evenly
1462 with other flows generated by the same queue (note that other queues
1463 with different weights might be connected to the same pipe).
1465 Available mask specifiers are a combination of one or more of the following:
1467 .Cm dst-ip Ar mask ,
1468 .Cm src-ip Ar mask ,
1469 .Cm dst-port Ar mask ,
1470 .Cm src-port Ar mask ,
1475 where the latter means all bits in all fields are significant.
1478 When a packet is dropped by a dummynet queue or pipe, the error
1479 is normally reported to the caller routine in the kernel, in the
1480 same way as it happens when a device queue fills up. Setting this
1481 option reports the packet as successfully delivered, which can be
1482 needed for some experimental setups where you want to simulate
1483 loss or congestion at a remote router.
1486 This option is always on,
1490 .It Cm plr Ar packet-loss-rate
1493 .Ar packet-loss-rate
1494 is a floating-point number between 0 and 1, with 0 meaning no
1495 loss, 1 meaning 100% loss.
1496 The loss rate is internally represented on 31 bits.
1498 .It Cm queue Brq Ar slots | size Ns Cm Kbytes
1503 Default value is 50 slots, which
1504 is the typical queue size for Ethernet devices.
1505 Note that for slow speed links you should keep the queue
1506 size short or your traffic might be affected by a significant
1508 E.g., 50 max-sized ethernet packets (1500 bytes) mean 600Kbit
1509 or 20s of queue on a 30Kbit/s pipe.
1510 Even worse effect can result if you get packets from an
1511 interface with a much larger MTU, e.g. the loopback interface
1512 with its 16KB packets.
1514 .It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p
1515 Make use of the RED (Random Early Detection) queue management algorithm.
1520 point numbers between 0 and 1 (0 not included), while
1524 are integer numbers specifying thresholds for queue management
1525 (thresholds are computed in bytes if the queue has been defined
1526 in bytes, in slots otherwise).
1529 also supports the gentle RED variant (gred).
1532 variables can be used to control the RED behaviour:
1533 .Bl -tag -width indent
1534 .It Em net.inet.ip.dummynet.red_lookup_depth
1535 specifies the accuracy in computing the average queue
1536 when the link is idle (defaults to 256, must be greater than zero)
1537 .It Em net.inet.ip.dummynet.red_avg_pkt_size
1538 specifies the expected average packet size (defaults to 512, must be
1540 .It Em net.inet.ip.dummynet.red_max_pkt_size
1541 specifies the expected maximum packet size, only used when queue
1542 thresholds are in bytes (defaults to 1500, must be greater than zero).
1546 Table provides a convenient way to support a large amount of
1547 discrete host or network addresses for the
1553 Non-existing tables never match.
1554 For network addresses,
1555 only CIDR form is supported.
1557 Tables are identified by
1559 which ranges from 0 to
1560 .Cm net.inet.ip.fw.table_max
1562 Default number of available tables is 64,
1563 i.e. valid table ids are from 0 to 63.
1564 Number of available tables can be changed by setting tunable
1565 .Cm net.inet.ip.fw.table_max .
1566 Max configurable number of available tables is 65535.
1568 Tables must be created explicitly
1569 before host or network addresses could be added to them:
1570 .Bd -ragged -offset indent
1571 .Cm table Ar number Cm create
1574 Host or network addresses can be added to an existing
1576 .Bd -ragged -offset indent
1577 .Cm table Ar number Cm add Ar address
1581 Host or network addresses can be removed from an existing
1583 .Bd -ragged -offset indent
1584 .Cm table Ar number Cm delete Ar address
1588 Addresses in a table can be flushed by:
1589 .Bd -ragged -offset indent
1590 .Cm table Ar number Cm flush
1593 Or you can optionally flush all existing tables:
1594 .Bd -ragged -offset indent
1598 Each address in a table has two counters.
1599 One records the number of usage,
1600 the other saves the time of the last match.
1601 These counters can be resetted for a specific table:
1602 .Bd -ragged -offset indent
1603 .Cm table Ar number Cm zero
1606 Or you can reset counters of addresses in all existing tables by:
1607 .Bd -ragged -offset indent
1611 Host and network addresses in the tables are not expired by the
1613 manual intervention is required to expire addresses unused in a table
1616 .Bd -ragged -offset indent
1617 .Cm table Ar number Cm expire Ar seconds
1621 you can expire all addresses that were unused within the last
1624 .Bd -ragged -offset indent
1625 .Cm table expire Ar seconds
1628 An existing table can be destroyed by:
1629 .Bd -ragged -offset indent
1630 .Cm table Ar number Cm destroy
1633 All existing tables can be listed by:
1634 .Bd -ragged -offset indent
1638 All addresses in an existing table can be dumped by:
1639 .Bd -ragged -offset indent
1641 .Brq Cm print | show
1644 Here are some important points to consider when designing your
1648 Remember that you filter both packets going
1652 Most connections need packets going in both directions.
1654 Remember to test very carefully.
1655 It is a good idea to be near the console when doing this.
1656 If you cannot be near the console,
1657 use an auto-recovery script such as the one in
1658 .Pa /usr/share/examples/ipfw/change_rules.sh .
1660 Don't forget the loopback interface.
1665 There are circumstances where fragmented datagrams are unconditionally
1667 TCP packets are dropped if they do not contain at least 20 bytes of
1668 TCP header, UDP packets are dropped if they do not contain a full 8
1669 byte UDP header, and ICMP packets are dropped if they do not contain
1670 4 bytes of ICMP header, enough to specify the ICMP type, code, and
1672 These packets are simply logged as
1674 since there may not be enough good data in the packet to produce a
1675 meaningful log entry.
1677 Another type of packet is unconditionally dropped, a TCP packet with a
1678 fragment offset of one.
1679 This is a valid packet, but it only has one use, to try
1680 to circumvent firewalls.
1681 When logging is enabled, these packets are
1682 reported as being dropped by rule -1.
1684 If you are logged in over a network, loading the
1688 is probably not as straightforward as you would think.
1689 I recommend the following command line:
1690 .Bd -literal -offset indent
1691 kldload /boot/modules/ipfw.ko && \e
1692 ipfw add 32000 allow ip from any to any
1695 Along the same lines, doing an
1696 .Bd -literal -offset indent
1700 in similar surroundings is also a bad idea.
1704 filter list may not be modified if the system security level
1705 is set to 3 or higher
1708 for information on system security levels).
1710 .Sh PACKET DIVERSION
1713 socket bound to the specified port will receive all packets
1714 diverted to that port.
1715 If no socket is bound to the destination port, or if the kernel
1716 wasn't compiled with divert socket support, the packets are
1718 .Sh SYSCTL VARIABLES
1721 variables controls the behaviour of the firewall and
1724 These are shown below together with their default value
1725 (but always check with the
1727 command what value is actually in use) and meaning:
1728 .Bl -tag -width indent
1729 .It Em net.filters_default_to_accept : No 0
1730 If set prior to loading the
1732 kernel module, the filter will default to allowing all packets through.
1733 If not set the filter will likely default to not allowing any packets through.
1734 .It Em net.inet.ip.dummynet.expire : No 1
1735 Lazily delete dynamic pipes/queue once they have no pending traffic.
1736 You can disable this by setting the variable to 0, in which case
1737 the pipes/queues will only be deleted when the threshold is reached.
1738 .It Em net.inet.ip.dummynet.hash_size : No 64
1739 Default size of the hash table used for dynamic pipes/queues.
1740 This value is used when no
1742 option is specified when configuring a pipe/queue.
1743 .It Em net.inet.ip.dummynet.max_chain_len : No 16
1744 Target value for the maximum number of pipes/queues in a hash bucket.
1746 .Cm max_chain_len*hash_size
1747 is used to determine the threshold over which empty pipes/queues
1748 will be expired even when
1749 .Cm net.inet.ip.dummynet.expire=0 .
1750 .It Em net.inet.ip.dummynet.red_lookup_depth : No 256
1751 .It Em net.inet.ip.dummynet.red_avg_pkt_size : No 512
1752 .It Em net.inet.ip.dummynet.red_max_pkt_size : No 1500
1753 Parameters used in the computations of the drop probability
1754 for the RED algorithm.
1755 .It Em net.inet.ip.fw.autoinc_step : No 100
1756 Delta between rule numbers when auto-generating them.
1757 The value must be in the range 1..1000.
1758 .It Em net.inet.ip.fw.debug : No 1
1759 Controls debugging messages produced by
1761 .It Em net.inet.ip.fw.table_max : No 64
1762 Number of available tables.
1763 This value can only be changed by setting tunable
1764 .Cm net.inet.ip.fw.table_max .
1765 .It Em net.inet.ip.fw.state_cnt : No 3
1766 Current number of states
1768 .It Em net.inet.ip.fw.state_max : No 4096
1769 Maximum number of states.
1770 When you hit this limit,
1771 no more states can be installed until old ones expire.
1772 .It Em net.inet.ip.fw.track_cnt : No 3
1773 Current number of tracks
1778 .It Em net.inet.ip.fw.track_max : No 4096
1779 Maximum number of tracks.
1780 When you hit this limit,
1781 no more tracks can be installed until old ones expire.
1782 .It Em net.inet.ip.fw.dyn_keepalive : No 1
1783 Enables generation of keepalive packets for
1785 rules on TCP sessions. A keepalive is generated to both
1786 sides of the connection every 5 seconds for the last 20
1787 seconds of the lifetime of the rule.
1788 .It Em net.inet.ip.fw.dyn_ack_lifetime : No 300
1789 .It Em net.inet.ip.fw.dyn_syn_lifetime : No 20
1790 .It Em net.inet.ip.fw.dyn_finwait_lifetime : No 20
1791 .It Em net.inet.ip.fw.dyn_fin_lifetime : No 2
1792 .It Em net.inet.ip.fw.dyn_rst_lifetime : No 2
1793 .It Em net.inet.ip.fw.dyn_udp_lifetime : No 10
1794 .It Em net.inet.ip.fw.dyn_short_lifetime : No 5
1795 These variables control the lifetime, in seconds, of states and tracks.
1796 Upon the initial SYN exchange the lifetime is kept short,
1797 then increased after both SYN have been seen, then decreased
1798 again during the final FIN exchange or when a RST is received.
1799 .It Em net.inet.ip.fw.enable : No 1
1800 Enables the firewall.
1801 Setting this variable to 0 lets you run your machine without
1802 firewall even if compiled in.
1803 .It Em net.inet.ip.fw.one_pass : No 1
1804 When set, the packet exiting from the
1806 pipe is not passed though the firewall again.
1807 Otherwise, after a pipe action, the packet is
1808 reinjected into the firewall at the next rule.
1810 Note: layer 2 packets coming out of a pipe
1811 are never reinjected in the firewall irrespective of the
1812 value of this variable.
1813 .It Em net.inet.ip.fw.verbose : No 1
1814 Enables verbose messages.
1815 .It Em net.inet.ip.fw.verbose_limit : No 0
1816 Limits the number of messages produced by a verbose firewall.
1817 .It Em net.link.ether.ipfw : No 0
1818 Controls whether layer-2 packets are passed to
1822 .Sh IPFW2 ENHANCEMENTS
1823 This Section lists the features that have been introduced in
1825 which were not present in
1827 We list them in order of the potential impact that they can
1828 have in writing your rulesets.
1829 You might want to consider using these features in order to
1830 write your rulesets in a more efficient way.
1831 .Bl -tag -width indent
1832 .It Handling of non-IPv4 packets
1834 will silently accept all non-IPv4 packets.
1836 will filter all packets (including non-IPv4 ones) according to the ruleset.
1837 To achieve the same behaviour as
1839 you can use the following as the very first rule in your ruleset:
1841 .Dl "ipfw add 1 allow layer2 not mac-type ip"
1845 option might seem redundant, but it is necessary -- packets
1846 passed to the firewall from layer3 will not have a MAC header,
1849 pattern will always fail on them, and the
1851 operator will make this rule into a pass-all.
1854 does not support address sets (those in the form
1855 .Ar addr/masklen{num,num,...} ) .
1860 .It Port specifications
1862 only allows one port range when specifying TCP and UDP ports, and
1863 is limited to 10 entries instead of the 15 allowed by
1867 you can only specify ports when the rule is requesting
1873 you can put port specifications in rules matching all packets,
1874 and the match will be attempted only on those packets carrying
1875 protocols which include port identifiers.
1879 allowed the first port entry to be specified as
1883 can be an arbitrary 16-bit mask.
1884 This syntax is of questionable usefulness and it is not
1885 supported anymore in
1889 does not support Or-blocks.
1892 does not generate keepalives for stateful sessions.
1893 As a consequence, it might cause idle sessions to drop because
1894 the lifetime of the states expires.
1897 does not implement sets of rules.
1898 .It MAC header filtering and Layer-2 firewalling.
1900 does not implement filtering on MAC header fields, nor is it
1901 invoked on packets from
1902 .Fn ether_demux_oncpu
1904 .Fn ether_output_frame .
1906 .Em net.link.ether.ipfw
1907 has no effect there.
1909 The following options are not supported in
1912 .Cm dst-ip, dst-port, layer2, mac, mac-type, src-ip, src-port.
1914 Additionally, the following options are not supported in
1919 .Cm ipid, iplen, ipprecedence, iptos, ipttl,
1920 .Cm ipversion, tcpack, tcpseq, tcpwin .
1921 .It Dummynet options
1922 The following option for
1924 pipes/queues is not supported:
1928 There are far too many possible uses of
1930 so this Section will only give a small set of examples.
1931 .Ss BASIC PACKET FILTERING
1932 This command adds an entry which denies all tcp packets from
1933 .Em cracker.evil.org
1934 to the telnet port of
1936 from being forwarded by the host:
1938 .Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet"
1940 This one disallows any connection from the entire cracker's
1943 .Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org"
1945 A first and efficient way to limit access (not using states)
1946 is the use of the following rules:
1948 .Dl "ipfw add allow tcp from any to any established"
1949 .Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup"
1950 .Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup"
1952 .Dl "ipfw add deny tcp from any to any"
1954 The first rule will be a quick match for normal TCP packets,
1955 but it will not match the initial SYN packet, which will be
1958 rules only for selected source/destination pairs.
1959 All other SYN packets will be rejected by the final
1963 If you administer one or more subnets, you can take advantage of the
1965 syntax to specify address sets and or-blocks and write extremely
1966 compact rulesets which selectively enable services to blocks
1967 of clients, as below:
1969 .Dl "goodguys=\*q{ 10.1.2.0/24{20,35,66,18} or 10.2.3.0/28{6,3,11} }\*q"
1970 .Dl "badguys=\*q10.1.2.0/24{8,38,60}\*q"
1972 .Dl "ipfw add allow ip from ${goodguys} to any"
1973 .Dl "ipfw add deny ip from ${badguys} to any"
1974 .Dl "... normal policies ..."
1978 syntax would require a separate rule for each IP in the above
1981 If you have large number of discrete addresses to block,
1982 and the number of addresses to block keep increasing,
1984 can be used as below:
1986 .Dl "... Initialize the blocked address list using table 0 ..."
1987 .Dl "ipfw table 0 create"
1988 .Dl "ipfw table 0 add 10.0.0.1 10.1.0.1 172.0.0.1"
1989 .Dl "... Block the addresses in table 0 ..."
1990 .Dl "ipfw add deny ip from <0> to any"
1991 .Dl "... Add more addresses to table 0 any time later..."
1992 .Dl "ipfw table 0 add 172.1.0.1"
1993 .Dl "... Expire the addresses unused within the last 24 hours ..."
1994 .Dl "ipfw table 0 expire 86400"
1996 In order to protect a site from flood attacks involving fake
1997 TCP packets, it is safer to use states:
1999 .Dl "ipfw add check-state"
2000 .Dl "ipfw add deny tcp from any to any established"
2001 .Dl "ipfw add allow tcp from my-net to any setup keep-state"
2003 This will let the firewall install states only for
2004 those connection which start with a regular SYN packet coming
2005 from the inside of our network.
2006 States are checked when encountering the first
2013 rule should usually be placed near the beginning of the
2014 ruleset to minimize the amount of work scanning the ruleset.
2015 Your mileage may vary.
2017 To limit the number of connections a user can open
2018 you can use the following type of rules:
2020 .Dl "ipfw add allow tcp from my-net/24 to any setup limit src-addr 10"
2021 .Dl "ipfw add allow tcp from any to me setup limit src-addr 4"
2023 The former (assuming it runs on a gateway) will allow each host
2024 on a /24 network to open at most 10 TCP connections.
2025 The latter can be placed on a server to make sure that a single
2026 client does not use more than 4 simultaneous connections.
2029 stateful rules can be subject to denial-of-service attacks
2030 by a SYN-flood which opens a huge number of states.
2031 The effects of such attacks can be partially limited by
2034 variables which control the operation of the firewall.
2036 Here is a good usage of the
2038 command to see accounting records and timestamp information:
2042 or in short form without timestamps:
2046 which is equivalent to:
2050 Next rule diverts all incoming packets from 192.168.2.0/24
2051 to divert port 5000:
2053 .Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in
2055 The following rules show some of the applications of
2059 for simulations and the like.
2061 This rule drops random incoming packets with a probability
2064 .Dl "ipfw add prob 0.05 deny ip from any to any in"
2066 A similar effect can be achieved making use of dummynet pipes:
2068 .Dl "ipfw add pipe 10 ip from any to any"
2069 .Dl "ipfw pipe 10 config plr 0.05"
2071 We can use pipes to artificially limit bandwidth, e.g. on a
2072 machine acting as a router, if we want to limit traffic from
2073 local clients on 192.168.2.0/24 we do:
2075 .Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
2076 .Dl "ipfw pipe 1 config bw 300Kbit/s queue 50KBytes"
2078 note that we use the
2080 modifier so that the rule is not used twice.
2081 Remember in fact that
2083 rules are checked both on incoming and outgoing packets.
2085 Should we want to simulate a bidirectional link with bandwidth
2086 limitations, the correct way is the following:
2088 .Dl "ipfw add pipe 1 ip from any to any out"
2089 .Dl "ipfw add pipe 2 ip from any to any in"
2090 .Dl "ipfw pipe 1 config bw 64Kbit/s queue 10Kbytes"
2091 .Dl "ipfw pipe 2 config bw 64Kbit/s queue 10Kbytes"
2093 The above can be very useful, e.g. if you want to see how
2094 your fancy Web page will look for a residential user who
2095 is connected only through a slow link.
2096 You should not use only one pipe for both directions, unless
2097 you want to simulate a half-duplex medium (e.g. AppleTalk,
2099 It is not necessary that both pipes have the same configuration,
2100 so we can also simulate asymmetric links.
2102 Should we want to verify network performance with the RED queue
2103 management algorithm:
2105 .Dl "ipfw add pipe 1 ip from any to any"
2106 .Dl "ipfw pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1"
2108 Another typical application of the traffic shaper is to
2109 introduce some delay in the communication.
2110 This can significantly affect applications which do a lot of Remote
2111 Procedure Calls, and where the round-trip-time of the
2112 connection often becomes a limiting factor much more than
2115 .Dl "ipfw add pipe 1 ip from any to any out"
2116 .Dl "ipfw add pipe 2 ip from any to any in"
2117 .Dl "ipfw pipe 1 config delay 250ms bw 1Mbit/s"
2118 .Dl "ipfw pipe 2 config delay 250ms bw 1Mbit/s"
2120 Per-flow queueing can be useful for a variety of purposes.
2121 A very simple one is counting traffic:
2123 .Dl "ipfw add pipe 1 tcp from any to any"
2124 .Dl "ipfw add pipe 1 udp from any to any"
2125 .Dl "ipfw add pipe 1 ip from any to any"
2126 .Dl "ipfw pipe 1 config mask all"
2128 The above set of rules will create queues (and collect
2129 statistics) for all traffic.
2130 Because the pipes have no limitations, the only effect is
2131 collecting statistics.
2132 Note that we need 3 rules, not just the last one, because
2135 tries to match IP packets it will not consider ports, so we
2136 would not see connections on separate ports as different
2139 A more sophisticated example is limiting the outbound traffic
2140 on a net with per-host limits, rather than per-network limits:
2142 .Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
2143 .Dl "ipfw add pipe 2 ip from any to 192.168.2.0/24 in"
2144 .Dl "ipfw pipe 1 config mask src-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
2145 .Dl "ipfw pipe 2 config mask dst-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
2147 To add a set of rules atomically, e.g. set 18:
2149 .Dl "ipfw disable set 18"
2150 .Dl "ipfw add NN set 18 ... # repeat as needed"
2151 .Dl "ipfw enable set 18"
2153 To delete a set of rules atomically the command is simply:
2155 .Dl "ipfw delete set 18"
2157 To test a ruleset and disable it and regain control if something goes wrong:
2159 .Dl "ipfw disable set 18"
2160 .Dl "ipfw add NN set 18 ... # repeat as needed"
2161 .Dl "ipfw enable set 18 ; echo done; sleep 30 && ipfw disable set 18"
2163 Here if everything goes well, you press control-C before the "sleep"
2164 terminates, and your ruleset will be left active. Otherwise, e.g. if
2165 you cannot access your box, the ruleset will be disabled after
2166 the sleep terminates thus restoring the previous situation.
2184 utility first appeared in
2189 Stateful extensions were introduced in
2191 and were rewritten in
2193 Table was introduced in
2196 was introduced in Summer 2002.
2198 .An Ugen J. S. Antsilevich ,
2199 .An Poul-Henning Kamp ,
2205 API based upon code written by
2211 traffic shaper supported by Akamba Corp.
2213 The syntax has grown over the years and sometimes it might be confusing.
2214 Unfortunately, backward compatibility prevents cleaning up mistakes
2215 made in the definition of the syntax.
2219 Misconfiguring the firewall can put your computer in an unusable state,
2220 possibly shutting down network services and requiring console access to
2221 regain control of it.
2223 Incoming packet fragments diverted by
2227 are reassembled before delivery to the socket.
2228 The action used on those packet is the one from the
2229 rule which matches the first fragment of the packet.
2231 Packets that match a
2233 rule should not be immediately accepted, but should continue
2234 going through the rule list.
2235 This may be fixed in a later version.
2237 Packets diverted to userland, and then reinserted by a userland process
2240 will lose various packet attributes, including their source interface.
2241 If a packet is reinserted in this manner, later rules may be incorrectly
2242 applied, making the order of
2244 rules in the rule sequence very important.