9 .Nd IP firewall and traffic shaper control program
19 .Op Ar rule | first-last ...
27 .Brq Cm delete | zero | resetlog
31 .Brq Cm firewall | altq | one_pass | debug | verbose | dyn_keepalive
34 .Brq Cm firewall | altq | one_pass | debug | verbose | dyn_keepalive
37 .Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
41 .Ar number Cm to Ar number
43 .Cm set swap Ar number number
48 .Cm table Ar number Cm add Ar addr Ns Oo / Ns Ar masklen Oc Op Ar value
50 .Cm table Ar number Cm delete Ar addr Ns Op / Ns Ar masklen
68 .Brq Cm delete | list | show
90 utility is the user interface for controlling the
103 numbered from 1 to 65535.
104 Packets are passed to
106 from a number of different places in the protocol stack
107 (depending on the source and destination of the packet,
110 is invoked multiple times on the same packet).
111 The packet passed to the firewall is compared
112 against each of the rules in the firewall
114 When a match is found, the action corresponding to the
115 matching rule is performed.
117 Depending on the action and certain system settings, packets
118 can be reinjected into the firewall at some rule after the
119 matching one for further processing.
123 ruleset always includes a
125 rule (numbered 65535) which cannot be modified or deleted,
126 and matches all packets.
127 The action associated with the
133 depending on how the kernel is configured.
135 If the ruleset includes one or more rules with the
143 behaviour, i.e., upon a match it will create dynamic rules matching
144 the exact parameters (addresses and ports) of the matching packet.
146 These dynamic rules, which have a limited lifetime, are checked
147 at the first occurrence of a
152 rule, and are typically used to open the firewall on-demand to
153 legitimate traffic only.
155 .Sx STATEFUL FIREWALL
158 Sections below for more information on the stateful behaviour of
161 All rules (including dynamic ones) have a few associated counters:
162 a packet count, a byte count, a log count and a timestamp
163 indicating the time of the last match.
164 Counters can be displayed or reset with
168 Rules can be added with the
170 command; deleted individually or in groups with the
172 command, and globally (except those in set 31) with the
174 command; displayed, optionally with the content of the
180 Finally, counters can be reset with the
186 Also, each rule belongs to one of 32 different
190 commands to atomically manipulate sets, such as enable,
191 disable, swap sets, move all rules in a set to another
192 one, delete all rules in a set.
193 These can be useful to
194 install temporary configurations, or to test them.
197 for more information on
200 The following options are available:
201 .Bl -tag -width indent
203 While listing, show counter values.
206 command just implies this option.
208 Only show the action and the comment, not the body of a rule.
212 When entering or showing rules, print them in compact form,
213 i.e., without the optional "ip from any to any" string
214 when this does not carry any additional information.
216 While listing, show dynamic rules in addition to static ones.
218 While listing, if the
220 option was specified, also show expired dynamic rules.
222 Do not ask for confirmation for commands that can cause problems
225 If there is no tty associated with the process, this is implied.
227 While listing a table (see the
229 section below for more information on lookup tables), format values
230 as IP addresses. By default, values are shown as integers.
232 Only check syntax of the command strings, without actually passing
235 Try to resolve addresses and service names in output.
244 be quiet about actions
247 This is useful for adjusting rules by executing multiple
251 .Ql sh\ /etc/rc.firewall ) ,
252 or by processing a file of many
254 rules across a remote login session.
255 It also stops a table add or delete
256 from failing if the entry already exists or is not present.
259 is performed in normal (verbose) mode (with the default kernel
260 configuration), it prints a message.
261 Because all rules are flushed, the message might not be delivered
262 to the login session, causing the remote login session to be closed
263 and the remainder of the ruleset to not be processed.
264 Access to the console would then be required to recover.
266 While listing rules, show the
268 each rule belongs to.
269 If this flag is not specified, disabled rules will not be
272 While listing pipes, sort according to one of the four
273 counters (total or current packets or bytes).
275 While listing, show last match timestamp (converted with ctime()).
277 While listing, show last match timestamp (as seconds from the epoch).
278 This form can be more convenient for postprocessing by scripts.
281 To ease configuration, rules can be put into a file which is
284 as shown in the last synopsis line.
288 The file will be read line by line and applied as arguments to the
292 Optionally, a preprocessor can be specified using
296 is to be piped through.
297 Useful preprocessors include
303 does not start with a slash
305 as its first character, the usual
307 name search is performed.
308 Care should be taken with this in environments where not all
309 file systems are mounted (yet) by the time
311 is being run (e.g.\& when they are mounted over NFS).
314 has been specified, any additional arguments as passed on to the preprocessor
316 This allows for flexible configuration files (like conditionalizing
317 them on the local hostname) and the use of macros to centralize
318 frequently required arguments like IP addresses.
325 commands are used to configure the traffic shaper, as shown in the
326 .Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
329 If the world and the kernel get out of sync the
331 ABI may break, preventing you from being able to add any rules.
333 adversely effect the booting process.
338 to temporarily disable the firewall to regain access to the network,
339 allowing you to fix the problem.
341 A packet is checked against the active ruleset in multiple places
342 in the protocol stack, under control of several sysctl variables.
343 These places and variables are shown below, and it is important to
344 have this picture in mind in order to design a correct ruleset.
345 .Bd -literal -offset indent
348 +----------->-----------+
350 [ip(6)_input] [ip(6)_output] net.inet(6).ip(6).fw.enable=1
353 [ether_demux] [ether_output_frame] net.link.ether.ipfw=1
355 +-->--[bdg_forward]-->--+ net.link.bridge.ipfw=1
360 As can be noted from the above picture, the number of
361 times the same packet goes through the firewall can
362 vary between 0 and 4 depending on packet source and
363 destination, and system configuration.
365 Note that as packets flow through the stack, headers can be
366 stripped or added to it, and so they may or may not be available
368 E.g., incoming packets will include the MAC header when
372 but the same packets will have the MAC header stripped off when
379 Also note that each packet is always checked against the complete ruleset,
380 irrespective of the place where the check occurs, or the source of the packet.
381 If a rule contains some match patterns or actions which are not valid
382 for the place of invocation (e.g.\& trying to match a MAC header within
386 the match pattern will not match, but a
388 operator in front of such patterns
392 match on those packets.
393 It is thus the responsibility of
394 the programmer, if necessary, to write a suitable ruleset to
395 differentiate among the possible places.
397 rules can be useful here, as an example:
398 .Bd -literal -offset indent
399 # packets from ether_demux or bdg_forward
400 ipfw add 10 skipto 1000 all from any to any layer2 in
401 # packets from ip_input
402 ipfw add 10 skipto 2000 all from any to any not layer2 in
403 # packets from ip_output
404 ipfw add 10 skipto 3000 all from any to any not layer2 out
405 # packets from ether_output_frame
406 ipfw add 10 skipto 4000 all from any to any layer2 out
409 (yes, at the moment there is no way to differentiate between
410 ether_demux and bdg_forward).
412 In general, each keyword or argument must be provided as
413 a separate command line argument, with no leading or trailing
415 Keywords are case-sensitive, whereas arguments may
416 or may not be case-sensitive depending on their nature
417 (e.g.\& uid's are, hostnames are not).
421 you can introduce spaces after commas ',' to make
422 the line more readable.
423 You can also put the entire
424 command (including flags) into a single argument.
425 E.g., the following forms are equivalent:
426 .Bd -literal -offset indent
427 ipfw -q add deny src-ip 10.0.0.0/24,127.0.0.1/8
428 ipfw -q add deny src-ip 10.0.0.0/24, 127.0.0.1/8
429 ipfw "-q add deny src-ip 10.0.0.0/24, 127.0.0.1/8"
434 rules is the following:
435 .Bd -ragged -offset indent
438 .Op Cm set Ar set_number
439 .Op Cm prob Ar match_probability
441 .Op Cm log Op Cm logamount Ar number
451 where the body of the rule specifies which information is used
452 for filtering packets, among the following:
454 .Bl -tag -width "Source and dest. addresses and ports" -offset XXX -compact
455 .It Layer-2 header fields
457 .It IPv4 and IPv6 Protocol
459 .It Source and dest. addresses and ports
463 .It Transmit and receive interface
465 .It Misc. IP header fields
466 Version, type of service, datagram length, identification,
467 fragment flag (non-zero IP offset),
470 .It IPv6 Extension headers
471 Fragmentation, Hop-by-Hop options,
472 Routing Headers, Source routing rthdr0, Mobile IPv6 rthdr2, IPSec options.
474 .It Misc. TCP header fields
475 TCP flags (SYN, FIN, ACK, RST, etc.),
476 sequence number, acknowledgment number,
484 When the packet can be associated with a local socket.
486 Whether a packet came from a divert socket (e.g.,
488 .It Fib annotation state
489 Whether a packet has been tagged for using a specific FIB (routing table)
490 in future forwarding decisions.
493 Note that some of the above information, e.g.\& source MAC or IP addresses and
494 TCP/UDP ports, could easily be spoofed, so filtering on those fields
495 alone might not guarantee the desired results.
496 .Bl -tag -width indent
498 Each rule is associated with a
500 in the range 1..65535, with the latter reserved for the
503 Rules are checked sequentially by rule number.
504 Multiple rules can have the same number, in which case they are
505 checked (and listed) according to the order in which they have
507 If a rule is entered without specifying a number, the kernel will
508 assign one in such a way that the rule becomes the last one
512 Automatic rule numbers are assigned by incrementing the last
513 non-default rule number by the value of the sysctl variable
514 .Ar net.inet.ip.fw.autoinc_step
515 which defaults to 100.
516 If this is not possible (e.g.\& because we would go beyond the
517 maximum allowed rule number), the number of the last
518 non-default value is used instead.
519 .It Cm set Ar set_number
520 Each rule is associated with a
523 Sets can be individually disabled and enabled, so this parameter
524 is of fundamental importance for atomic ruleset manipulation.
525 It can be also used to simplify deletion of groups of rules.
526 If a rule is entered without specifying a set number,
529 Set 31 is special in that it cannot be disabled,
530 and rules in set 31 are not deleted by the
532 command (but you can delete them with the
533 .Nm ipfw delete set 31
535 Set 31 is also used for the
538 .It Cm prob Ar match_probability
539 A match is only declared with the specified probability
540 (floating point number between 0 and 1).
541 This can be useful for a number of applications such as
542 random packet drop or
545 to simulate the effect of multiple paths leading to out-of-order
548 Note: this condition is checked before any other condition, including
549 ones such as keep-state or check-state which might have side effects.
550 .It Cm log Op Cm logamount Ar number
551 When a packet matches a rule with the
553 keyword, a message will be
559 The logging only occurs if the sysctl variable
560 .Va net.inet.ip.fw.verbose
562 (which is the default when the kernel is compiled with
563 .Dv IPFIREWALL_VERBOSE )
564 and the number of packets logged so far for that
565 particular rule does not exceed the
570 is specified, the limit is taken from the sysctl variable
571 .Va net.inet.ip.fw.verbose_limit .
572 In both cases, a value of 0 removes the logging limit.
574 Once the limit is reached, logging can be re-enabled by
575 clearing the logging counter or the packet counter for that entry, see the
579 Note: logging is done after all other packet matching conditions
580 have been successfully verified, and before performing the final
581 action (accept, deny, etc.) on the packet.
583 When a packet matches a rule with the
585 keyword, the numeric tag for the given
587 in the range 1..65534 will be attached to the packet.
588 The tag acts as an internal marker (it is not sent out over
589 the wire) that can be used to identify these packets later on.
590 This can be used, for example, to provide trust between interfaces
591 and to start doing policy-based filtering.
592 A packet can have mutiple tags at the same time.
593 Tags are "sticky", meaning once a tag is applied to a packet by a
594 matching rule it exists until explicit removal.
595 Tags are kept with the packet everywhere within the kernel, but are
596 lost when packet leaves the kernel, for example, on transmitting
597 packet out to the network or sending packet to a
601 To check for previously applied tags, use the
604 To delete previously applied tag, use the
608 Note: since tags are kept with the packet everywhere in kernelspace,
609 they can be set and unset anywhere in kernel network subsystem
612 facility), not only by means of
618 For example, there can be a specialized
620 node doing traffic analyzing and tagging for later inspecting
622 .It Cm untag Ar number
623 When a packet matches a rule with the
625 keyword, the tag with the number
627 is searched among the tags attached to this packet and,
628 if found, removed from it.
629 Other tags bound to packet, if present, are left untouched.
631 When a packet matches a rule with the
633 keyword, the ALTQ identifier for the given
638 Note that this ALTQ tag is only meaningful for packets going "out" of IPFW,
639 and not being rejected or going to divert sockets.
640 Note that if there is insufficient memory at the time the packet is
641 processed, it will not be tagged, so it is wise to make your ALTQ
642 "default" queue policy account for this.
645 rules match a single packet, only the first one adds the ALTQ classification
647 In doing so, traffic may be shaped by using
648 .Cm count Cm altq Ar queue
649 rules for classification early in the ruleset, then later applying
650 the filtering decision.
655 rules may come later and provide the actual filtering decisions in
656 addition to the fallback ALTQ tag.
660 to set up the queues before IPFW will be able to look them up by name,
661 and if the ALTQ disciplines are rearranged, the rules in containing the
662 queue identifiers in the kernel will likely have gone stale and need
664 Stale queue identifiers will probably result in misclassification.
666 All system ALTQ processing can be turned on or off via
671 .Cm disable Ar altq .
673 .Va net.inet.ip.fw.one_pass
674 is irrelevant to ALTQ traffic shaping, as the actual rule action is followed
675 always after adding an ALTQ tag.
678 A rule can be associated with one of the following actions, which
679 will be executed when the packet matches the body of the rule.
680 .Bl -tag -width indent
681 .It Cm allow | accept | pass | permit
682 Allow packets that match rule.
683 The search terminates.
685 Checks the packet against the dynamic ruleset.
686 If a match is found, execute the action associated with
687 the rule which generated this dynamic rule, otherwise
688 move to the next rule.
691 rules do not have a body.
694 rule is found, the dynamic ruleset is checked at the first
700 Update counters for all packets that match rule.
701 The search continues with the next rule.
703 Discard packets that match this rule.
704 The search terminates.
705 .It Cm divert Ar port
706 Divert packets that match this rule to the
710 The search terminates.
711 .It Cm fwd | forward Ar ipaddr | tablearg Ns Op , Ns Ar port
712 Change the next-hop on matching packets to
714 which can be an IP address or a host name.
715 The next hop can also be supplied by the last table
716 looked up for the packet by using the
718 keyword instead of an explicit address.
719 The search terminates if this rule matches.
723 is a local address, then matching packets will be forwarded to
725 (or the port number in the packet if one is not specified in the rule)
726 on the local machine.
730 is not a local address, then the port number
731 (if specified) is ignored, and the packet will be
732 forwarded to the remote address, using the route as found in
733 the local routing table for that IP.
737 rule will not match layer-2 packets (those received
738 on ether_input, ether_output, or bridged).
742 action does not change the contents of the packet at all.
743 In particular, the destination address remains unmodified, so
744 packets forwarded to another system will usually be rejected by that system
745 unless there is a matching rule on that system to capture them.
746 For packets forwarded locally,
747 the local address of the socket will be
748 set to the original destination address of the packet.
751 entry look rather weird but is intended for
752 use with transparent proxy servers.
756 a custom kernel needs to be compiled with the option
757 .Cd "options IPFIREWALL_FORWARD" .
761 (for network address translation, address redirect, etc.):
763 .Sx NETWORK ADDRESS TRANSLATION (NAT)
764 Section for further information.
765 .It Cm pipe Ar pipe_nr
769 (for bandwidth limitation, delay, etc.).
771 .Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
772 Section for further information.
773 The search terminates; however, on exit from the pipe and if
777 .Va net.inet.ip.fw.one_pass
778 is not set, the packet is passed again to the firewall code
779 starting from the next rule.
780 .It Cm queue Ar queue_nr
784 (for bandwidth limitation using WF2Q+).
790 Discard packets that match this rule, and if the
791 packet is a TCP packet, try to send a TCP reset (RST) notice.
792 The search terminates.
794 Discard packets that match this rule, and if the
795 packet is a TCP packet, try to send a TCP reset (RST) notice.
796 The search terminates.
797 .It Cm skipto Ar number | tablearg
798 Skip all subsequent rules numbered less than
800 The search continues with the first rule numbered
803 It is possible to use the
805 keyword with a skipto for a
807 skipto, but care should be used, as no destination caching
808 is possible in this case so the rules are always walked to find it,
812 Send a copy of packets matching this rule to the
816 The search continues with the next rule.
817 .It Cm unreach Ar code
818 Discard packets that match this rule, and try to send an ICMP
819 unreachable notice with code
823 is a number from 0 to 255, or one of these aliases:
824 .Cm net , host , protocol , port ,
825 .Cm needfrag , srcfail , net-unknown , host-unknown ,
826 .Cm isolated , net-prohib , host-prohib , tosnet ,
827 .Cm toshost , filter-prohib , host-precedence
829 .Cm precedence-cutoff .
830 The search terminates.
831 .It Cm unreach6 Ar code
832 Discard packets that match this rule, and try to send an ICMPv6
833 unreachable notice with code
837 is a number from 0, 1, 3 or 4, or one of these aliases:
838 .Cm no-route, admin-prohib, address
841 The search terminates.
842 .It Cm netgraph Ar cookie
843 Divert packet into netgraph with given
845 The search terminates.
846 If packet is later returned from netgraph it is either
847 accepted or continues with the next rule, depending on
848 .Va net.inet.ip.fw.one_pass
850 .It Cm ngtee Ar cookie
851 A copy of packet is diverted into netgraph, original
852 packet is either accepted or continues with the next rule, depending on
853 .Va net.inet.ip.fw.one_pass
857 for more information on
862 .It Cm setfib Ar fibnum
863 The packet is tagged so as to use the FIB (routing table)
865 in any subsequent forwarding decisions. Initially this is
866 limited to the values 0 through 15. See
868 Processing continues at the next rule.
871 The body of a rule contains zero or more patterns (such as
872 specific source and destination addresses or ports,
873 protocol options, incoming or outgoing interfaces, etc.)
874 that the packet must match in order to be recognised.
875 In general, the patterns are connected by (implicit)
877 operators -- i.e., all must match in order for the
879 Individual patterns can be prefixed by the
881 operator to reverse the result of the match, as in
883 .Dl "ipfw add 100 allow ip from not 1.2.3.4 to any"
885 Additionally, sets of alternative match patterns
887 can be constructed by putting the patterns in
888 lists enclosed between parentheses ( ) or braces { }, and
893 .Dl "ipfw add 100 allow ip from { x or not y or z } to any"
895 Only one level of parentheses is allowed.
896 Beware that most shells have special meanings for parentheses
897 or braces, so it is advisable to put a backslash \\ in front of them
898 to prevent such interpretations.
900 The body of a rule must in general include a source and destination
904 can be used in various places to specify that the content of
905 a required field is irrelevant.
907 The rule body has the following format:
908 .Bd -ragged -offset indent
909 .Op Ar proto Cm from Ar src Cm to Ar dst
913 The first part (proto from src to dst) is for backward
914 compatibility with earlier versions of
918 any match pattern (including MAC headers, IP protocols,
919 addresses and ports) can be specified in the
923 Rule fields have the following meaning:
924 .Bl -tag -width indent
925 .It Ar proto : protocol | Cm { Ar protocol Cm or ... }
926 .It Ar protocol : Oo Cm not Oc Ar protocol-name | protocol-number
927 An IP protocol specified by number or name
928 (for a complete list see
929 .Pa /etc/protocols ) ,
930 or one of the following keywords:
931 .Bl -tag -width indent
933 Matches IPv4 packets.
935 Matches IPv6 packets.
944 option will be treated as inner protocol.
952 .Cm { Ar protocol Cm or ... }
955 is provided for convenience only but its use is deprecated.
956 .It Ar src No and Ar dst : Bro Cm addr | Cm { Ar addr Cm or ... } Brc Op Oo Cm not Oc Ar ports
957 An address (or a list, see below)
958 optionally followed by
964 with multiple addresses) is provided for convenience only and
965 its use is discouraged.
966 .It Ar addr : Oo Cm not Oc Bro
968 .Cm table Ns Pq Ar number Ns Op , Ns Ar value
969 .Ar | addr-list | addr-set
972 matches any IP address.
974 matches any IP address configured on an interface in the system.
976 matches any IPv6 address configured on an interface in the system.
977 The address list is evaluated at the time the packet is
979 .It Cm table Ns Pq Ar number Ns Op , Ns Ar value
980 Matches any IPv4 address for which an entry exists in the lookup table
982 If an optional 32-bit unsigned
984 is also specified, an entry will match only if it has this value.
987 section below for more information on lookup tables.
988 .It Ar addr-list : ip-addr Ns Op Ns , Ns Ar addr-list
990 A host or subnet address specified in one of the following ways:
991 .Bl -tag -width indent
992 .It Ar numeric-ip | hostname
993 Matches a single IPv4 address, specified as dotted-quad or a hostname.
994 Hostnames are resolved at the time the rule is added to the firewall list.
995 .It Ar addr Ns / Ns Ar masklen
996 Matches all addresses with base
998 (specified as an IP address, a network number, or a hostname)
1002 As an example, 1.2.3.4/25 or 1.2.3.0/25 will match
1003 all IP numbers from 1.2.3.0 to 1.2.3.127 .
1004 .It Ar addr Ns : Ns Ar mask
1005 Matches all addresses with base
1007 (specified as an IP address, a network number, or a hostname)
1010 specified as a dotted quad.
1011 As an example, 1.2.3.4:255.0.255.0 or 1.0.3.0:255.0.255.0 will match
1013 This form is advised only for non-contiguous
1015 It is better to resort to the
1016 .Ar addr Ns / Ns Ar masklen
1017 format for contiguous masks, which is more compact and less
1020 .It Ar addr-set : addr Ns Oo Ns / Ns Ar masklen Oc Ns Cm { Ns Ar list Ns Cm }
1021 .It Ar list : Bro Ar num | num-num Brc Ns Op Ns , Ns Ar list
1022 Matches all addresses with base address
1024 (specified as an IP address, a network number, or a hostname)
1025 and whose last byte is in the list between braces { } .
1026 Note that there must be no spaces between braces and
1027 numbers (spaces after commas are allowed).
1028 Elements of the list can be specified as single entries
1032 field is used to limit the size of the set of addresses,
1033 and can have any value between 24 and 32.
1035 it will be assumed as 24.
1037 This format is particularly useful to handle sparse address sets
1038 within a single rule.
1039 Because the matching occurs using a
1040 bitmask, it takes constant time and dramatically reduces
1041 the complexity of rulesets.
1043 As an example, an address specified as 1.2.3.4/24{128,35-55,89}
1044 or 1.2.3.0/24{128,35-55,89}
1045 will match the following IP addresses:
1047 1.2.3.128, 1.2.3.35 to 1.2.3.55, 1.2.3.89 .
1048 .It Ar addr6-list : ip6-addr Ns Op Ns , Ns Ar addr6-list
1050 A host or subnet specified one of the following ways:
1052 .Bl -tag -width indent
1053 .It Ar numeric-ip | hostname
1054 Matches a single IPv6 address as allowed by
1057 Hostnames are resolved at the time the rule is added to the firewall
1059 .It Ar addr Ns / Ns Ar masklen
1060 Matches all IPv6 addresses with base
1062 (specified as allowed by
1070 No support for sets of IPv6 addresses is provided because IPv6 addresses
1071 are typically random past the initial prefix.
1072 .It Ar ports : Bro Ar port | port Ns \&- Ns Ar port Ns Brc Ns Op , Ns Ar ports
1073 For protocols which support port numbers (such as TCP and UDP), optional
1075 may be specified as one or more ports or port ranges, separated
1076 by commas but no spaces, and an optional
1081 notation specifies a range of ports (including boundaries).
1085 may be used instead of numeric port values.
1086 The length of the port list is limited to 30 ports or ranges,
1087 though one can specify larger ranges by using an
1091 section of the rule.
1095 can be used to escape the dash
1097 character in a service name (from a shell, the backslash must be
1098 typed twice to avoid the shell itself interpreting it as an escape
1101 .Dl "ipfw add count tcp from any ftp\e\e-data-ftp to any"
1103 Fragmented packets which have a non-zero offset (i.e., not the first
1104 fragment) will never match a rule which has one or more port
1108 option for details on matching fragmented packets.
1110 .Ss RULE OPTIONS (MATCH PATTERNS)
1111 Additional match patterns can be used within
1113 Zero or more of these so-called
1115 can be present in a rule, optionally prefixed by the
1117 operand, and possibly grouped into
1120 The following match patterns can be used (listed in alphabetical order):
1121 .Bl -tag -width indent
1122 .It Cm // this is a comment.
1123 Inserts the specified text as a comment in the rule.
1124 Everything following // is considered as a comment and stored in the rule.
1125 You can have comment-only rules, which are listed as having a
1127 action followed by the comment.
1132 Matches only packets generated by a divert socket.
1133 .It Cm diverted-loopback
1134 Matches only packets coming from a divert socket back into the IP stack
1136 .It Cm diverted-output
1137 Matches only packets going from a divert socket back outward to the IP
1138 stack output for delivery.
1139 .It Cm dst-ip Ar ip-address
1140 Matches IPv4 packets whose destination IP is one of the address(es)
1141 specified as argument.
1142 .It Bro Cm dst-ip6 | dst-ipv6 Brc Ar ip6-address
1143 Matches IPv6 packets whose destination IP is one of the address(es)
1144 specified as argument.
1145 .It Cm dst-port Ar ports
1146 Matches IP packets whose destination port is one of the port(s)
1147 specified as argument.
1149 Matches TCP packets that have the RST or ACK bits set.
1150 .It Cm ext6hdr Ar header
1151 Matches IPv6 packets containing the extended header given by
1153 Supported headers are:
1159 any type of Routing Header
1161 Source routing Routing Header Type 0
1163 Mobile IPv6 Routing Header Type 2
1167 IPSec authentication headers
1169 and IPSec encapsulated security payload headers
1171 .It Cm fib Ar fibnum
1172 Matches a packet that has been tagged to use
1173 the given FIB (routing table) number.
1174 .It Cm flow-id Ar labels
1175 Matches IPv6 packets containing any of the flow labels given in
1178 is a comma seperate list of numeric flow labels.
1180 Matches packets that are fragments and not the first
1181 fragment of an IP datagram.
1182 Note that these packets will not have
1183 the next protocol header (e.g.\& TCP, UDP) so options that look into
1184 these headers cannot match.
1186 Matches all TCP or UDP packets sent by or received for a
1190 may be specified by name or number.
1191 .It Cm jail Ar prisonID
1192 Matches all TCP or UDP packets sent by or received for the
1193 jail whos prison ID is
1195 .It Cm icmptypes Ar types
1196 Matches ICMP packets whose ICMP type is in the list
1198 The list may be specified as any combination of
1199 individual types (numeric) separated by commas.
1200 .Em Ranges are not allowed .
1201 The supported ICMP types are:
1205 destination unreachable
1213 router advertisement
1217 time-to-live exceeded
1229 address mask request
1231 and address mask reply
1233 .It Cm icmp6types Ar types
1234 Matches ICMP6 packets whose ICMP6 type is in the list of
1236 The list may be specified as any combination of
1237 individual types (numeric) separated by commas.
1238 .Em Ranges are not allowed .
1240 Matches incoming or outgoing packets, respectively.
1244 are mutually exclusive (in fact,
1248 .It Cm ipid Ar id-list
1249 Matches IPv4 packets whose
1251 field has value included in
1253 which is either a single value or a list of values or ranges
1254 specified in the same way as
1256 .It Cm iplen Ar len-list
1257 Matches IP packets whose total length, including header and data, is
1260 which is either a single value or a list of values or ranges
1261 specified in the same way as
1263 .It Cm ipoptions Ar spec
1264 Matches packets whose IPv4 header contains the comma separated list of
1265 options specified in
1267 The supported IP options are:
1270 (strict source route),
1272 (loose source route),
1274 (record packet route) and
1277 The absence of a particular option may be denoted
1280 .It Cm ipprecedence Ar precedence
1281 Matches IPv4 packets whose precedence field is equal to
1284 Matches packets that have IPSEC history associated with them
1285 (i.e., the packet comes encapsulated in IPSEC, the kernel
1286 has IPSEC support and IPSEC_FILTERTUNNEL option, and can correctly
1289 Note that specifying
1291 is different from specifying
1293 as the latter will only look at the specific IP protocol field,
1294 irrespective of IPSEC kernel support and the validity of the IPSEC data.
1296 Further note that this flag is silently ignored in kernels without
1298 It does not affect rule processing when given and the
1299 rules are handled as if with no
1302 .It Cm iptos Ar spec
1303 Matches IPv4 packets whose
1305 field contains the comma separated list of
1306 service types specified in
1308 The supported IP types of service are:
1311 .Pq Dv IPTOS_LOWDELAY ,
1313 .Pq Dv IPTOS_THROUGHPUT ,
1315 .Pq Dv IPTOS_RELIABILITY ,
1317 .Pq Dv IPTOS_MINCOST ,
1319 .Pq Dv IPTOS_ECN_CE .
1320 The absence of a particular type may be denoted
1323 .It Cm ipttl Ar ttl-list
1324 Matches IPv4 packets whose time to live is included in
1326 which is either a single value or a list of values or ranges
1327 specified in the same way as
1329 .It Cm ipversion Ar ver
1330 Matches IP packets whose IP version field is
1333 Upon a match, the firewall will create a dynamic rule, whose
1334 default behaviour is to match bidirectional traffic between
1335 source and destination IP/port using the same protocol.
1336 The rule has a limited lifetime (controlled by a set of
1338 variables), and the lifetime is refreshed every time a matching
1341 Matches only layer2 packets, i.e., those passed to
1343 from ether_demux() and ether_output_frame().
1344 .It Cm limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N
1345 The firewall will only allow
1347 connections with the same
1348 set of parameters as specified in the rule.
1350 of source and destination addresses and ports can be
1353 only IPv4 flows are supported.
1354 .It Cm { MAC | mac } Ar dst-mac src-mac
1355 Match packets with a given
1359 addresses, specified as the
1361 keyword (matching any MAC address), or six groups of hex digits
1362 separated by colons,
1363 and optionally followed by a mask indicating the significant bits.
1364 The mask may be specified using either of the following methods:
1365 .Bl -enum -width indent
1369 followed by the number of significant bits.
1370 For example, an address with 33 significant bits could be specified as:
1372 .Dl "MAC 10:20:30:40:50:60/33 any"
1377 followed by a bitmask specified as six groups of hex digits separated
1379 For example, an address in which the last 16 bits are significant could
1382 .Dl "MAC 10:20:30:40:50:60&00:00:00:00:ff:ff any"
1384 Note that the ampersand character has a special meaning in many shells
1385 and should generally be escaped.
1388 Note that the order of MAC addresses (destination first,
1390 the same as on the wire, but the opposite of the one used for
1392 .It Cm mac-type Ar mac-type
1393 Matches packets whose Ethernet Type field
1394 corresponds to one of those specified as argument.
1396 is specified in the same way as
1398 (i.e., one or more comma-separated single values or ranges).
1399 You can use symbolic names for known values such as
1400 .Em vlan , ipv4, ipv6 .
1401 Values can be entered as decimal or hexadecimal (if prefixed by 0x),
1402 and they are always printed as hexadecimal (unless the
1404 option is used, in which case symbolic resolution will be attempted).
1405 .It Cm proto Ar protocol
1406 Matches packets with the corresponding IP protocol.
1407 .It Cm recv | xmit | via Brq Ar ifX | Ar if Ns Cm * | Ar ipno | Ar any
1408 Matches packets received, transmitted or going through,
1409 respectively, the interface specified by exact name
1410 .Ns No ( Ar ifX Ns No ),
1412 .Ns No ( Ar if Ns Ar * Ns No ),
1413 by IP address, or through some interface.
1417 keyword causes the interface to always be checked.
1424 then only the receive or transmit interface (respectively)
1426 By specifying both, it is possible to match packets based on
1427 both receive and transmit interface, e.g.:
1429 .Dl "ipfw add deny ip from any to any out recv ed0 xmit ed1"
1433 interface can be tested on either incoming or outgoing packets,
1436 interface can only be tested on outgoing packets.
1441 is invalid) whenever
1445 A packet may not have a receive or transmit interface: packets
1446 originating from the local host have no receive interface,
1447 while packets destined for the local host have no transmit
1450 Matches TCP packets that have the SYN bit set but no ACK bit.
1451 This is the short form of
1452 .Dq Li tcpflags\ syn,!ack .
1453 .It Cm src-ip Ar ip-address
1454 Matches IPv4 packets whose source IP is one of the address(es)
1455 specified as an argument.
1456 .It Cm src-ip6 Ar ip6-address
1457 Matches IPv6 packets whose source IP is one of the address(es)
1458 specified as an argument.
1459 .It Cm src-port Ar ports
1460 Matches IP packets whose source port is one of the port(s)
1461 specified as argument.
1462 .It Cm tagged Ar tag-list
1463 Matches packets whose tags are included in
1465 which is either a single value or a list of values or ranges
1466 specified in the same way as
1468 Tags can be applied to the packet using
1470 rule action parameter (see it's description for details on tags).
1471 .It Cm tcpack Ar ack
1473 Match if the TCP header acknowledgment number field is set to
1475 .It Cm tcpdatalen Ar tcpdatalen-list
1476 Matches TCP packets whose length of TCP data is
1477 .Ar tcpdatalen-list ,
1478 which is either a single value or a list of values or ranges
1479 specified in the same way as
1481 .It Cm tcpflags Ar spec
1483 Match if the TCP header contains the comma separated list of
1486 The supported TCP flags are:
1495 The absence of a particular flag may be denoted
1498 A rule which contains a
1500 specification can never match a fragmented packet which has
1504 option for details on matching fragmented packets.
1505 .It Cm tcpseq Ar seq
1507 Match if the TCP header sequence number field is set to
1509 .It Cm tcpwin Ar win
1511 Match if the TCP header window field is set to
1513 .It Cm tcpoptions Ar spec
1515 Match if the TCP header contains the comma separated list of
1516 options specified in
1518 The supported TCP options are:
1521 (maximum segment size),
1523 (tcp window advertisement),
1527 (rfc1323 timestamp) and
1529 (rfc1644 t/tcp connection count).
1530 The absence of a particular option may be denoted
1534 Match all TCP or UDP packets sent by or received for a
1538 may be matched by name or identification number.
1540 For incoming packets,
1541 a routing table lookup is done on the packet's source address.
1542 If the interface on which the packet entered the system matches the
1543 outgoing interface for the route,
1545 If the interfaces do not match up,
1546 the packet does not match.
1547 All outgoing packets or packets with no incoming interface match.
1549 The name and functionality of the option is intentionally similar to
1550 the Cisco IOS command:
1552 .Dl ip verify unicast reverse-path
1554 This option can be used to make anti-spoofing rules to reject all
1555 packets with source addresses not from this interface.
1559 For incoming packets,
1560 a routing table lookup is done on the packet's source address.
1561 If a route to the source address exists, but not the default route
1562 or a blackhole/reject route, the packet matches.
1563 Otherwise, the packet does not match.
1564 All outgoing packets match.
1566 The name and functionality of the option is intentionally similar to
1567 the Cisco IOS command:
1569 .Dl ip verify unicast source reachable-via any
1571 This option can be used to make anti-spoofing rules to reject all
1572 packets whose source address is unreachable.
1574 For incoming packets, the packet's source address is checked if it
1575 belongs to a directly connected network.
1576 If the network is directly connected, then the interface the packet
1577 came on in is compared to the interface the network is connected to.
1578 When incoming interface and directly connected interface are not the
1579 same, the packet does not match.
1580 Otherwise, the packet does match.
1581 All outgoing packets match.
1583 This option can be used to make anti-spoofing rules to reject all
1584 packets that pretend to be from a directly connected network but do
1585 not come in through that interface.
1586 This option is similar to but more restricted than
1588 because it engages only on packets with source addresses of directly
1589 connected networks instead of all source addresses.
1592 Lookup tables are useful to handle large sparse address sets,
1593 typically from a hundred to several thousands of entries.
1594 There may be up to 128 different lookup tables, numbered 0 to 127.
1596 Each entry is represented by an
1597 .Ar addr Ns Op / Ns Ar masklen
1598 and will match all addresses with base
1600 (specified as an IP address or a hostname)
1606 is not specified, it defaults to 32.
1607 When looking up an IP address in a table, the most specific
1609 Associated with each entry is a 32-bit unsigned
1611 which can optionally be checked by a rule matching code.
1612 When adding an entry, if
1614 is not specified, it defaults to 0.
1616 An entry can be added to a table
1618 removed from a table
1620 a table can be examined
1625 Internally, each table is stored in a Radix tree, the same way as
1626 the routing table (see
1629 Lookup tables currently support IPv4 addresses only.
1633 feature provides the ability to use a value, looked up in the table, as
1634 the argument for a rule action, action parameter or rule option.
1635 This can significantly reduce number of rules in some configurations.
1636 If two tables are used in a rule, the result of the second (destination)
1640 argument can be used with the following actions:
1641 .Cm nat, pipe , queue, divert, tee, netgraph, ngtee, fwd, skipto
1649 it is possible to supply table entries with values
1650 that are in the form of IP addresses or hostnames.
1653 Section for example usage of tables and the tablearg keyword.
1657 action, the user should be aware that the code will walk the ruleset
1658 up to a rule equal to, or past, the given number, and should therefore try keep the
1659 ruleset compact between the skipto and the target rules.
1661 Each rule belongs to one of 32 different
1664 Set 31 is reserved for the default rule.
1666 By default, rules are put in set 0, unless you use the
1668 attribute when entering a new rule.
1669 Sets can be individually and atomically enabled or disabled,
1670 so this mechanism permits an easy way to store multiple configurations
1671 of the firewall and quickly (and atomically) switch between them.
1672 The command to enable/disable sets is
1673 .Bd -ragged -offset indent
1675 .Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ...
1682 sections can be specified.
1683 Command execution is atomic on all the sets specified in the command.
1684 By default, all sets are enabled.
1686 When you disable a set, its rules behave as if they do not exist
1687 in the firewall configuration, with only one exception:
1688 .Bd -ragged -offset indent
1689 dynamic rules created from a rule before it had been disabled
1690 will still be active until they expire.
1692 dynamic rules you have to explicitly delete the parent rule
1693 which generated them.
1696 The set number of rules can be changed with the command
1697 .Bd -ragged -offset indent
1700 .Brq Cm rule Ar rule-number | old-set
1704 Also, you can atomically swap two rulesets with the command
1705 .Bd -ragged -offset indent
1707 .Cm set swap Ar first-set second-set
1712 Section on some possible uses of sets of rules.
1713 .Sh STATEFUL FIREWALL
1714 Stateful operation is a way for the firewall to dynamically
1715 create rules for specific flows when packets that
1716 match a given pattern are detected.
1717 Support for stateful
1718 operation comes through the
1719 .Cm check-state , keep-state
1725 Dynamic rules are created when a packet matches a
1729 rule, causing the creation of a
1731 rule which will match all and only packets with
1735 .Em src-ip/src-port dst-ip/dst-port
1740 are used here only to denote the initial match addresses, but they
1741 are completely equivalent afterwards).
1742 Dynamic rules will be checked at the first
1743 .Cm check-state, keep-state
1746 occurrence, and the action performed upon a match will be the same
1747 as in the parent rule.
1749 Note that no additional attributes other than protocol and IP addresses
1750 and ports are checked on dynamic rules.
1752 The typical use of dynamic rules is to keep a closed firewall configuration,
1753 but let the first TCP SYN packet from the inside network install a
1754 dynamic rule for the flow so that packets belonging to that session
1755 will be allowed through the firewall:
1757 .Dl "ipfw add check-state"
1758 .Dl "ipfw add allow tcp from my-subnet to any setup keep-state"
1759 .Dl "ipfw add deny tcp from any to any"
1761 A similar approach can be used for UDP, where an UDP packet coming
1762 from the inside will install a dynamic rule to let the response through
1765 .Dl "ipfw add check-state"
1766 .Dl "ipfw add allow udp from my-subnet to any keep-state"
1767 .Dl "ipfw add deny udp from any to any"
1769 Dynamic rules expire after some time, which depends on the status
1770 of the flow and the setting of some
1774 .Sx SYSCTL VARIABLES
1776 For TCP sessions, dynamic rules can be instructed to periodically
1777 send keepalive packets to refresh the state of the rule when it is
1782 for more examples on how to use dynamic rules.
1783 .Sh TRAFFIC SHAPER (DUMMYNET) CONFIGURATION
1785 is also the user interface for the
1790 operates by first using the firewall to classify packets and divide them into
1792 using any match pattern that can be used in
1795 Depending on local policies, a flow can contain packets for a single
1796 TCP connection, or from/to a given host, or entire subnet, or a
1799 There are two modes of
1807 mode tries to emulate a real link: the
1809 scheduler ensures that the packet will not leave the pipe faster than it
1810 would on the real link with a given bandwidth.
1813 mode allows certain packets to bypass the
1815 scheduler (if packet flow does not exceed pipe's bandwidth).
1816 This is the reason why the
1818 mode requires less CPU cycles per packet (on average) and packet latency
1819 can be significantly lower in comparison to a real link with the same
1825 mode can be enabled by setting the
1826 .Va net.inet.ip.dummynet.io_fast
1828 variable to a non-zero value.
1830 Packets belonging to the same flow are then passed to either of two
1831 different objects, which implement the traffic regulation:
1832 .Bl -hang -offset XXXX
1834 A pipe emulates a link with given bandwidth, propagation delay,
1835 queue size and packet loss rate.
1836 Packets are queued in front of the pipe as they come out from the classifier,
1837 and then transferred to the pipe according to the pipe's parameters.
1841 is an abstraction used to implement the WF2Q+
1842 (Worst-case Fair Weighted Fair Queueing) policy, which is
1843 an efficient variant of the WFQ policy.
1845 The queue associates a
1847 and a reference pipe to each flow, and then all backlogged (i.e.,
1848 with packets queued) flows linked to the same pipe share the pipe's
1849 bandwidth proportionally to their weights.
1850 Note that weights are not priorities; a flow with a lower weight
1851 is still guaranteed to get its fraction of the bandwidth even if a
1852 flow with a higher weight is permanently backlogged.
1857 can be used to set hard limits to the bandwidth that a flow can use, whereas
1859 can be used to determine how different flows share the available bandwidth.
1865 configuration commands are the following:
1866 .Bd -ragged -offset indent
1867 .Cm pipe Ar number Cm config Ar pipe-configuration
1869 .Cm queue Ar number Cm config Ar queue-configuration
1872 The following parameters can be configured for a pipe:
1874 .Bl -tag -width indent -compact
1875 .It Cm bw Ar bandwidth | device
1876 Bandwidth, measured in
1879 .Brq Cm bit/s | Byte/s .
1882 A value of 0 (default) means unlimited bandwidth.
1883 The unit must immediately follow the number, as in
1885 .Dl "ipfw pipe 1 config bw 300Kbit/s"
1887 If a device name is specified instead of a numeric value, as in
1889 .Dl "ipfw pipe 1 config bw tun0"
1891 then the transmit clock is supplied by the specified device.
1892 At the moment only the
1894 device supports this
1895 functionality, for use in conjunction with
1898 .It Cm delay Ar ms-delay
1899 Propagation delay, measured in milliseconds.
1900 The value is rounded to the next multiple of the clock tick
1901 (typically 10ms, but it is a good practice to run kernels
1903 .Dq "options HZ=1000"
1905 the granularity to 1ms or less).
1906 Default value is 0, meaning no delay.
1909 The following parameters can be configured for a queue:
1911 .Bl -tag -width indent -compact
1912 .It Cm pipe Ar pipe_nr
1913 Connects a queue to the specified pipe.
1914 Multiple queues (with the same or different weights) can be connected to
1915 the same pipe, which specifies the aggregate rate for the set of queues.
1917 .It Cm weight Ar weight
1918 Specifies the weight to be used for flows matching this queue.
1919 The weight must be in the range 1..100, and defaults to 1.
1922 Finally, the following parameters can be configured for both
1925 .Bl -tag -width XXXX -compact
1927 .It Cm buckets Ar hash-table-size
1928 Specifies the size of the hash table used for storing the
1930 Default value is 64 controlled by the
1933 .Va net.inet.ip.dummynet.hash_size ,
1934 allowed range is 16 to 65536.
1936 .It Cm mask Ar mask-specifier
1937 Packets sent to a given pipe or queue by an
1939 rule can be further classified into multiple flows, each of which is then
1943 A flow identifier is constructed by masking the IP addresses,
1944 ports and protocol types as specified with the
1946 options in the configuration of the pipe or queue.
1947 For each different flow identifier, a new pipe or queue is created
1948 with the same parameters as the original object, and matching packets
1953 are used, each flow will get the same bandwidth as defined by the pipe,
1956 are used, each flow will share the parent's pipe bandwidth evenly
1957 with other flows generated by the same queue (note that other queues
1958 with different weights might be connected to the same pipe).
1960 Available mask specifiers are a combination of one or more of the following:
1962 .Cm dst-ip Ar mask ,
1963 .Cm dst-ip6 Ar mask ,
1964 .Cm src-ip Ar mask ,
1965 .Cm src-ip6 Ar mask ,
1966 .Cm dst-port Ar mask ,
1967 .Cm src-port Ar mask ,
1968 .Cm flow-id Ar mask ,
1973 where the latter means all bits in all fields are significant.
1976 When a packet is dropped by a
1978 queue or pipe, the error
1979 is normally reported to the caller routine in the kernel, in the
1980 same way as it happens when a device queue fills up.
1982 option reports the packet as successfully delivered, which can be
1983 needed for some experimental setups where you want to simulate
1984 loss or congestion at a remote router.
1986 .It Cm plr Ar packet-loss-rate
1989 .Ar packet-loss-rate
1990 is a floating-point number between 0 and 1, with 0 meaning no
1991 loss, 1 meaning 100% loss.
1992 The loss rate is internally represented on 31 bits.
1994 .It Cm queue Brq Ar slots | size Ns Cm Kbytes
1999 Default value is 50 slots, which
2000 is the typical queue size for Ethernet devices.
2001 Note that for slow speed links you should keep the queue
2002 size short or your traffic might be affected by a significant
2004 E.g., 50 max-sized ethernet packets (1500 bytes) mean 600Kbit
2005 or 20s of queue on a 30Kbit/s pipe.
2006 Even worse effects can result if you get packets from an
2007 interface with a much larger MTU, e.g.\& the loopback interface
2008 with its 16KB packets.
2012 .Em net.inet.ip.dummynet.pipe_byte_limit
2014 .Em net.inet.ip.dummynet.pipe_slot_limit
2015 control the maximum lengths that can be specified.
2017 .It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p
2018 Make use of the RED (Random Early Detection) queue management algorithm.
2023 point numbers between 0 and 1 (0 not included), while
2027 are integer numbers specifying thresholds for queue management
2028 (thresholds are computed in bytes if the queue has been defined
2029 in bytes, in slots otherwise).
2032 also supports the gentle RED variant (gred).
2035 variables can be used to control the RED behaviour:
2036 .Bl -tag -width indent
2037 .It Va net.inet.ip.dummynet.red_lookup_depth
2038 specifies the accuracy in computing the average queue
2039 when the link is idle (defaults to 256, must be greater than zero)
2040 .It Va net.inet.ip.dummynet.red_avg_pkt_size
2041 specifies the expected average packet size (defaults to 512, must be
2043 .It Va net.inet.ip.dummynet.red_max_pkt_size
2044 specifies the expected maximum packet size, only used when queue
2045 thresholds are in bytes (defaults to 1500, must be greater than zero).
2049 When used with IPv6 data,
2051 currently has several limitations.
2052 Information necessary to route link-local packets to an
2053 interface is not available after processing by
2055 so those packets are dropped in the output path.
2056 Care should be taken to insure that link-local packets are not passed to
2059 Here are some important points to consider when designing your
2063 Remember that you filter both packets going
2067 Most connections need packets going in both directions.
2069 Remember to test very carefully.
2070 It is a good idea to be near the console when doing this.
2071 If you cannot be near the console,
2072 use an auto-recovery script such as the one in
2073 .Pa /usr/share/examples/ipfw/change_rules.sh .
2075 Do not forget the loopback interface.
2080 There are circumstances where fragmented datagrams are unconditionally
2082 TCP packets are dropped if they do not contain at least 20 bytes of
2083 TCP header, UDP packets are dropped if they do not contain a full 8
2084 byte UDP header, and ICMP packets are dropped if they do not contain
2085 4 bytes of ICMP header, enough to specify the ICMP type, code, and
2087 These packets are simply logged as
2089 since there may not be enough good data in the packet to produce a
2090 meaningful log entry.
2092 Another type of packet is unconditionally dropped, a TCP packet with a
2093 fragment offset of one.
2094 This is a valid packet, but it only has one use, to try
2095 to circumvent firewalls.
2096 When logging is enabled, these packets are
2097 reported as being dropped by rule -1.
2099 If you are logged in over a network, loading the
2103 is probably not as straightforward as you would think.
2104 I recommend the following command line:
2105 .Bd -literal -offset indent
2107 ipfw add 32000 allow ip from any to any
2110 Along the same lines, doing an
2111 .Bd -literal -offset indent
2115 in similar surroundings is also a bad idea.
2119 filter list may not be modified if the system security level
2120 is set to 3 or higher
2123 for information on system security levels).
2125 .Sh PACKET DIVERSION
2128 socket bound to the specified port will receive all packets
2129 diverted to that port.
2130 If no socket is bound to the destination port, or if the divert module is
2131 not loaded, or if the kernel was not compiled with divert socket support,
2132 the packets are dropped.
2133 .Sh NETWORK ADDRESS TRANSLATION (NAT)
2134 The nat configuration command is the following:
2135 .Bd -ragged -offset indent
2140 .Ar nat-configuration
2145 The following parameters can be configured:
2146 .Bl -tag -width indent
2147 .It Cm ip Ar ip_address
2148 Define an ip address to use for aliasing.
2150 Use ip addres of NIC for aliasing, dynamically changing
2151 it if NIC's ip address change.
2153 Enable logging on this nat instance.
2155 Deny any incoming connection from outside world.
2157 Try to leave the alias port numbers unchanged from
2158 the actual local port numbers.
2160 Traffic on the local network not originating from an
2161 unregistered address spaces will be ignored.
2163 Reset table of the packet aliasing engine on address change.
2165 Reverse the way libalias handles aliasing.
2167 Obey transparent proxy rules only, packet aliasing is not performed.
2170 To let the packet continue after being (de)aliased, set the sysctl variable
2171 .Va net.inet.ip.fw.one_pass
2173 For more information about aliasing modes, refer to
2178 for some examples about nat usage.
2179 .Sh REDIRECT AND LSNAT SUPPORT IN IPFW
2180 Redirect and LSNAT support follow closely the syntax used in
2185 for some examples on how to do redirect and lsnat.
2186 .Sh SCTP NAT SUPPORT
2187 Sctp nat can be configured in a simillar manner to TCP through the
2188 ipfw command line tool
2190 , the main difference is that
2193 translation. Since the local and global side ports will be the same,
2194 there is no need to specify both. Ports are redirected as follows:
2195 .Bd -ragged -offset indent
2201 .Cm redirect_port sctp
2202 .Ar ip_address [,addr_list] {[port | port-port] [,ports]}
2209 configuration can be done in real-time through the
2211 interface. All may be changed dynamically, though the hash_table size will only
2215 .Sx SYSCTL VARIABLES
2217 .Sh SYSCTL VARIABLES
2220 variables controls the behaviour of the firewall and
2222 .Pq Nm dummynet , bridge , sctp nat .
2223 These are shown below together with their default value
2224 (but always check with the
2226 command what value is actually in use) and meaning:
2227 .Bl -tag -width indent
2228 .It Va net.inet.ip.alias.sctp.accept_global_ootb_addip: No 0
2231 responds to receipt of global OOTB ASCONF-AddIP:
2232 .Bl -tag -width indent
2234 No response (unless a partially matching association exists -
2235 ports and vtags match but global address does not)
2238 will accept and process all OOTB global AddIP messages.
2241 Option 1 should never be selected as this forms a security risk. An attacker can
2242 establish multiple fake associations by sending AddIP messages.
2243 .It Va net.inet.ip.alias.sctp.chunk_proc_limit: No 5
2244 Defines the maximum number of chunks in an SCTP packet that will be parsed for a
2245 packet that matches an existing association. This value is enforced to be greater or equal
2247 .Cm net.inet.ip.alias.sctp.initialising_chunk_proc_limit .
2249 a DoS risk yet setting too low a value may result in important control chunks in
2250 the packet not being located and parsed.
2251 .It Va net.inet.ip.alias.sctp.error_on_ootb: No 1
2254 responds to any Out-of-the-Blue (OOTB) packets with ErrorM
2255 packets. An OOTB packet is a packet that arrives with no existing association
2258 and is not an INIT or ASCONF-AddIP packet:
2259 .Bl -tag -width indent
2261 ErrorM is never sent in response to OOTB packets.
2263 ErrorM is only sent to OOTB packets received on the local side.
2265 ErrorM is sent to the local side and on the global side ONLY if there is a
2266 partial match (ports and vtags match but the source global IP does not). This
2267 value is only useful if the
2269 is tracking global IP addresses.
2271 ErrorM is sent in response to all OOTB packets on both the local and global side
2275 At the moment the default is 0, since the ErrorM packet is not yet
2276 supported by most SCTP stacks. When it is supported, and if not tracking
2277 global addresses, we recommend setting this value to 1 to allow
2278 multi-homed local hosts to function with the
2280 To track global addresses, we recommend setting this value to 2 to
2281 allow global hosts to be informed when they need to (re)send an
2282 ASCONF-AddIP. Value 3 should never be chosen (except for debugging) as
2285 will respond to all OOTB global packets (a DoS risk).
2286 .It Va net.inet.ip.alias.sctp.hashtable_size: No 2003
2287 Size of hash tables used for
2289 lookups (100 < prime_number > 1000001)
2292 size for any future created
2294 instance and therefore must be set prior to creating a
2297 The table sizes my be changed to suit specific needs. If there will be few
2298 concurrent associations, and memory is scarce, you may make these smaller. If
2299 there will be many thousands (or millions) of concurrent associations, you
2300 should make these larger. A prime number is best for the table size. The sysctl
2301 update function will adjust your input value to the next highest prime number.
2302 .It Va net.inet.ip.alias.sctp.holddown_time: No 0
2303 Hold association in table for this many seconds after receiving a
2304 SHUTDOWN-COMPLETE. This allows endpoints to correct shutdown gracefully if a
2305 shutdown_complete is lost and retransmissions are required.
2306 .It Va net.inet.ip.alias.sctp.init_timer: No 15
2307 Timeout value while waiting for (INIT-ACK|AddIP-ACK).
2308 This value cannot be 0.
2309 .It Va net.inet.ip.alias.sctp.initialising_chunk_proc_limit: No 2
2310 Defines the maximum number of chunks in an SCTP packet that will be parsed when
2311 no existing association exists that matches that packet. Ideally this packet
2312 will only be an INIT or ASCONF-AddIP packet. A higher value may become a DoS
2313 risk as malformed packets can consume processing resources.
2314 .It Va net.inet.ip.alias.sctp.param_proc_limit: No 25
2315 Defines the maximum number of parameters within a chunk that will be parsed in a
2316 packet. As for other similar sysctl variables, larger values pose a DoS risk.
2317 .It Va net.inet.ip.alias.sctp.log_level: No 0
2318 Level of detail in the system log messages (0 \- minimal, 1 \- event,
2319 2 \- info, 3 \- detail, 4 \- debug, 5 \- max debug). May be a good
2320 option in high loss environments.
2321 .It Va net.inet.ip.alias.sctp.shutdown_time: No 15
2322 Timeout value while waiting for SHUTDOWN-COMPLETE.
2323 This value cannot be 0.
2324 .It Va net.inet.ip.alias.sctp.track_global_addresses: No 0
2325 Enables/disables global IP address tracking within the
2328 upper limit on the number of addresses tracked for each association:
2329 .Bl -tag -width indent
2331 Global tracking is disabled
2333 Enables tracking, the maximum number of addresses tracked for each
2334 association is limited to this value
2337 This variable is fully dynamic, the new value will be adopted for all newly
2338 arriving associations, existing association are treated as they were previously.
2339 Global tracking will decrease the number of collisions within the
2342 of increased processing load, memory usage, complexity, and possible
2345 problems in complex networks with multiple
2347 We recommend not tracking
2348 global IP addresses, this will still result in a fully functional
2350 .It Va net.inet.ip.alias.sctp.up_timer: No 300
2351 Timeout value to keep an association up with no traffic.
2352 This value cannot be 0.
2353 .It Va net.inet.ip.dummynet.expire : No 1
2354 Lazily delete dynamic pipes/queue once they have no pending traffic.
2355 You can disable this by setting the variable to 0, in which case
2356 the pipes/queues will only be deleted when the threshold is reached.
2357 .It Va net.inet.ip.dummynet.hash_size : No 64
2358 Default size of the hash table used for dynamic pipes/queues.
2359 This value is used when no
2361 option is specified when configuring a pipe/queue.
2362 .It Va net.inet.ip.dummynet.io_fast : No 0
2363 If set to a non-zero value,
2368 operation (see above) is enabled.
2369 .It Va net.inet.ip.dummynet.io_pkt
2370 Number of packets passed to
2372 .It Va net.inet.ip.dummynet.io_pkt_drop
2373 Number of packets dropped by
2375 .It Va net.inet.ip.dummynet.io_pkt_fast
2376 Number of packets bypassed by the
2379 .It Va net.inet.ip.dummynet.max_chain_len : No 16
2380 Target value for the maximum number of pipes/queues in a hash bucket.
2382 .Cm max_chain_len*hash_size
2383 is used to determine the threshold over which empty pipes/queues
2384 will be expired even when
2385 .Cm net.inet.ip.dummynet.expire=0 .
2386 .It Va net.inet.ip.dummynet.red_lookup_depth : No 256
2387 .It Va net.inet.ip.dummynet.red_avg_pkt_size : No 512
2388 .It Va net.inet.ip.dummynet.red_max_pkt_size : No 1500
2389 Parameters used in the computations of the drop probability
2390 for the RED algorithm.
2391 .It Va net.inet.ip.dummynet.pipe_byte_limit : No 1048576
2392 .It Va net.inet.ip.dummynet.pipe_slot_limit : No 100
2393 The maximum queue size that can be specified in bytes or packets.
2394 These limits prevent accidental exhaustion of resources such as mbufs.
2395 If you raise these limits,
2396 you should make sure the system is configured so that sufficient resources
2398 .It Va net.inet.ip.fw.autoinc_step : No 100
2399 Delta between rule numbers when auto-generating them.
2400 The value must be in the range 1..1000.
2401 .It Va net.inet.ip.fw.curr_dyn_buckets : Va net.inet.ip.fw.dyn_buckets
2402 The current number of buckets in the hash table for dynamic rules
2404 .It Va net.inet.ip.fw.debug : No 1
2405 Controls debugging messages produced by
2407 .It Va net.inet.ip.fw.default_rule : No 65535
2408 The default rule number (read-only).
2410 .Nm , the default rule is the last one, so its number
2411 can also serve as the highest number allowed for a rule.
2412 .It Va net.inet.ip.fw.dyn_buckets : No 256
2413 The number of buckets in the hash table for dynamic rules.
2414 Must be a power of 2, up to 65536.
2415 It only takes effect when all dynamic rules have expired, so you
2416 are advised to use a
2418 command to make sure that the hash table is resized.
2419 .It Va net.inet.ip.fw.dyn_count : No 3
2420 Current number of dynamic rules
2422 .It Va net.inet.ip.fw.dyn_keepalive : No 1
2423 Enables generation of keepalive packets for
2425 rules on TCP sessions.
2426 A keepalive is generated to both
2427 sides of the connection every 5 seconds for the last 20
2428 seconds of the lifetime of the rule.
2429 .It Va net.inet.ip.fw.dyn_max : No 8192
2430 Maximum number of dynamic rules.
2431 When you hit this limit, no more dynamic rules can be
2432 installed until old ones expire.
2433 .It Va net.inet.ip.fw.dyn_ack_lifetime : No 300
2434 .It Va net.inet.ip.fw.dyn_syn_lifetime : No 20
2435 .It Va net.inet.ip.fw.dyn_fin_lifetime : No 1
2436 .It Va net.inet.ip.fw.dyn_rst_lifetime : No 1
2437 .It Va net.inet.ip.fw.dyn_udp_lifetime : No 5
2438 .It Va net.inet.ip.fw.dyn_short_lifetime : No 30
2439 These variables control the lifetime, in seconds, of dynamic
2441 Upon the initial SYN exchange the lifetime is kept short,
2442 then increased after both SYN have been seen, then decreased
2443 again during the final FIN exchange or when a RST is received.
2445 .Em dyn_fin_lifetime
2447 .Em dyn_rst_lifetime
2448 must be strictly lower than 5 seconds, the period of
2449 repetition of keepalives.
2450 The firewall enforces that.
2451 .It Va net.inet.ip.fw.enable : No 1
2452 Enables the firewall.
2453 Setting this variable to 0 lets you run your machine without
2454 firewall even if compiled in.
2455 .It Va net.inet6.ip6.fw.enable : No 1
2456 provides the same functionality as above for the IPv6 case.
2457 .It Va net.inet.ip.fw.one_pass : No 1
2458 When set, the packet exiting from the
2462 node is not passed though the firewall again.
2463 Otherwise, after an action, the packet is
2464 reinjected into the firewall at the next rule.
2465 .It Va net.inet.ip.fw.tables_max : No 128
2466 Maximum number of tables (read-only).
2467 .It Va net.inet.ip.fw.verbose : No 1
2468 Enables verbose messages.
2469 .It Va net.inet.ip.fw.verbose_limit : No 0
2470 Limits the number of messages produced by a verbose firewall.
2471 .It Va net.inet6.ip6.fw.deny_unknown_exthdrs : No 1
2472 If enabled packets with unknown IPv6 Extension Headers will be denied.
2473 .It Va net.link.ether.ipfw : No 0
2474 Controls whether layer-2 packets are passed to
2477 .It Va net.link.bridge.ipfw : No 0
2478 Controls whether bridged packets are passed to
2484 There are far too many possible uses of
2486 so this Section will only give a small set of examples.
2488 .Ss BASIC PACKET FILTERING
2489 This command adds an entry which denies all tcp packets from
2490 .Em cracker.evil.org
2491 to the telnet port of
2493 from being forwarded by the host:
2495 .Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet"
2497 This one disallows any connection from the entire cracker's
2500 .Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org"
2502 A first and efficient way to limit access (not using dynamic rules)
2503 is the use of the following rules:
2505 .Dl "ipfw add allow tcp from any to any established"
2506 .Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup"
2507 .Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup"
2509 .Dl "ipfw add deny tcp from any to any"
2511 The first rule will be a quick match for normal TCP packets,
2512 but it will not match the initial SYN packet, which will be
2515 rules only for selected source/destination pairs.
2516 All other SYN packets will be rejected by the final
2520 If you administer one or more subnets, you can take advantage
2521 of the address sets and or-blocks and write extremely
2522 compact rulesets which selectively enable services to blocks
2523 of clients, as below:
2525 .Dl "goodguys=\*q{ 10.1.2.0/24{20,35,66,18} or 10.2.3.0/28{6,3,11} }\*q"
2526 .Dl "badguys=\*q10.1.2.0/24{8,38,60}\*q"
2528 .Dl "ipfw add allow ip from ${goodguys} to any"
2529 .Dl "ipfw add deny ip from ${badguys} to any"
2530 .Dl "... normal policies ..."
2534 option could be used to do automated anti-spoofing by adding the
2535 following to the top of a ruleset:
2537 .Dl "ipfw add deny ip from any to any not verrevpath in"
2539 This rule drops all incoming packets that appear to be coming to the
2540 system on the wrong interface.
2541 For example, a packet with a source
2542 address belonging to a host on a protected internal network would be
2543 dropped if it tried to enter the system from an external interface.
2547 option could be used to do similar but more restricted anti-spoofing
2548 by adding the following to the top of a ruleset:
2550 .Dl "ipfw add deny ip from any to any not antispoof in"
2552 This rule drops all incoming packets that appear to be coming from another
2553 directly connected system but on the wrong interface.
2554 For example, a packet with a source address of
2562 In order to protect a site from flood attacks involving fake
2563 TCP packets, it is safer to use dynamic rules:
2565 .Dl "ipfw add check-state"
2566 .Dl "ipfw add deny tcp from any to any established"
2567 .Dl "ipfw add allow tcp from my-net to any setup keep-state"
2569 This will let the firewall install dynamic rules only for
2570 those connection which start with a regular SYN packet coming
2571 from the inside of our network.
2572 Dynamic rules are checked when encountering the first
2579 rule should usually be placed near the beginning of the
2580 ruleset to minimize the amount of work scanning the ruleset.
2581 Your mileage may vary.
2583 To limit the number of connections a user can open
2584 you can use the following type of rules:
2586 .Dl "ipfw add allow tcp from my-net/24 to any setup limit src-addr 10"
2587 .Dl "ipfw add allow tcp from any to me setup limit src-addr 4"
2589 The former (assuming it runs on a gateway) will allow each host
2590 on a /24 network to open at most 10 TCP connections.
2591 The latter can be placed on a server to make sure that a single
2592 client does not use more than 4 simultaneous connections.
2595 stateful rules can be subject to denial-of-service attacks
2596 by a SYN-flood which opens a huge number of dynamic rules.
2597 The effects of such attacks can be partially limited by
2600 variables which control the operation of the firewall.
2602 Here is a good usage of the
2604 command to see accounting records and timestamp information:
2608 or in short form without timestamps:
2612 which is equivalent to:
2616 Next rule diverts all incoming packets from 192.168.2.0/24
2617 to divert port 5000:
2619 .Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in
2622 The following rules show some of the applications of
2626 for simulations and the like.
2628 This rule drops random incoming packets with a probability
2631 .Dl "ipfw add prob 0.05 deny ip from any to any in"
2633 A similar effect can be achieved making use of
2637 .Dl "ipfw add pipe 10 ip from any to any"
2638 .Dl "ipfw pipe 10 config plr 0.05"
2640 We can use pipes to artificially limit bandwidth, e.g.\& on a
2641 machine acting as a router, if we want to limit traffic from
2642 local clients on 192.168.2.0/24 we do:
2644 .Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
2645 .Dl "ipfw pipe 1 config bw 300Kbit/s queue 50KBytes"
2647 note that we use the
2649 modifier so that the rule is not used twice.
2650 Remember in fact that
2652 rules are checked both on incoming and outgoing packets.
2654 Should we want to simulate a bidirectional link with bandwidth
2655 limitations, the correct way is the following:
2657 .Dl "ipfw add pipe 1 ip from any to any out"
2658 .Dl "ipfw add pipe 2 ip from any to any in"
2659 .Dl "ipfw pipe 1 config bw 64Kbit/s queue 10Kbytes"
2660 .Dl "ipfw pipe 2 config bw 64Kbit/s queue 10Kbytes"
2662 The above can be very useful, e.g.\& if you want to see how
2663 your fancy Web page will look for a residential user who
2664 is connected only through a slow link.
2665 You should not use only one pipe for both directions, unless
2666 you want to simulate a half-duplex medium (e.g.\& AppleTalk,
2668 It is not necessary that both pipes have the same configuration,
2669 so we can also simulate asymmetric links.
2671 Should we want to verify network performance with the RED queue
2672 management algorithm:
2674 .Dl "ipfw add pipe 1 ip from any to any"
2675 .Dl "ipfw pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1"
2677 Another typical application of the traffic shaper is to
2678 introduce some delay in the communication.
2679 This can significantly affect applications which do a lot of Remote
2680 Procedure Calls, and where the round-trip-time of the
2681 connection often becomes a limiting factor much more than
2684 .Dl "ipfw add pipe 1 ip from any to any out"
2685 .Dl "ipfw add pipe 2 ip from any to any in"
2686 .Dl "ipfw pipe 1 config delay 250ms bw 1Mbit/s"
2687 .Dl "ipfw pipe 2 config delay 250ms bw 1Mbit/s"
2689 Per-flow queueing can be useful for a variety of purposes.
2690 A very simple one is counting traffic:
2692 .Dl "ipfw add pipe 1 tcp from any to any"
2693 .Dl "ipfw add pipe 1 udp from any to any"
2694 .Dl "ipfw add pipe 1 ip from any to any"
2695 .Dl "ipfw pipe 1 config mask all"
2697 The above set of rules will create queues (and collect
2698 statistics) for all traffic.
2699 Because the pipes have no limitations, the only effect is
2700 collecting statistics.
2701 Note that we need 3 rules, not just the last one, because
2704 tries to match IP packets it will not consider ports, so we
2705 would not see connections on separate ports as different
2708 A more sophisticated example is limiting the outbound traffic
2709 on a net with per-host limits, rather than per-network limits:
2711 .Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out"
2712 .Dl "ipfw add pipe 2 ip from any to 192.168.2.0/24 in"
2713 .Dl "ipfw pipe 1 config mask src-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
2714 .Dl "ipfw pipe 2 config mask dst-ip 0x000000ff bw 200Kbit/s queue 20Kbytes"
2716 In the following example, we need to create several traffic bandwidth
2717 classes and we need different hosts/networks to fall into different classes.
2718 We create one pipe for each class and configure them accordingly.
2719 Then we create a single table and fill it with IP subnets and addresses.
2720 For each subnet/host we set the argument equal to the number of the pipe
2722 Then we classify traffic using a single rule:
2724 .Dl "ipfw pipe 1 config bw 1000Kbyte/s"
2725 .Dl "ipfw pipe 4 config bw 4000Kbyte/s"
2727 .Dl "ipfw table 1 add 192.168.2.0/24 1"
2728 .Dl "ipfw table 1 add 192.168.0.0/27 4"
2729 .Dl "ipfw table 1 add 192.168.0.2 1"
2731 .Dl "ipfw add pipe tablearg ip from table(1) to any"
2735 action, the table entries may include hostnames and IP addresses.
2737 .Dl "ipfw table 1 add 192.168.2.0/24 10.23.2.1"
2738 .Dl "ipfw table 1 add 192.168.0.0/27 router1.dmz"
2740 .Dl "ipfw add 100 fwd tablearg ip from any to table(1)"
2742 To add a set of rules atomically, e.g.\& set 18:
2744 .Dl "ipfw set disable 18"
2745 .Dl "ipfw add NN set 18 ... # repeat as needed"
2746 .Dl "ipfw set enable 18"
2748 To delete a set of rules atomically the command is simply:
2750 .Dl "ipfw delete set 18"
2752 To test a ruleset and disable it and regain control if something goes wrong:
2754 .Dl "ipfw set disable 18"
2755 .Dl "ipfw add NN set 18 ... # repeat as needed"
2756 .Dl "ipfw set enable 18; echo done; sleep 30 && ipfw set disable 18"
2758 Here if everything goes well, you press control-C before the "sleep"
2759 terminates, and your ruleset will be left active.
2760 Otherwise, e.g.\& if
2761 you cannot access your box, the ruleset will be disabled after
2762 the sleep terminates thus restoring the previous situation.
2764 To show rules of the specific set:
2766 .Dl "ipfw set 18 show"
2768 To show rules of the disabled set:
2770 .Dl "ipfw -S set 18 show"
2772 To clear a specific rule counters of the specific set:
2774 .Dl "ipfw set 18 zero NN"
2776 To delete a specific rule of the specific set:
2778 .Dl "ipfw set 18 delete NN"
2779 .Ss NAT, REDIRECT AND LSNAT
2780 First redirect all the traffic to nat instance 123:
2782 .Dl "ipfw add nat 123 all from any to any"
2784 Then to configure nat instance 123 to alias all the outgoing traffic with ip
2785 192.168.0.123, blocking all incoming connections, trying to keep
2786 same ports on both sides, clearing aliasing table on address change
2787 and keeping a log of traffic/link statistics:
2789 .Dl "ipfw nat 123 config ip 192.168.0.123 log deny_in reset same_ports"
2791 Or to change address of instance 123, aliasing table will be cleared (see
2794 .Dl "ipfw nat 123 config ip 10.0.0.1"
2796 To see configuration of nat instance 123:
2798 .Dl "ipfw nat 123 show config"
2800 To show logs of all the instances in range 111-999:
2802 .Dl "ipfw nat 111-999 show"
2804 To see configurations of all instances:
2806 .Dl "ipfw nat show config"
2808 Or a redirect rule with mixed modes could looks like:
2810 .Dl "ipfw nat 123 config redirect_addr 10.0.0.1 10.0.0.66"
2811 .Dl " redirect_port tcp 192.168.0.1:80 500"
2812 .Dl " redirect_proto udp 192.168.1.43 192.168.1.1"
2813 .Dl " redirect_addr 192.168.0.10,192.168.0.11"
2814 .Dl " 10.0.0.100 # LSNAT"
2815 .Dl " redirect_port tcp 192.168.0.1:80,192.168.0.10:22"
2818 or it could be splitted in:
2820 .Dl "ipfw nat 1 config redirect_addr 10.0.0.1 10.0.0.66"
2821 .Dl "ipfw nat 2 config redirect_port tcp 192.168.0.1:80 500"
2822 .Dl "ipfw nat 3 config redirect_proto udp 192.168.1.43 192.168.1.1"
2823 .Dl "ipfw nat 4 config redirect_addr 192.168.0.10,192.168.0.11,192.168.0.12"
2825 .Dl "ipfw nat 5 config redirect_port tcp"
2826 .Dl " 192.168.0.1:80,192.168.0.10:22,192.168.0.20:25 500"
2848 utility first appeared in
2853 Stateful extensions were introduced in
2856 was introduced in Summer 2002.
2858 .An Ugen J. S. Antsilevich ,
2859 .An Poul-Henning Kamp ,
2865 API based upon code written by
2870 In-kernel NAT support written by
2871 .An Paolo Pisati Aq piso@FreeBSD.org
2872 as part of a Summer of Code 2005 project.
2876 traffic shaper supported by Akamba Corp.
2880 support has been developed by
2881 .An The Centre for Advanced Internet Architectures (CAIA) Aq http://www.caia.swin.edu.au .
2882 The primary developers and maintainers are David Hayes and Jason But.
2883 For further information visit:
2884 .Aq http://www.caia.swin.edu.au/urp/SONATA
2887 The syntax has grown over the years and sometimes it might be confusing.
2888 Unfortunately, backward compatibility prevents cleaning up mistakes
2889 made in the definition of the syntax.
2893 Misconfiguring the firewall can put your computer in an unusable state,
2894 possibly shutting down network services and requiring console access to
2895 regain control of it.
2897 Incoming packet fragments diverted by
2899 are reassembled before delivery to the socket.
2900 The action used on those packet is the one from the
2901 rule which matches the first fragment of the packet.
2903 Packets diverted to userland, and then reinserted by a userland process
2904 may lose various packet attributes.
2905 The packet source interface name
2906 will be preserved if it is shorter than 8 bytes and the userland process
2907 saves and reuses the sockaddr_in
2910 otherwise, it may be lost.
2911 If a packet is reinserted in this manner, later rules may be incorrectly
2912 applied, making the order of
2914 rules in the rule sequence very important.
2916 Dummynet drops all packets with IPv6 link-local addresses.
2922 may not behave as expected.
2923 In particular, incoming SYN packets may
2924 have no uid or gid associated with them since they do not yet belong
2925 to a TCP connection, and the uid/gid associated with a packet may not
2926 be as expected if the associated process calls
2928 or similar system calls.
2930 Rule syntax is subject to the command line environment and some patterns
2931 may need to be escaped with the backslash character
2932 or quoted appropriately.
2934 Due to the architecture of
2936 ipfw nat is not compatible with the tcp segmentation offloading
2937 (TSO). Thus, to reliably nat your network traffic, please disable TSO
2941 ICMP error messages are not implicitly matched by dynamic rules
2942 for the respective conversations.
2943 To avoid failures of network error detection and path MTU discovery,
2944 ICMP error messages may need to be allowed explicitly through static