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
175 behaviour, i.e. upon a match it will create states matching
176 the exact parameters (addresses and ports) of the matching packet.
178 These states, which have a limited lifetime, are checked
179 at the first occurrence of a
185 rule, and are typically used to open the firewall on-demand to
186 legitimate traffic only.
188 .Sx STATEFUL FIREWALL
191 Sections below for more information on the stateful behaviour of
194 All rules (including states) have a few associated counters:
195 a packet count, a byte count, a log count and a timestamp
196 indicating the time of the last match.
197 Counters can be displayed or reset with
201 Rules can be added with the
203 command; deleted individually or in groups with the
205 command, and globally with the
207 command; displayed, optionally with the content of the
213 Finally, counters can be reset with the
219 Also, each rule belongs to one of 32 different
223 commands to atomically manipulate sets, such as enable,
224 disable, swap sets, move all rules in a set to another
225 one, delete all rules in a set. These can be useful to
226 install temporary configurations, or to test them.
229 for more information on
232 The following options are available:
233 .Bl -tag -width indent
235 While listing, show counter values.
238 command just implies this option.
240 When entering or showing rules, print them in compact form,
241 i.e. without the optional "ip from any to any" string
242 when this does not carry any additional information.
244 While listing, show states and tracks in addition to static ones.
246 While listing, if the
248 option was specified, also show expired states and tracks.
250 Don't ask for confirmation for commands that can cause problems
253 If there is no tty associated with the process, this is implied.
255 Try to resolve addresses and service names in output.
263 be quiet about actions
266 This is useful for adjusting rules by executing multiple
270 .Ql sh\ /etc/rc.firewall ) ,
271 or by processing a file of many
273 rules across a remote login session.
276 is performed in normal (verbose) mode (with the default kernel
277 configuration), it prints a message.
278 Because all rules are flushed, the message might not be delivered
279 to the login session, causing the remote login session to be closed
280 and the remainder of the ruleset to not be processed.
281 Access to the console would then be required to recover.
283 While listing rules, show the
285 each rule belongs to.
286 If this flag is not specified, disabled rules will not be
289 While listing pipes, sort according to one of the four
290 counters (total or current packets or bytes).
292 While listing, show last match timestamp.
295 To ease configuration, rules can be put into a file which is
298 as shown in the last synopsis line.
302 The file will be read line by line and applied as arguments to the
306 Optionally, a preprocessor can be specified using
310 is to be piped through.
311 Useful preprocessors include
317 doesn't start with a slash
319 as its first character, the usual
321 name search is performed.
322 Care should be taken with this in environments where not all
323 file systems are mounted (yet) by the time
325 is being run (e.g. when they are mounted over NFS).
328 has been specified, optional
332 specifications can follow and will be passed on to the preprocessor.
333 This allows for flexible configuration files (like conditionalizing
334 them on the local hostname) and the use of macros to centralize
335 frequently required arguments like IP addresses.
342 commands are used to configure the traffic shaper, as shown in the
343 .Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
346 If the world and the kernel get out of sync the
348 ABI may break, preventing you from being able to add any rules. This can
349 adversely affect the booting process. You can use
353 to temporarily disable the firewall to regain access to the network,
354 allowing you to fix the problem.
356 A packet is checked against the active ruleset in multiple places
357 in the protocol stack, under control of several sysctl variables.
358 These places and variables are shown below, and it is important to
359 have this picture in mind in order to design a correct ruleset.
360 .Bd -literal -offset indent
363 +------------>------------+
365 [ip_input] [ip_output] net.inet.ip.fw.enable=1
368 [ether_demux_oncpu] [ether_output_frame] net.link.ether.ipfw=1
373 As can be noted from the above picture, the number of
374 times the same packet goes through the firewall can
375 vary between 0 and 4 depending on packet source and
376 destination, and system configuration.
378 Note that as packets flow through the stack, headers can be
379 stripped or added to it, and so they may or may not be available
381 E.g., incoming packets will include the MAC header when
384 .Fn ether_demux_oncpu ,
385 but the same packets will have the MAC header stripped off when
390 Also note that each packet is always checked against the complete ruleset,
391 irrespective of the place where the check occurs, or the source of the packet.
392 If a rule contains some match patterns or actions which are not valid
393 for the place of invocation (e.g. trying to match a MAC header within
395 the match pattern will not match, but a
397 operator in front of such patterns
401 match on those packets.
402 It is thus the responsibility of
403 the programmer, if necessary, to write a suitable ruleset to
404 differentiate among the possible places.
406 rules can be useful here, as an example:
407 .Bd -literal -offset indent
408 # packets from ether_demux_oncpu
409 ipfw add 10 skipto 1000 all from any to any layer2 in
410 # packets from ip_input
411 ipfw add 10 skipto 2000 all from any to any not layer2 in
412 # packets from ip_output
413 ipfw add 10 skipto 3000 all from any to any not layer2 out
414 # packets from ether_output_frame
415 ipfw add 10 skipto 4000 all from any to any layer2 out
420 rules is the following:
421 .Bd -ragged -offset indent
423 .Op Cm set Ar set_number
424 .Op Cm prob Ar match_probability
427 .Op Cm log Op Cm logamount Ar number
431 where the body of the rule specifies which information is used
432 for filtering packets, among the following:
434 .Bl -tag -width "Source and dest. addresses and ports" -offset XXX -compact
435 .It Layer-2 header fields
439 .It Source and dest. addresses and ports
443 .It Transmit and receive interface
445 .It Misc. IP header fields
446 Version, type of service, datagram length, identification,
450 .It Misc. TCP header fields
451 TCP flags (SYN, FIN, ACK, RST, etc.),
452 sequence number, acknowledgment number,
458 When the packet can be associated with a local socket.
461 Note that some of the above information, e.g. source MAC or IP addresses and
462 TCP/UDP ports, could easily be spoofed, so filtering on those fields
463 alone might not guarantee the desired results.
464 .Bl -tag -width indent
466 Each rule is associated with a
468 in the range 1..65535, with the latter reserved for the
471 Rules are checked sequentially by rule number.
472 Multiple rules can have the same number, in which case they are
473 checked (and listed) according to the order in which they have
475 If a rule is entered without specifying a number, the kernel will
476 assign one in such a way that the rule becomes the last one
480 Automatic rule numbers are assigned by incrementing the last
481 non-default rule number by the value of the sysctl variable
482 .Ar net.inet.ip.fw.autoinc_step
483 which defaults to 100.
484 If this is not possible (e.g. because we would go beyond the
485 maximum allowed rule number), the number of the last
486 non-default value is used instead.
487 .It Cm set Ar set_number
488 Each rule is associated with a
490 in the range 0..31, with the latter reserved for the
493 Sets can be individually disabled and enabled, so this parameter
494 is of fundamental importance for atomic ruleset manipulation.
495 It can be also used to simplify deletion of groups of rules.
496 If a rule is entered without specifying a set number,
498 .It Cm prob Ar match_probability
499 A match is only declared with the specified probability
500 (floating point number between 0 and 1).
501 This can be useful for a number of applications such as
502 random packet drop or
505 to simulate the effect of multiple paths leading to out-of-order
507 .It Cm log Op Cm logamount Ar number
508 When a packet matches a rule with the
510 keyword, a message will be
516 The logging only occurs if the sysctl variable
517 .Em net.inet.ip.fw.verbose
519 (which is the default when the kernel is compiled with
520 .Dv IPFIREWALL_VERBOSE )
521 and the number of packets logged so far for that
522 particular rule does not exceed the
527 is specified, the limit is taken from the sysctl variable
528 .Em net.inet.ip.fw.verbose_limit .
529 In both cases, a value of 0 removes the logging limit.
531 Once the limit is reached, logging can be re-enabled by
532 clearing the logging counter or the packet counter for that entry, see the
537 A rule can be associated with one of the following actions, which
538 will be executed when the packet matches the body of the rule.
539 .Bl -tag -width indent
540 .It Cm allow | accept | pass | permit
541 Allow packets that match rule.
542 The search terminates.
544 Checks the packet against the state table.
545 If a match is found, execute the action associated with
546 the rule which generated this state, otherwise
547 move to the next rule.
550 rules do not have a body.
553 rule is found, the state table is checked at the first
560 Update counters for all packets that match rule.
561 The search continues with the next rule.
563 Reassemble IP fragments.
564 If an IP packet was reassembled,
565 the reassembled IP packet would be passed to the next rule for further
567 This action only applies to IP fragments received by
569 The most common way to use this action is like this:
571 .Dl "ipfw add defrag ip from any to any"
573 It is recommended to reassemble IP fragments before
578 or any layer 4 protocols filtering,
585 Discard packets that match this rule.
586 The search terminates.
587 .It Cm divert Ar port
588 Divert packets that match this rule to the
592 The search terminates.
593 .It Cm fwd | forward Ar ipaddr Ns Op , Ns Ar port
594 Change the next-hop on matching packets to
596 which can be an IP address in dotted quad format or a host name.
597 The search terminates if this rule matches.
601 is a local address, then matching packets will be forwarded to
603 (or the port number in the packet if one is not specified in the rule)
604 on the local machine.
608 is not a local address, then the port number
609 (if specified) is ignored, and the packet will be
610 forwarded to the remote address, using the route as found in
611 the local routing table for that IP.
615 rule will not match layer-2 packets (those received
623 action does not change the contents of the packet at all.
624 In particular, the destination address remains unmodified, so
625 packets forwarded to another system will usually be rejected by that system
626 unless there is a matching rule on that system to capture them.
627 For packets forwarded locally,
628 the local address of the socket will be
629 set to the original destination address of the packet.
632 entry look rather weird but is intended for
633 use with transparent proxy servers.
634 .It Cm pipe Ar pipe_nr
638 (for bandwidth limitation, delay, etc.).
640 .Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
641 Section for further information.
642 The search terminates; however, on exit from the pipe and if
646 .Em net.inet.ip.fw.one_pass
647 is not set, the packet is passed again to the firewall code
648 starting from the next rule.
649 .It Cm queue Ar queue_nr
653 (for bandwidth limitation using WF2Q+).
659 Discard packets that match this rule, and if the
660 packet is a TCP packet, try to send a TCP reset (RST) notice.
661 The search terminates.
662 .It Cm skipto Ar number
663 Skip all subsequent rules numbered less than
665 The search continues with the first rule numbered
669 Send a copy of packets matching this rule to the
673 The search terminates and the original packet is accepted
677 .It Cm unreach Ar code
678 Discard packets that match this rule, and try to send an ICMP
679 unreachable notice with code
683 is a number from 0 to 255, or one of these aliases:
684 .Cm net , host , protocol , port ,
685 .Cm needfrag , srcfail , net-unknown , host-unknown ,
686 .Cm isolated , net-prohib , host-prohib , tosnet ,
687 .Cm toshost , filter-prohib , host-precedence
689 .Cm precedence-cutoff .
690 The search terminates.
693 The body of a rule contains zero or more patterns (such as
694 specific source and destination addresses or ports,
695 protocol options, incoming or outgoing interfaces, etc.)
696 that the packet must match in order to be recognised.
697 In general, the patterns are connected by (implicit)
699 operators -- i.e. all must match in order for the
701 Individual patterns can be prefixed by the
703 operator to reverse the result of the match, as in
705 .Dl "ipfw add 100 allow ip from not 1.2.3.4 to any"
707 Additionally, sets of alternative match patterns
709 can be constructed by putting the patterns in
710 lists enclosed between parentheses ( ) or braces { }, and
715 .Dl "ipfw add 100 allow ip from { x or not y or z } to any"
717 Only one level of parentheses is allowed.
718 Beware that most shells have special meanings for parentheses
719 or braces, so it is advisable to put a backslash \\ in front of them
720 to prevent such interpretations.
722 The body of a rule must in general include a source and destination
726 can be used in various places to specify that the content of
727 a required field is irrelevant.
729 The rule body has the following format:
730 .Bd -ragged -offset indent
731 .Op Ar proto Cm from Ar src Cm to Ar dst
735 The first part (protocol from src to dst) is for backward
740 any match pattern (including MAC headers, IPv4 protocols,
741 addresses and ports) can be specified in the
745 Rule fields have the following meaning:
746 .Bl -tag -width indent
747 .It Ar proto : protocol | Cm { Ar protocol Cm or ... }
748 An IPv4 protocol (or an
750 with multiple protocols) specified by number or name
751 (for a complete list see
752 .Pa /etc/protocols ) .
757 keywords mean any protocol will match.
758 .It Ar src No and Ar dst : ip-address | Cm { Ar ip-address Cm or ... } Op Ar ports
763 containing one or more of them,
764 optionally followed by
768 An address (or set of addresses) specified in one of the following
769 ways, optionally preceded by a
772 .Bl -tag -width indent
774 matches any IP address.
776 matches any IP address configured on an interface in the system.
777 The address list is evaluated at the time the packet is
779 .It Cm < Ns Ar number Ns Cm >
780 Matches any network or host addresses in the
785 Matches the first IPv4 address assigned to the
787 It is intended to help matching the IPv4 address assigned to the
791 .It Cm Op ifX Ns Cm :net
792 Matches the IPv4 network of the first IPv4 address assigned to the
794 It is intended to help matching the IPv4 network of the IPv4 address
799 .It Ar numeric-ip | hostname
800 Matches a single IPv4 address, specified as dotted-quad or a hostname.
801 Hostnames are resolved at the time the rule is added to the firewall list.
802 .It Ar addr Ns / Ns Ar masklen
803 Matches all addresses with base
805 (specified as a dotted quad or a hostname)
809 As an example, 1.2.3.4/25 will match
810 all IP numbers from 1.2.3.0 to 1.2.3.127 .
811 .It Ar addr Ns / Ns Ar masklen Ns Cm { Ns Ar num,num,... Ns Cm }
812 Matches all addresses with base address
814 (specified as a dotted quad or a hostname)
815 and whose last byte is in the list between braces { } .
816 Note that there must be no spaces between braces, commas and
820 field is used to limit the size of the set of addresses,
821 and can have any value between 24 and 32.
823 As an example, an address specified as 1.2.3.4/24{128,35,55,89}
824 will match the following IP addresses:
826 1.2.3.128 1.2.3.35 1.2.3.55 1.2.3.89 .
828 This format is particularly useful to handle sparse address sets
829 within a single rule. Because the matching occurs using a
830 bitmask, it takes constant time and dramatically reduces
831 the complexity of rulesets.
832 .It Ar addr Ns : Ns Ar mask
833 Matches all addresses with base
835 (specified as a dotted quad or a hostname)
838 specified as a dotted quad.
839 As an example, 1.2.3.4/255.0.255.0 will match
841 We suggest to use this form only for non-contiguous
842 masks, and resort to the
843 .Ar addr Ns / Ns Ar masklen
844 format for contiguous masks, which is more compact and less
847 .It Ar ports : Oo Cm not Oc Bro Ar port | port Ns \&- Ns Ar port Ns Brc Op , Ns Ar ...
848 For protocols which support port numbers (such as TCP and UDP), optional
850 may be specified as one or more ports or port ranges, separated
851 by commas but no spaces, and an optional
856 notation specifies a range of ports (including boundaries).
860 may be used instead of numeric port values.
861 The length of the port list is limited to 30 ports or ranges,
862 though one can specify larger ranges by using an
870 can be used to escape the dash
872 character in a service name (from a shell, the backslash must be
873 typed twice to avoid the shell itself interpreting it as an escape
876 .Dl "ipfw add count tcp from any ftp\e\e-data-ftp to any"
878 Fragmented packets which have a non-zero offset (i.e. not the first
879 fragment) will never match a rule which has one or more port
885 options for details on matching fragmented packets.
888 action for reassembling IP fragments.
890 .Ss RULE OPTIONS (MATCH PATTERNS)
891 Additional match patterns can be used within
892 rules. Zero or more of these so-called
894 can be present in a rule, optionally prefixed by the
896 operand, and possibly grouped into
899 The following match patterns can be used (listed in alphabetical order):
900 .Bl -tag -width indent
901 .It Cm dst-ip Ar ip-address
902 Matches IP packets whose destination IP is one of the address(es)
903 specified as argument.
904 .It Cm dst-port Ar ports
905 Matches IP packets whose destination port is one of the port(s)
906 specified as argument.
908 Matches TCP packets that have the RST or ACK bits set.
910 Matches packets that are fragments and not the first
911 fragment of an IP datagram.
912 Note that these packets will not have the next protocol header
913 (e.g. TCP, UDP) so options that look into these headers cannot match.
920 Matches all TCP or UDP packets sent by or received for a
924 may be specified by name or number.
925 .It Cm icmptypes Ar types
926 Matches ICMP packets whose ICMP type is in the list
928 The list may be specified as any combination of ranges or
929 individual types separated by commas.
930 The supported ICMP types are:
934 destination unreachable
946 time-to-live exceeded
960 and address mask reply
963 Matches incoming or outgoing packets, respectively.
967 are mutually exclusive (in fact,
973 even if it's the first fragment.
980 Matches IP packets whose
985 Matches IP packets whose total length, including header and data, is
988 .It Cm ipoptions Ar spec
989 Matches packets whose IP header contains the comma separated list of
992 The supported IP options are:
995 (strict source route),
997 (loose source route),
999 (record packet route) and
1002 The absence of a particular option may be denoted
1005 .It Cm ipprecedence Ar precedence
1006 Matches IP packets whose precedence field is equal to
1008 .It Cm iptos Ar spec
1009 Matches IP packets whose
1011 field contains the comma separated list of
1012 service types specified in
1014 The supported IP types of service are:
1017 .Pq Dv IPTOS_LOWDELAY ,
1019 .Pq Dv IPTOS_THROUGHPUT ,
1021 .Pq Dv IPTOS_RELIABILITY ,
1023 .Pq Dv IPTOS_MINCOST ,
1026 The absence of a particular type may be denoted
1030 Matches IP packets whose time to live is
1032 .It Cm ipversion Ar ver
1033 Matches IP packets whose IP version field is
1036 Upon a match, the firewall will create a state, whose
1037 default behaviour is to match bidirectional traffic between
1038 source and destination IP/port using the same protocol.
1039 The rule has a limited lifetime (controlled by a set of
1041 variables), and the lifetime is refreshed every time a matching
1044 Matches only layer2 packets, i.e. those passed to
1047 .Fn ether_demux_oncpu
1049 .Fn ether_output_frame .
1050 .It Cm limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N
1051 The firewall will only allow
1053 connections with the same
1054 set of parameters as specified in the rule.
1056 of source and destination addresses and ports can be
1058 .It Cm { MAC | mac } Ar dst-mac src-mac
1059 Match packets with a given
1063 addresses, specified as the
1065 keyword (matching any MAC address), or six groups of hex digits
1066 separated by colons,
1067 and optionally followed by a mask indicating how many bits are
1070 .Dl "MAC 10:20:30:40:50:60/33 any"
1072 Note that the order of MAC addresses (destination first,
1074 the same as on the wire, but the opposite of the one used for
1076 .It Cm mac-type Ar mac-type
1077 Matches packets whose Ethernet Type field
1078 corresponds to one of those specified as argument.
1080 is specified in the same way as
1082 (i.e. one or more comma-separated single values or ranges).
1083 You can use symbolic names for known values such as
1084 .Em vlan , ipv4, ipv6 .
1085 Values can be entered as decimal or hexadecimal (if prefixed by 0x),
1086 and they are always printed as hexadecimal (unless the
1088 option is used, in which case symbolic resolution will be attempted).
1089 .It Cm proto Ar protocol
1090 Matches packets with the corresponding IPv4 protocol.
1091 .It Cm rdr | redirect Ar ipaddr Ns Op , Ns Ar port
1093 the TCP or UDP packet will be redirected to
1097 after changing the packet's destination IP address to
1099 and destination port to
1104 packet's destination port will not be changed.
1105 This rule only applies to
1117 This rule will create a state.
1120 .It Cm recv | xmit | via Brq Ar ifX | Ar if Ns Cm * | Ar ipno | Ar any
1121 Matches packets received, transmitted or going through,
1122 respectively, the interface specified by exact name
1126 by IP address, or through some interface.
1130 keyword causes the interface to always be checked.
1137 then only the receive or transmit interface (respectively)
1139 By specifying both, it is possible to match packets based on
1140 both receive and transmit interface, e.g.:
1142 .Dl "ipfw add deny ip from any to any out recv ed0 xmit ed1"
1146 interface can be tested on either incoming or outgoing packets,
1149 interface can only be tested on outgoing packets.
1154 is invalid) whenever
1158 A packet may not have a receive or transmit interface: packets
1159 originating from the local host have no receive interface,
1160 while packets destined for the local host have no transmit
1163 Matches TCP packets that have the SYN bit set but no ACK bit.
1164 This is the short form of
1165 .Dq Li tcpflags\ syn,!ack .
1166 .It Cm src-ip Ar ip-address
1167 Matches IP packets whose source IP is one of the address(es)
1168 specified as argument.
1169 .It Cm src-port Ar ports
1170 Matches IP packets whose source port is one of the port(s)
1171 specified as argument.
1172 .It Cm tcpack Ar ack
1174 Match if the TCP header acknowledgment number field is set to
1176 .It Cm tcpflags Ar spec
1178 Match if the TCP header contains the comma separated list of
1181 The supported TCP flags are:
1190 The absence of a particular flag may be denoted
1193 A rule which contains a
1195 specification can never match a fragmented packet which has
1201 options for details on matching fragmented packets.
1204 action for reassembling IP fragments.
1205 .It Cm tcpseq Ar seq
1207 Match if the TCP header sequence number field is set to
1209 .It Cm tcpwin Ar win
1211 Match if the TCP header window field is set to
1213 .It Cm tcpoptions Ar spec
1215 Match if the TCP header contains the comma separated list of
1216 options specified in
1218 The supported TCP options are:
1221 (maximum segment size),
1223 (tcp window advertisement),
1227 (rfc1323 timestamp) and
1229 (rfc1644 t/tcp connection count).
1230 The absence of a particular option may be denoted
1234 Match all TCP or UDP packets sent by or received for a
1238 may be matched by name or identification number.
1241 Each rule belongs to one of 32 different
1244 Set 31 is reserved for the default rule.
1246 By default, rules are put in set 0, unless you use the
1248 attribute when entering a new rule.
1249 Sets can be individually and atomically enabled or disabled,
1250 so this mechanism permits an easy way to store multiple configurations
1251 of the firewall and quickly (and atomically) switch between them.
1252 The command to enable/disable sets is
1253 .Bd -ragged -offset indent
1255 .Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
1262 sections can be specified.
1263 Command execution is atomic on all the sets specified in the command.
1264 By default, all sets are enabled.
1266 When you disable a set, its rules behave as if they do not exist
1267 in the firewall configuration, with only one exception:
1268 .Bd -ragged -offset indent
1269 states and tracks created from a rule before it had been disabled
1270 will still be active until they expire. In order to delete
1271 states and tracks you have to explicitly delete the parent rule
1272 which generated them.
1275 The set number of rules can be changed with the command
1276 .Bd -ragged -offset indent
1279 .Brq Cm rule Ar rule-number | old-set
1283 Also, you can atomically swap two rulesets with the command
1284 .Bd -ragged -offset indent
1286 .Cm set swap Ar first-set second-set
1291 Section on some possible uses of sets of rules.
1292 .Sh STATEFUL FIREWALL
1293 Stateful operation is a way for the firewall to dynamically
1294 create states and tracks for specific flows when packets that
1295 match a given pattern are detected. Support for stateful
1296 operation comes through the
1306 States are created when a packet matches a
1311 rule, causing the creation of a
1313 which will match all and only packets with
1317 .Em src-ip/src-port dst-ip/dst-port
1322 are used here only to denote the initial match addresses, but they
1323 are completely equivalent afterwards).
1325 tracks are created when a packet matches a
1328 States will be checked at the first
1334 occurrence, and the action performed upon a match will be the same
1335 as in the parent rule.
1337 Note that no additional attributes other than protocol and IP addresses
1338 and ports are checked on states.
1340 The typical use of states is to keep a closed firewall configuration,
1341 but let the first TCP SYN packet from the inside network install a
1342 state for the flow so that packets belonging to that session
1343 will be allowed through the firewall:
1345 .Dl "ipfw add check-state"
1346 .Dl "ipfw add allow tcp from my-subnet to any setup keep-state"
1347 .Dl "ipfw add deny tcp from any to any"
1349 A similar approach can be used for UDP, where an UDP packet coming
1350 from the inside will install a state to let the response through
1353 .Dl "ipfw add check-state"
1354 .Dl "ipfw add allow udp from my-subnet to any keep-state"
1355 .Dl "ipfw add deny udp from any to any"
1357 States and tracks expire after some time, which depends on the status
1358 of the flow and the setting of some
1362 .Sx SYSCTL VARIABLES
1364 For TCP sessions, states can be instructed to periodically
1365 send keepalive packets to refresh the state of the rule when it is
1370 for more examples on how to use states.
1371 .Sh TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
1373 is also the user interface for the
1378 operates by first using the firewall to classify packets and divide them into
1380 using any match pattern that can be used in
1383 Depending on local policies, a flow can contain packets for a single
1384 TCP connection, or from/to a given host, or entire subnet, or a
1387 Packets belonging to the same flow are then passed to either of two
1388 different objects, which implement the traffic regulation:
1389 .Bl -hang -offset XXXX
1391 A pipe emulates a link with given bandwidth, propagation delay,
1392 queue size and packet loss rate.
1393 Packets are queued in front of the pipe as they come out from the classifier,
1394 and then transferred to the pipe according to the pipe's parameters.
1397 is an abstraction used to implement the WF2Q+
1398 (Worst-case Fair Weighted Fair Queueing) policy, which is
1399 an efficient variant of the WFQ policy.
1401 The queue associates a
1403 and a reference pipe to each flow, and then all backlogged (i.e.,
1404 with packets queued) flows linked to the same pipe share the pipe's
1405 bandwidth proportionally to their weights.
1406 Note that weights are not priorities; a flow with a lower weight
1407 is still guaranteed to get its fraction of the bandwidth even if a
1408 flow with a higher weight is permanently backlogged.
1412 can be used to set hard limits to the bandwidth that a flow can use, whereas
1414 can be used to determine how different flow share the available bandwidth.
1420 configuration commands are the following:
1421 .Bd -ragged -offset indent
1422 .Cm pipe Ar number Cm config Ar pipe-configuration
1424 .Cm queue Ar number Cm config Ar queue-configuration
1427 The following parameters can be configured for a pipe:
1429 .Bl -tag -width indent -compact
1430 .It Cm bw Ar bandwidth
1431 Bandwidth, measured in
1434 .Brq Cm bit/s | Byte/s .
1437 A value of 0 (default) means unlimited bandwidth.
1438 The unit must immediately follow the number, as in
1440 .Dl "ipfw pipe 1 config bw 300Kbit/s"
1442 .It Cm delay Ar ms-delay
1443 Propagation delay, measured in milliseconds.
1444 The value is rounded to the next multiple of the clock tick
1445 (typically 10ms, but it is a good practice to run kernels
1447 .Cd "options HZ=1000"
1449 the granularity to 1ms or less).
1450 Default value is 0, meaning no delay.
1453 The following parameters can be configured for a queue:
1455 .Bl -tag -width indent -compact
1456 .It Cm pipe Ar pipe_nr
1457 Connects a queue to the specified pipe.
1458 Multiple queues (with the same or different weights) can be connected to
1459 the same pipe, which specifies the aggregate rate for the set of queues.
1461 .It Cm weight Ar weight
1462 Specifies the weight to be used for flows matching this queue.
1463 The weight must be in the range 1..100, and defaults to 1.
1466 Finally, the following parameters can be configured for both
1469 .Bl -tag -width XXXX -compact
1470 .It Cm buckets Ar hash-table-size
1471 Specifies the size of the hash table used for storing the
1473 Default value is 64 controlled by the
1476 .Em net.inet.ip.dummynet.hash_size ,
1477 allowed range is 16 to 65536.
1479 .It Cm mask Ar mask-specifier
1480 Packets sent to a given pipe or queue by an
1482 rule can be further classified into multiple flows, each of which is then
1486 A flow identifier is constructed by masking the IP addresses,
1487 ports and protocol types as specified with the
1489 options in the configuration of the pipe or queue.
1490 For each different flow identifier, a new pipe or queue is created
1491 with the same parameters as the original object, and matching packets
1496 are used, each flow will get the same bandwidth as defined by the pipe,
1499 are used, each flow will share the parent's pipe bandwidth evenly
1500 with other flows generated by the same queue (note that other queues
1501 with different weights might be connected to the same pipe).
1503 Available mask specifiers are a combination of one or more of the following:
1505 .Cm dst-ip Ar mask ,
1506 .Cm src-ip Ar mask ,
1507 .Cm dst-port Ar mask ,
1508 .Cm src-port Ar mask ,
1513 where the latter means all bits in all fields are significant.
1516 When a packet is dropped by a dummynet queue or pipe, the error
1517 is normally reported to the caller routine in the kernel, in the
1518 same way as it happens when a device queue fills up. Setting this
1519 option reports the packet as successfully delivered, which can be
1520 needed for some experimental setups where you want to simulate
1521 loss or congestion at a remote router.
1524 This option is always on,
1528 .It Cm plr Ar packet-loss-rate
1531 .Ar packet-loss-rate
1532 is a floating-point number between 0 and 1, with 0 meaning no
1533 loss, 1 meaning 100% loss.
1534 The loss rate is internally represented on 31 bits.
1536 .It Cm queue Brq Ar slots | size Ns Cm Kbytes
1541 Default value is 50 slots, which
1542 is the typical queue size for Ethernet devices.
1543 Note that for slow speed links you should keep the queue
1544 size short or your traffic might be affected by a significant
1546 E.g., 50 max-sized ethernet packets (1500 bytes) mean 600Kbit
1547 or 20s of queue on a 30Kbit/s pipe.
1548 Even worse effect can result if you get packets from an
1549 interface with a much larger MTU, e.g. the loopback interface
1550 with its 16KB packets.
1552 .It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p
1553 Make use of the RED (Random Early Detection) queue management algorithm.
1558 point numbers between 0 and 1 (0 not included), while
1562 are integer numbers specifying thresholds for queue management
1563 (thresholds are computed in bytes if the queue has been defined
1564 in bytes, in slots otherwise).
1567 also supports the gentle RED variant (gred).
1570 variables can be used to control the RED behaviour:
1571 .Bl -tag -width indent
1572 .It Em net.inet.ip.dummynet.red_lookup_depth
1573 specifies the accuracy in computing the average queue
1574 when the link is idle (defaults to 256, must be greater than zero)
1575 .It Em net.inet.ip.dummynet.red_avg_pkt_size
1576 specifies the expected average packet size (defaults to 512, must be
1578 .It Em net.inet.ip.dummynet.red_max_pkt_size
1579 specifies the expected maximum packet size, only used when queue
1580 thresholds are in bytes (defaults to 1500, must be greater than zero).
1584 Table provides a convenient way to support a large amount of
1585 discrete host or network addresses for the
1591 Non-existing tables never match.
1592 For network addresses,
1593 only CIDR form is supported.
1595 Tables are identified by
1597 which ranges from 0 to
1598 .Cm net.inet.ip.fw.table_max
1600 Default number of available tables is 64,
1601 i.e. valid table ids are from 0 to 63.
1602 Number of available tables can be changed by setting tunable
1603 .Cm net.inet.ip.fw.table_max .
1604 Max configurable number of available tables is 65535.
1606 Tables must be created explicitly
1607 before host or network addresses could be added to them:
1608 .Bd -ragged -offset indent
1609 .Cm table Ar number Cm create
1612 Host or network addresses can be added to an existing
1614 .Bd -ragged -offset indent
1615 .Cm table Ar number Cm add Ar address
1619 Host or network addresses can be removed from an existing
1621 .Bd -ragged -offset indent
1622 .Cm table Ar number Cm delete Ar address
1626 Addresses in a table can be flushed by:
1627 .Bd -ragged -offset indent
1628 .Cm table Ar number Cm flush
1631 Or you can optionally flush all existing tables:
1632 .Bd -ragged -offset indent
1636 Each address in a table has two counters.
1637 One records the number of usage,
1638 the other saves the time of the last match.
1639 These counters can be resetted for a specific table:
1640 .Bd -ragged -offset indent
1641 .Cm table Ar number Cm zero
1644 Or you can reset counters of addresses in all existing tables by:
1645 .Bd -ragged -offset indent
1649 Host and network addresses in the tables are not expired by the
1651 manual intervention is required to expire addresses unused in a table
1654 .Bd -ragged -offset indent
1655 .Cm table Ar number Cm expire Ar seconds
1659 you can expire all addresses that were unused within the last
1662 .Bd -ragged -offset indent
1663 .Cm table expire Ar seconds
1666 An existing table can be destroyed by:
1667 .Bd -ragged -offset indent
1668 .Cm table Ar number Cm destroy
1671 All existing tables can be listed by:
1672 .Bd -ragged -offset indent
1676 All addresses in an existing table can be dumped by:
1677 .Bd -ragged -offset indent
1679 .Brq Cm print | show
1682 Here are some important points to consider when designing your
1686 Remember that you filter both packets going
1690 Most connections need packets going in both directions.
1692 Remember to test very carefully.
1693 It is a good idea to be near the console when doing this.
1694 If you cannot be near the console,
1695 use an auto-recovery script such as the one in
1696 .Pa /usr/share/examples/ipfw/change_rules.sh .
1698 Don't forget the loopback interface.
1703 There are circumstances where fragmented datagrams are unconditionally
1705 TCP packets are dropped if they do not contain at least 20 bytes of
1706 TCP header, UDP packets are dropped if they do not contain a full 8
1707 byte UDP header, and ICMP packets are dropped if they do not contain
1708 4 bytes of ICMP header, enough to specify the ICMP type, code, and
1710 These packets are simply logged as
1712 since there may not be enough good data in the packet to produce a
1713 meaningful log entry.
1715 Another type of packet is unconditionally dropped, a TCP packet with a
1716 fragment offset of one.
1717 This is a valid packet, but it only has one use, to try
1718 to circumvent firewalls.
1719 When logging is enabled, these packets are
1720 reported as being dropped by rule -1.
1722 If you are logged in over a network, loading the
1726 is probably not as straightforward as you would think.
1727 I recommend the following command line:
1728 .Bd -literal -offset indent
1729 kldload /boot/modules/ipfw.ko && \e
1730 ipfw add 32000 allow ip from any to any
1733 Along the same lines, doing an
1734 .Bd -literal -offset indent
1738 in similar surroundings is also a bad idea.
1742 filter list may not be modified if the system security level
1743 is set to 3 or higher
1746 for information on system security levels).
1748 .Sh PACKET DIVERSION
1751 socket bound to the specified port will receive all packets
1752 diverted to that port.
1753 If no socket is bound to the destination port, or if the kernel
1754 wasn't compiled with divert socket support, the packets are
1756 .Sh SYSCTL VARIABLES
1759 variables controls the behaviour of the firewall and
1762 These are shown below together with their default value
1763 (but always check with the
1765 command what value is actually in use) and meaning:
1766 .Bl -tag -width indent
1767 .It Em net.filters_default_to_accept : No 0
1768 If set prior to loading the
1770 kernel module, the filter will default to allowing all packets through.
1771 If not set the filter will likely default to not allowing any packets through.
1772 .It Em net.inet.ip.dummynet.expire : No 1
1773 Lazily delete dynamic pipes/queue once they have no pending traffic.
1774 You can disable this by setting the variable to 0, in which case
1775 the pipes/queues will only be deleted when the threshold is reached.
1776 .It Em net.inet.ip.dummynet.hash_size : No 64
1777 Default size of the hash table used for dynamic pipes/queues.
1778 This value is used when no
1780 option is specified when configuring a pipe/queue.
1781 .It Em net.inet.ip.dummynet.max_chain_len : No 16
1782 Target value for the maximum number of pipes/queues in a hash bucket.
1784 .Cm max_chain_len*hash_size
1785 is used to determine the threshold over which empty pipes/queues
1786 will be expired even when
1787 .Cm net.inet.ip.dummynet.expire=0 .
1788 .It Em net.inet.ip.dummynet.red_lookup_depth : No 256
1789 .It Em net.inet.ip.dummynet.red_avg_pkt_size : No 512
1790 .It Em net.inet.ip.dummynet.red_max_pkt_size : No 1500
1791 Parameters used in the computations of the drop probability
1792 for the RED algorithm.
1793 .It Em net.inet.ip.fw.autoinc_step : No 100
1794 Delta between rule numbers when auto-generating them.
1795 The value must be in the range 1..1000.
1796 .It Em net.inet.ip.fw.debug : No 1
1797 Controls debugging messages produced by
1799 .It Em net.inet.ip.fw.table_max : No 64
1800 Number of available tables.
1801 This value can only be changed by setting tunable
1802 .Cm net.inet.ip.fw.table_max .
1803 .It Em net.inet.ip.fw.state_cnt : No 3
1804 Current number of states
1806 .It Em net.inet.ip.fw.state_max : No 4096
1807 Maximum number of states.
1808 When you hit this limit,
1809 no more states can be installed until old ones expire.
1810 .It Em net.inet.ip.fw.track_cnt : No 3
1811 Current number of tracks
1816 .It Em net.inet.ip.fw.track_max : No 4096
1817 Maximum number of tracks.
1818 When you hit this limit,
1819 no more tracks can be installed until old ones expire.
1820 .It Em net.inet.ip.fw.dyn_keepalive : No 1
1821 Enables generation of keepalive packets for
1826 rules on TCP sessions. A keepalive is generated to both
1827 sides of the connection every 5 seconds for the last 20
1828 seconds of the lifetime of the rule.
1829 .It Em net.inet.ip.fw.dyn_ack_lifetime : No 300
1830 .It Em net.inet.ip.fw.dyn_syn_lifetime : No 20
1831 .It Em net.inet.ip.fw.dyn_finwait_lifetime : No 20
1832 .It Em net.inet.ip.fw.dyn_fin_lifetime : No 2
1833 .It Em net.inet.ip.fw.dyn_rst_lifetime : No 2
1834 .It Em net.inet.ip.fw.dyn_udp_lifetime : No 10
1835 .It Em net.inet.ip.fw.dyn_short_lifetime : No 5
1836 These variables control the lifetime, in seconds, of states and tracks.
1837 Upon the initial SYN exchange the lifetime is kept short,
1838 then increased after both SYN have been seen, then decreased
1839 again during the final FIN exchange or when a RST is received.
1840 .It Em net.inet.ip.fw.enable : No 1
1841 Enables the firewall.
1842 Setting this variable to 0 lets you run your machine without
1843 firewall even if compiled in.
1844 .It Em net.inet.ip.fw.one_pass : No 1
1845 When set, the packet exiting from the
1847 pipe is not passed though the firewall again.
1848 Otherwise, after a pipe action, the packet is
1849 reinjected into the firewall at the next rule.
1851 Note: layer 2 packets coming out of a pipe
1852 are never reinjected in the firewall irrespective of the
1853 value of this variable.
1854 .It Em net.inet.ip.fw.verbose : No 1
1855 Enables verbose messages.
1856 .It Em net.inet.ip.fw.verbose_limit : No 0
1857 Limits the number of messages produced by a verbose firewall.
1858 .It Em net.link.ether.ipfw : No 0
1859 Controls whether layer-2 packets are passed to
1863 .Sh IPFW2 ENHANCEMENTS
1864 This Section lists the features that have been introduced in
1866 which were not present in
1868 We list them in order of the potential impact that they can
1869 have in writing your rulesets.
1870 You might want to consider using these features in order to
1871 write your rulesets in a more efficient way.
1872 .Bl -tag -width indent
1873 .It Handling of non-IPv4 packets
1875 will silently accept all non-IPv4 packets.
1877 will filter all packets (including non-IPv4 ones) according to the ruleset.
1878 To achieve the same behaviour as
1880 you can use the following as the very first rule in your ruleset:
1882 .Dl "ipfw add 1 allow layer2 not mac-type ip"
1886 option might seem redundant, but it is necessary -- packets
1887 passed to the firewall from layer3 will not have a MAC header,
1890 pattern will always fail on them, and the
1892 operator will make this rule into a pass-all.
1895 does not support address sets (those in the form
1896 .Ar addr/masklen{num,num,...} ) .
1901 .It Port specifications
1903 only allows one port range when specifying TCP and UDP ports, and
1904 is limited to 10 entries instead of the 15 allowed by
1908 you can only specify ports when the rule is requesting
1914 you can put port specifications in rules matching all packets,
1915 and the match will be attempted only on those packets carrying
1916 protocols which include port identifiers.
1920 allowed the first port entry to be specified as
1924 can be an arbitrary 16-bit mask.
1925 This syntax is of questionable usefulness and it is not
1926 supported anymore in
1930 does not support Or-blocks.
1933 does not generate keepalives for stateful sessions.
1934 As a consequence, it might cause idle sessions to drop because
1935 the lifetime of the states expires.
1938 does not implement sets of rules.
1939 .It MAC header filtering and Layer-2 firewalling.
1941 does not implement filtering on MAC header fields, nor is it
1942 invoked on packets from
1943 .Fn ether_demux_oncpu
1945 .Fn ether_output_frame .
1947 .Em net.link.ether.ipfw
1948 has no effect there.
1950 The following options are not supported in
1953 .Cm dst-ip, dst-port, layer2, mac, mac-type, src-ip, src-port.
1955 Additionally, the following options are not supported in
1960 .Cm ipid, iplen, ipprecedence, iptos, ipttl,
1961 .Cm ipversion, tcpack, tcpseq, tcpwin .
1962 .It Dummynet options
1963 The following option for
1965 pipes/queues is not supported:
1969 There are far too many possible uses of
1971 so this Section will only give a small set of examples.
1972 .Ss BASIC PACKET FILTERING
1973 This command adds an entry which denies all tcp packets from
1974 .Em cracker.evil.org
1975 to the telnet port of
1977 from being forwarded by the host:
1979 .Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet"
1981 This one disallows any connection from the entire cracker's
1984 .Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org"
1986 A first and efficient way to limit access (not using states)
1987 is the use of the following rules:
1989 .Dl "ipfw add allow tcp from any to any established"
1990 .Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup"
1991 .Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup"
1993 .Dl "ipfw add deny tcp from any to any"
1995 The first rule will be a quick match for normal TCP packets,
1996 but it will not match the initial SYN packet, which will be
1999 rules only for selected source/destination pairs.
2000 All other SYN packets will be rejected by the final
2004 If you administer one or more subnets, you can take advantage of the
2006 syntax to specify address sets and or-blocks and write extremely
2007 compact rulesets which selectively enable services to blocks
2008 of clients, as below:
2010 .Dl "goodguys=\*q{ 10.1.2.0/24{20,35,66,18} or 10.2.3.0/28{6,3,11} }\*q"
2011 .Dl "badguys=\*q10.1.2.0/24{8,38,60}\*q"
2013 .Dl "ipfw add allow ip from ${goodguys} to any"
2014 .Dl "ipfw add deny ip from ${badguys} to any"
2015 .Dl "... normal policies ..."
2019 syntax would require a separate rule for each IP in the above
2022 If you have large number of discrete addresses to block,
2023 and the number of addresses to block keep increasing,
2025 can be used as below:
2027 .Dl "... Initialize the blocked address list using table 0 ..."
2028 .Dl "ipfw table 0 create"
2029 .Dl "ipfw table 0 add 10.0.0.1 10.1.0.1 172.0.0.1"
2030 .Dl "... Block the addresses in table 0 ..."
2031 .Dl "ipfw add deny ip from <0> to any"
2032 .Dl "... Add more addresses to table 0 any time later..."
2033 .Dl "ipfw table 0 add 172.1.0.1"
2034 .Dl "... Expire the addresses unused within the last 24 hours ..."
2035 .Dl "ipfw table 0 expire 86400"
2037 In order to protect a site from flood attacks involving fake
2038 TCP packets, it is safer to use states:
2040 .Dl "ipfw add check-state"
2041 .Dl "ipfw add deny tcp from any to any established"
2042 .Dl "ipfw add allow tcp from my-net to any setup keep-state"
2044 This will let the firewall install states only for
2045 those connection which start with a regular SYN packet coming
2046 from the inside of our network.
2047 States are checked when encountering the first
2054 rule should usually be placed near the beginning of the
2055 ruleset to minimize the amount of work scanning the ruleset.
2056 Your mileage may vary.
2058 To limit the number of connections a user can open
2059 you can use the following type of rules:
2061 .Dl "ipfw add allow tcp from my-net/24 to any setup limit src-addr 10"
2062 .Dl "ipfw add allow tcp from any to me setup limit src-addr 4"
2064 The former (assuming it runs on a gateway) will allow each host
2065 on a /24 network to open at most 10 TCP connections.
2066 The latter can be placed on a server to make sure that a single
2067 client does not use more than 4 simultaneous connections.
2070 stateful rules can be subject to denial-of-service attacks
2071 by a SYN-flood which opens a huge number of states.
2072 The effects of such attacks can be partially limited by
2075 variables which control the operation of the firewall.
2077 Here is a good usage of the
2079 command to see accounting records and timestamp information:
2083 or in short form without timestamps:
2087 which is equivalent to:
2091 Next rule diverts all incoming packets from 192.168.2.0/24
2092 to divert port 5000:
2094 .Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in
2096 The following rules show some of the applications of
2100 for simulations and the like.
2102 This rule drops random incoming packets with a probability
2105 .Dl "ipfw add prob 0.05 deny ip from any to any in"
2107 A similar effect can be achieved making use of dummynet pipes:
2109 .Dl "ipfw add pipe 10 ip from any to any"
2110 .Dl "ipfw pipe 10 config plr 0.05"
2112 We can use pipes to artificially limit bandwidth, e.g. on a
2113 machine acting as a router, if we want to limit traffic from
2114 local clients on 192.168.2.0/24 we do:
2116 .Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
2117 .Dl "ipfw pipe 1 config bw 300Kbit/s queue 50KBytes"
2119 note that we use the
2121 modifier so that the rule is not used twice.
2122 Remember in fact that
2124 rules are checked both on incoming and outgoing packets.
2126 Should we want to simulate a bidirectional link with bandwidth
2127 limitations, the correct way is the following:
2129 .Dl "ipfw add pipe 1 ip from any to any out"
2130 .Dl "ipfw add pipe 2 ip from any to any in"
2131 .Dl "ipfw pipe 1 config bw 64Kbit/s queue 10Kbytes"
2132 .Dl "ipfw pipe 2 config bw 64Kbit/s queue 10Kbytes"
2134 The above can be very useful, e.g. if you want to see how
2135 your fancy Web page will look for a residential user who
2136 is connected only through a slow link.
2137 You should not use only one pipe for both directions, unless
2138 you want to simulate a half-duplex medium (e.g. AppleTalk,
2140 It is not necessary that both pipes have the same configuration,
2141 so we can also simulate asymmetric links.
2143 Should we want to verify network performance with the RED queue
2144 management algorithm:
2146 .Dl "ipfw add pipe 1 ip from any to any"
2147 .Dl "ipfw pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1"
2149 Another typical application of the traffic shaper is to
2150 introduce some delay in the communication.
2151 This can significantly affect applications which do a lot of Remote
2152 Procedure Calls, and where the round-trip-time of the
2153 connection often becomes a limiting factor much more than
2156 .Dl "ipfw add pipe 1 ip from any to any out"
2157 .Dl "ipfw add pipe 2 ip from any to any in"
2158 .Dl "ipfw pipe 1 config delay 250ms bw 1Mbit/s"
2159 .Dl "ipfw pipe 2 config delay 250ms bw 1Mbit/s"
2161 Per-flow queueing can be useful for a variety of purposes.
2162 A very simple one is counting traffic:
2164 .Dl "ipfw add pipe 1 tcp from any to any"
2165 .Dl "ipfw add pipe 1 udp from any to any"
2166 .Dl "ipfw add pipe 1 ip from any to any"
2167 .Dl "ipfw pipe 1 config mask all"
2169 The above set of rules will create queues (and collect
2170 statistics) for all traffic.
2171 Because the pipes have no limitations, the only effect is
2172 collecting statistics.
2173 Note that we need 3 rules, not just the last one, because
2176 tries to match IP packets it will not consider ports, so we
2177 would not see connections on separate ports as different
2180 A more sophisticated example is limiting the outbound traffic
2181 on a net with per-host limits, rather than per-network limits:
2183 .Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
2184 .Dl "ipfw add pipe 2 ip from any to 192.168.2.0/24 in"
2185 .Dl "ipfw pipe 1 config mask src-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
2186 .Dl "ipfw pipe 2 config mask dst-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
2188 To add a set of rules atomically, e.g. set 18:
2190 .Dl "ipfw disable set 18"
2191 .Dl "ipfw add NN set 18 ... # repeat as needed"
2192 .Dl "ipfw enable set 18"
2194 To delete a set of rules atomically the command is simply:
2196 .Dl "ipfw delete set 18"
2198 To test a ruleset and disable it and regain control if something goes wrong:
2200 .Dl "ipfw disable set 18"
2201 .Dl "ipfw add NN set 18 ... # repeat as needed"
2202 .Dl "ipfw enable set 18 ; echo done; sleep 30 && ipfw disable set 18"
2204 Here if everything goes well, you press control-C before the "sleep"
2205 terminates, and your ruleset will be left active. Otherwise, e.g. if
2206 you cannot access your box, the ruleset will be disabled after
2207 the sleep terminates thus restoring the previous situation.
2225 utility first appeared in
2230 Stateful extensions were introduced in
2232 and were rewritten in
2234 Table was introduced in
2237 was introduced in Summer 2002.
2239 .An Ugen J. S. Antsilevich ,
2240 .An Poul-Henning Kamp ,
2246 API based upon code written by
2252 traffic shaper supported by Akamba Corp.
2254 The syntax has grown over the years and sometimes it might be confusing.
2255 Unfortunately, backward compatibility prevents cleaning up mistakes
2256 made in the definition of the syntax.
2260 Misconfiguring the firewall can put your computer in an unusable state,
2261 possibly shutting down network services and requiring console access to
2262 regain control of it.
2264 Incoming packet fragments diverted by
2268 are reassembled before delivery to the socket.
2269 The action used on those packet is the one from the
2270 rule which matches the first fragment of the packet.
2272 Packets that match a
2274 rule should not be immediately accepted, but should continue
2275 going through the rule list.
2276 This may be fixed in a later version.
2278 Packets diverted to userland, and then reinserted by a userland process
2281 will lose various packet attributes, including their source interface.
2282 If a packet is reinserted in this manner, later rules may be incorrectly
2283 applied, making the order of
2285 rules in the rule sequence very important.