]> git.saurik.com Git - apple/network_cmds.git/blame - ipfw.tproj/ipfw.8
network_cmds-176.3.1.tar.gz
[apple/network_cmds.git] / ipfw.tproj / ipfw.8
CommitLineData
ac2f15b3 1.Dd July 2, 2003
7ba0088d
A
2.Dt IPFW 8
3.Os Darwin
b7080c8e
A
4.Sh NAME
5.Nm ipfw
7ba0088d 6.Nd IP firewall and traffic shaper control program
b7080c8e 7.Sh SYNOPSIS
7ba0088d 8.Nm
b7080c8e
A
9.Op Fl q
10.Oo
11.Fl p Ar preproc
7ba0088d
A
12.Oo Fl D
13.Ar macro Ns Op = Ns Ar value
b7080c8e 14.Oc
7ba0088d 15.Op Fl U Ar macro
b7080c8e 16.Oc
7ba0088d
A
17.Ar pathname
18.Nm
19.Op Fl f | q
20.Cm flush
21.Nm
22.Op Fl q
23.Es \&{ \&}
24.En Cm zero | resetlog | delete
b7080c8e 25.Op Ar number ...
7ba0088d
A
26.Nm
27.Op Fl s Op Ar field
b7080c8e 28.Op Fl aftN
7ba0088d
A
29.Es \&{ \&}
30.En Cm list | show
b7080c8e 31.Op Ar number ...
7ba0088d
A
32.Nm
33.Op Fl q
34.Cm add
b7080c8e 35.Op Ar number
7ba0088d 36.Ar rule-body
b7080c8e 37.Sh DESCRIPTION
b7080c8e 38.Nm
7ba0088d
A
39is the user interface for controlling the
40.Xr ipfirewall 4
ac2f15b3 41.
7ba0088d
A
42.Pp
43Each incoming or outgoing packet is passed through the
44.Nm
45rules.
ac2f15b3 46If the host is acting as a gateway, packets forwarded by
7ba0088d
A
47the gateway are processed by
48.Nm
49twice.
ac2f15b3 50When the host is acting as a bridge, packets forwarded by
7ba0088d
A
51the bridge are processed by
52.Nm
53once.
54.Pp
55A firewall configuration is made of a list of numbered rules,
56which is scanned for each packet until a match is found and
57the relevant action is performed.
58Depending on the action and certain system settings, packets
59can be reinjected into the firewall at the rule after the
60matching one for further processing.
61All rules apply to all interfaces, so it is responsibility
62of the system administrator to write the ruleset in such a
63way as to minimize the number of checks.
64.Pp
65A configuration always includes a
66.Em DEFAULT
67rule (numbered 65535) which cannot be modified by the programmer
68and always matches packets.
69The action associated with the default rule can be either
70.Cm deny
71or
72.Cm allow
73depending on how the kernel is configured.
74.Pp
75If the ruleset includes one or more rules with the
76.Cm keep-state
77option, then
78.Nm
79assumes a
80.Em stateful
81behaviour, i.e. upon a match will create dynamic rules matching
82the exact parameters (addresses and ports) of the matching packet.
83.Pp
84These dynamic rules, which have a limited lifetime, are checked
85at the first occurrence of a
86.Cm check-state
87or
88.Cm keep-state
89rule, and are typically used to open the firewall on-demand to
90legitimate traffic only.
91See the
92.Sx RULE FORMAT
93and
94.Sx EXAMPLES
95sections below for more information on the stateful behaviour of
96.Nm .
97.Pp
98All rules (including dynamic ones) have a few associated counters:
99a packet count, a byte count, a log count and a timestamp
100indicating the time of the last match.
101Counters can be displayed or reset with
102.Nm
103commands.
104.Pp
105Rules can be added with the
106.Cm add
107command; deleted individually with the
108.Cm delete
109command, and globally with the
110.Cm flush
111command; displayed, optionally with the content of the
112counters, using the
113.Cm show
114and
115.Cm list
116commands.
117Finally, counters can be reset with the
118.Cm zero
119and
120.Cm resetlog
121commands.
122.Pp
123The following options are available:
124.Bl -tag -width indent
125.It Fl a
126While listing, show counter values.
127See also the
128.Cm show
b7080c8e 129command.
7ba0088d
A
130.It Fl f
131Don't ask for confirmation for commands that can cause problems
132if misused,
133.No i.e. Cm flush .
134.Em Note ,
135if there is no tty associated with the process, this is implied.
136.It Fl q
137While
138.Cm add Ns ing ,
139.Cm zero Ns ing ,
140.Cm resetlog Ns ging
141or
142.Cm flush Ns ing ,
143be quiet about actions
144(implies
145.Fl f ) .
146This is useful for adjusting rules by executing multiple
147.Nm
148commands in a script
149(e.g.,
150.Ql sh\ /etc/rc.firewall ) ,
151or by processing a file of many
152.Nm
153rules,
154across a remote login session.
155If a
156.Cm flush
157is performed in normal (verbose) mode (with the default kernel
158configuration), it prints a message.
159Because all rules are flushed, the message cannot be delivered
160to the login session.
161This causes the remote login session to be closed and the
162remainder of the ruleset is not processed.
163Access to the console is required to recover.
164.It Fl t
165While listing, show last match timestamp.
166.It Fl N
167Try to resolve addresses and service names in output.
7ba0088d
A
168.El
169.Pp
170To ease configuration, rules can be put into a file which is
171processed using
172.Nm
173as shown in the first synopsis line.
174An absolute
175.Ar pathname
176must be used.
177The file
178will be read line by line and applied as arguments to the
179.Nm
180utility.
b7080c8e
A
181.Pp
182Optionally, a preprocessor can be specified using
183.Fl p Ar preproc
184where
7ba0088d
A
185.Ar pathname
186is to be piped through.
187Useful preprocessors include
b7080c8e
A
188.Xr cpp 1
189and
190.Xr m4 1 .
191If
192.Ar preproc
7ba0088d
A
193doesn't start with a slash
194.Pq Ql /
195as its first character, the usual
b7080c8e 196.Ev PATH
7ba0088d
A
197name search is performed.
198Care should be taken with this in environments where not all
199filesystems are mounted (yet) by the time
b7080c8e 200.Nm
7ba0088d
A
201is being run (e.g. when they are mounted over NFS).
202Once
b7080c8e
A
203.Fl p
204has been specified, optional
205.Fl D
206and
207.Fl U
208specifications can follow and will be passed on to the preprocessor.
209This allows for flexible configuration files (like conditionalizing
210them on the local hostname) and the use of macros to centralize
211frequently required arguments like IP addresses.
7ba0088d 212.Sh RULE FORMAT
b7080c8e
A
213The
214.Nm
7ba0088d
A
215rule format is the following:
216.Bd -ragged
217.Op Cm prob Ar match_probability
218.Ar action
219.Op Cm log Op Cm logamount Ar number
220.Ar proto
221.Cm from Ar src
222.Cm to Ar dst
223.Op Ar interface-spec
224.Op Ar options
b7080c8e
A
225.Ed
226.Pp
7ba0088d
A
227Each packet can be filtered based on the following information that is
228associated with it:
b7080c8e 229.Pp
7ba0088d
A
230.Bl -tag -width "Source and destination IP address" -offset indent -compact
231.It Transmit and receive interface
232(by name or address)
233.It Direction
234(incoming or outgoing)
235.It Source and destination IP address
236(possibly masked)
237.It Protocol
238(TCP, UDP, ICMP, etc.)
239.It Source and destination port
240(lists, ranges or masks)
241.It TCP flags
242.It IP fragment flag
243.It IP options
244.It ICMP types
ac2f15b3 245.It User ID of the socket associated with the packet
b7080c8e
A
246.El
247.Pp
7ba0088d
A
248Note that it may be dangerous to filter on the source IP
249address or source TCP/UDP port because either or both could
250easily be spoofed.
251.Bl -tag -width indent
252.It Cm prob Ar match_probability
253A match is only declared with the specified probability
254(floating point number between 0 and 1).
255This can be useful for a number of applications such as
ac2f15b3 256random packet drop.
7ba0088d
A
257.It Ar action :
258.Bl -tag -width indent
259.It Cm allow
b7080c8e 260Allow packets that match rule.
7ba0088d
A
261The search terminates.
262Aliases are
263.Cm pass ,
264.Cm permit
b7080c8e 265and
7ba0088d
A
266.Cm accept .
267.It Cm deny
b7080c8e
A
268Discard packets that match this rule.
269The search terminates.
7ba0088d 270.Cm drop
b7080c8e 271is an alias for
7ba0088d
A
272.Cm deny .
273.It Cm reject
274(Deprecated).
275Discard packets that match this rule, and try to send an ICMP
b7080c8e
A
276host unreachable notice.
277The search terminates.
7ba0088d 278.It Cm unreach Ar code
b7080c8e
A
279Discard packets that match this rule, and try to send an ICMP
280unreachable notice with code
281.Ar code ,
282where
283.Ar code
7ba0088d
A
284is a number from 0 to 255, or one of these aliases:
285.Cm net , host , protocol , port ,
286.Cm needfrag , srcfail , net-unknown , host-unknown ,
287.Cm isolated , net-prohib , host-prohib , tosnet ,
288.Cm toshost , filter-prohib , host-precedence
b7080c8e 289or
7ba0088d 290.Cm precedence-cutoff .
b7080c8e 291The search terminates.
7ba0088d
A
292.It Cm reset
293TCP packets only.
294Discard packets that match this rule, and try to send a TCP
295reset (RST) notice.
b7080c8e 296The search terminates.
7ba0088d 297.It Cm count
b7080c8e
A
298Update counters for all packets that match rule.
299The search continues with the next rule.
7ba0088d
A
300.It Cm check-state
301Checks the packet against the dynamic ruleset.
302If a match is found then the search terminates, otherwise
303we move to the next rule.
304If no
305.Cm check-state
306rule is found, the dynamic ruleset is checked at the first
307.Cm keep-state
308rule.
309.It Cm divert Ar port
b7080c8e
A
310Divert packets that match this rule to the
311.Xr divert 4
312socket bound to port
313.Ar port .
314The search terminates.
7ba0088d 315.It Cm tee Ar port
b7080c8e
A
316Send a copy of packets matching this rule to the
317.Xr divert 4
318socket bound to port
319.Ar port .
7ba0088d
A
320The search terminates and the original packet is accepted
321(but see section
322.Sx BUGS
323below).
324.It Cm fwd Ar ipaddr Ns Xo
325.Op , Ns Ar port
326.Xc
b7080c8e
A
327Change the next-hop on matching packets to
328.Ar ipaddr ,
329which can be an IP address in dotted quad or a host name.
330If
331.Ar ipaddr
7ba0088d
A
332is not a directly-reachable address, the route as found in
333the local routing table for that IP is used instead.
b7080c8e
A
334If
335.Ar ipaddr
7ba0088d
A
336is a local address, then on a packet entering the system
337from a remote host it will be diverted to
b7080c8e 338.Ar port
7ba0088d
A
339on the local machine, keeping the local address of the socket
340set to the original IP address the packet was destined for.
341This is intended for use with transparent proxy servers.
342If the IP is not a local address then the port number
343(if specified) is ignored and the rule only applies to packets
344leaving the system.
345This will also map addresses to local ports when packets are
346generated locally.
347The search terminates if this rule matches.
348If the port number is not given then the port number in the
349packet is used, so that a packet for an external machine port
350Y would be forwarded to local port Y.
351The kernel must have been compiled with the
352.Dv IPFIREWALL_FORWARD
353option.
7ba0088d 354.It Cm skipto Ar number
b7080c8e
A
355Skip all subsequent rules numbered less than
356.Ar number .
357The search continues with the first rule numbered
358.Ar number
359or higher.
360.El
7ba0088d 361.It Cm log Op Cm logamount Ar number
b7080c8e
A
362If the kernel was compiled with
363.Dv IPFIREWALL_VERBOSE ,
364then when a packet matches a rule with the
7ba0088d
A
365.Cm log
366keyword a message will be
367logged to
368.Xr syslogd 8
369with a
ac2f15b3 370.Dv LOG_AUTHPRIV
7ba0088d
A
371facility.
372.Em Note :
373by default, they are appended to the
ac2f15b3 374.Pa /var/log/system.log
7ba0088d
A
375file (see
376.Xr syslog.conf 5 ) .
b7080c8e
A
377If the kernel was compiled with the
378.Dv IPFIREWALL_VERBOSE_LIMIT
7ba0088d
A
379option, then by default logging will cease after the number
380of packets specified by the option are received for that
381particular chain entry, and
382.Em net.inet.ip.fw.verbose_limit
383will be set to that number.
384However, if
385.Cm logamount Ar number
386is used, that
387.Ar number
388will be the logging limit rather than
389.Em net.inet.ip.fw.verbose_limit ,
390where the value
391.Dq 0
392removes the logging limit.
393Logging may then be re-enabled by clearing the logging counter
394or the packet counter for that entry.
b7080c8e
A
395.Pp
396Console logging and the log limit are adjustable dynamically
397through the
398.Xr sysctl 8
7ba0088d
A
399interface in the MIB base of
400.Em net.inet.ip.fw .
401.It Ar proto
402An IP protocol specified by number or name (for a complete
403list see
404.Pa /etc/protocols ) .
405The
406.Cm ip
407or
408.Cm all
409keywords mean any protocol will match.
410.It Ar src No and Ar dst :
411.Cm any | me | Op Cm not
412.Aq Ar address Ns / Ns Ar mask
413.Op Ar ports
b7080c8e 414.Pp
7ba0088d
A
415Specifying
416.Cm any
417makes the rule match any IP number.
b7080c8e 418.Pp
7ba0088d
A
419Specifying
420.Cm me
421makes the rule match any IP number configured on an interface in the system.
422This is a computationally semi-expensive check which should be used with care.
b7080c8e
A
423.Pp
424The
7ba0088d 425.Aq Ar address Ns / Ns Ar mask
b7080c8e 426may be specified as:
7ba0088d 427.Bl -tag -width "ipno/bits"
b7080c8e 428.It Ar ipno
7ba0088d
A
429An IP number of the form 1.2.3.4.
430Only this exact IP number will match the rule.
431.It Ar ipno Ns / Ns Ar bits
432An IP number with a mask width of the form 1.2.3.4/24.
433In this case all IP numbers from 1.2.3.0 to 1.2.3.255 will match.
434.It Ar ipno Ns : Ns Ar mask
435An IP number with a mask of the form 1.2.3.4:255.255.240.0.
436In this case all IP numbers from 1.2.0.0 to 1.2.15.255 will match.
b7080c8e
A
437.El
438.Pp
439The sense of the match can be inverted by preceding an address with the
7ba0088d
A
440.Cm not
441modifier, causing all other addresses to be matched instead.
442This does not affect the selection of port numbers.
b7080c8e
A
443.Pp
444With the TCP and UDP protocols, optional
445.Em ports
446may be specified as:
7ba0088d
A
447.Bd -ragged -offset indent
448.Sm off
449.Eo \&{
450.Ar port |
451.Ar port No \&- Ar port |
452.Ar port : mask
453.Ec \&} Op , Ar port Op , Ar ...
454.Sm on
455.Ed
b7080c8e 456.Pp
7ba0088d
A
457The
458.Ql \&-
459notation specifies a range of ports (including boundaries).
460.Pp
461The
462.Ql \&:
463notation specifies a port and a mask, a match is declared if
464the port number in the packet matches the one in the rule,
465limited to the bits which are set in the mask.
b7080c8e 466.Pp
7ba0088d 467Service names (from
b7080c8e
A
468.Pa /etc/services )
469may be used instead of numeric port values.
7ba0088d
A
470A range may only be specified as the first value, and the
471length of the port list is limited to
b7080c8e 472.Dv IP_FW_MAX_PORTS
7ba0088d
A
473ports (as defined in
474.Pa /usr/src/sys/netinet/ip_fw.h ) .
475A backslash
476.Pq Ql \e
477can be used to escape the dash
478.Pq Ql -
479character in a service name:
480.Pp
481.Dl "ipfw add count tcp from any ftp\e\e-data-ftp to any"
b7080c8e
A
482.Pp
483Fragmented packets which have a non-zero offset (i.e. not the first
484fragment) will never match a rule which has one or more port
7ba0088d
A
485specifications.
486See the
487.Cm frag
b7080c8e 488option for details on matching fragmented packets.
7ba0088d
A
489.It Ar interface-spec
490Some combinations of the following specifiers are allowed:
491.Bl -tag -width "via ipno"
492.It Cm in
493Only match incoming packets.
494.It Cm out
495Only match outgoing packets.
496.It Cm via Ar ifX
b7080c8e 497Packet must be going through interface
7ba0088d
A
498.Ar ifX .
499.It Cm via Ar if Ns Cm *
b7080c8e
A
500Packet must be going through interface
501.Ar ifX ,
7ba0088d
A
502where
503.Ar X
504is any unit number.
505.It Cm via any
b7080c8e
A
506Packet must be going through
507.Em some
508interface.
7ba0088d 509.It Cm via Ar ipno
b7080c8e
A
510Packet must be going through the interface having IP address
511.Ar ipno .
512.El
513.Pp
514The
7ba0088d 515.Cm via
b7080c8e
A
516keyword causes the interface to always be checked.
517If
7ba0088d 518.Cm recv
b7080c8e 519or
7ba0088d 520.Cm xmit
b7080c8e 521is used instead of
7ba0088d
A
522.Cm via ,
523then the only receive or transmit interface (respectively)
524is checked.
525By specifying both, it is possible to match packets based on
526both receive and transmit interface, e.g.:
b7080c8e
A
527.Pp
528.Dl "ipfw add 100 deny ip from any to any out recv ed0 xmit ed1"
529.Pp
530The
7ba0088d
A
531.Cm recv
532interface can be tested on either incoming or outgoing packets,
533while the
534.Cm xmit
535interface can only be tested on outgoing packets.
536So
537.Cm out
b7080c8e 538is required (and
7ba0088d
A
539.Cm in
540is invalid) whenever
541.Cm xmit
542is used.
543Specifying
544.Cm via
b7080c8e 545together with
7ba0088d 546.Cm xmit
b7080c8e 547or
7ba0088d 548.Cm recv
b7080c8e
A
549is invalid.
550.Pp
7ba0088d
A
551A packet may not have a receive or transmit interface: packets
552originating from the local host have no receive interface,
553while packets destined for the local host have no transmit
554interface.
555.It Ar options :
556.Bl -tag -width indent
557.It Cm keep-state Op Ar method
558Upon a match, the firewall will create a dynamic rule, whose
559default behaviour is to matching bidirectional traffic between
560source and destination IP/port using the same protocol.
561The rule has a limited lifetime (controlled by a set of
562.Xr sysctl 8
563variables), and the lifetime is refreshed every time a matching
564packet is found.
565.Pp
566The actual behaviour can be modified by specifying a different
567.Ar method ,
568although at the moment only the default one is specified.
569.It Cm bridged
570Matches only bridged packets.
571This can be useful for multicast or broadcast traffic, which
572would otherwise pass through the firewall twice: once during
573bridging, and a second time when the packet is delivered to
574the local stack.
7ba0088d
A
575.It Cm frag
576Match if the packet is a fragment and this is not the first
577fragment of the datagram.
578.Cm frag
b7080c8e 579may not be used in conjunction with either
7ba0088d 580.Cm tcpflags
b7080c8e 581or TCP/UDP port specifications.
7ba0088d
A
582.It Cm ipoptions Ar spec
583Match if the IP header contains the comma separated list of
b7080c8e
A
584options specified in
585.Ar spec .
586The supported IP options are:
7ba0088d
A
587.Pp
588.Cm ssrr
b7080c8e 589(strict source route),
7ba0088d 590.Cm lsrr
b7080c8e 591(loose source route),
7ba0088d
A
592.Cm rr
593(record packet route) and
594.Cm ts
b7080c8e
A
595(timestamp).
596The absence of a particular option may be denoted
597with a
7ba0088d
A
598.Ql \&! .
599.It Cm tcpoptions Ar spec
600Match if the TCP header contains the comma separated list of
601options specified in
602.Ar spec .
603The supported TCP options are:
604.Pp
605.Cm mss
606(maximum segment size),
607.Cm window
608(tcp window advertisement),
609.Cm sack
610(selective ack),
611.Cm ts
612(rfc1323 timestamp) and
613.Cm cc
614(rfc1644 t/tcp connection count).
615The absence of a particular option may be denoted
616with a
617.Ql \&! .
618.It Cm established
619TCP packets only.
620Match packets that have the RST or ACK bits set.
621.It Cm setup
b7080c8e 622TCP packets only.
7ba0088d
A
623Match packets that have the SYN bit set but no ACK bit.
624.It Cm tcpflags Ar spec
b7080c8e 625TCP packets only.
7ba0088d 626Match if the TCP header contains the comma separated list of
b7080c8e
A
627flags specified in
628.Ar spec .
629The supported TCP flags are:
7ba0088d
A
630.Pp
631.Cm fin ,
632.Cm syn ,
633.Cm rst ,
634.Cm psh ,
635.Cm ack
b7080c8e 636and
7ba0088d 637.Cm urg .
b7080c8e
A
638The absence of a particular flag may be denoted
639with a
7ba0088d 640.Ql \&! .
b7080c8e 641A rule which contains a
7ba0088d 642.Cm tcpflags
b7080c8e 643specification can never match a fragmented packet which has
7ba0088d
A
644a non-zero offset.
645See the
646.Cm frag
b7080c8e 647option for details on matching fragmented packets.
7ba0088d
A
648.It Cm icmptypes Ar types
649ICMP packets only.
650Match if the ICMP type is in the list
b7080c8e 651.Ar types .
7ba0088d
A
652The list may be specified as any combination of ranges or
653individual types separated by commas.
654The supported ICMP types are:
655.Pp
656echo reply
657.Pq Cm 0 ,
658destination unreachable
659.Pq Cm 3 ,
660source quench
661.Pq Cm 4 ,
662redirect
663.Pq Cm 5 ,
664echo request
665.Pq Cm 8 ,
666router advertisement
667.Pq Cm 9 ,
668router solicitation
669.Pq Cm 10 ,
670time-to-live exceeded
671.Pq Cm 11 ,
672IP header bad
673.Pq Cm 12 ,
674timestamp request
675.Pq Cm 13 ,
676timestamp reply
677.Pq Cm 14 ,
678information request
679.Pq Cm 15 ,
680information reply
681.Pq Cm 16 ,
682address mask request
683.Pq Cm 17
684and address mask reply
685.Pq Cm 18 .
686.It Cm uid Ar user
687Match all TCP or UDP packets sent by or received for a
688.Ar user .
689A
690.Ar user
691may be matched by name or identification number.
7ba0088d 692.El
b7080c8e
A
693.El
694.Sh CHECKLIST
695Here are some important points to consider when designing your
696rules:
7ba0088d
A
697.Bl -bullet
698.It
699Remember that you filter both packets going
700.Cm in
701and
702.Cm out .
b7080c8e
A
703Most connections need packets going in both directions.
704.It
705Remember to test very carefully.
706It is a good idea to be near the console when doing this.
7ba0088d 707If you cannot be near the console,
ac2f15b3 708use an auto-recovery script.
b7080c8e
A
709.It
710Don't forget the loopback interface.
711.El
712.Sh FINE POINTS
7ba0088d
A
713.Bl -bullet
714.It
715There is one kind of packet that the firewall will always
716discard, that is a TCP packet's fragment with a fragment offset of
717one.
718This is a valid packet, but it only has one use, to try
719to circumvent firewalls.
720When logging is enabled, these packets are
721reported as being dropped by rule -1.
722.It
7ba0088d
A
723The
724.Nm
725filter list may not be modified if the system security level
b7080c8e 726is set to 3 or higher
7ba0088d 727(see
b7080c8e 728.Xr init 8
7ba0088d
A
729for information on system security levels).
730.El
b7080c8e 731.Sh PACKET DIVERSION
7ba0088d
A
732A
733.Xr divert 4
734socket bound to the specified port will receive all packets
735diverted to that port.
b7080c8e 736If no socket is bound to the destination port, or if the kernel
7ba0088d
A
737wasn't compiled with divert socket support, the packets are
738dropped.
739.Sh SYSCTL VARIABLES
740A set of
741.Xr sysctl 8
742variables controls the behaviour of the firewall.
743These are shown below together with their default value and
744meaning:
745.Bl -tag -width indent
746.It Em net.inet.ip.fw.debug : No 1
747Controls debugging messages produced by
748.Nm .
7ba0088d
A
749.It Em net.inet.ip.fw.verbose : No 1
750Enables verbose messages.
751.It Em net.inet.ip.fw.enable : No 1
752Enables the firewall.
753Setting this variable to 0 lets you run your machine without
754firewall even if compiled in.
755.It Em net.inet.ip.fw.verbose_limit : No 0
756Limits the number of messages produced by a verbose firewall.
757.It Em net.inet.ip.fw.dyn_buckets : No 256
758.It Em net.inet.ip.fw.curr_dyn_buckets : No 256
759The configured and current size of the hash table used to
760hold dynamic rules.
761This must be a power of 2.
762The table can only be resized when empty, so in order to
763resize it on the fly you will probably have to
764.Cm flush
765and reload the ruleset.
766.It Em net.inet.ip.fw.dyn_count : No 3
767Current number of dynamic rules
768(read-only).
769.It Em net.inet.ip.fw.dyn_max : No 1000
770Maximum number of dynamic rules.
771When you hit this limit, no more dynamic rules can be
772installed until old ones expire.
773.It Em net.inet.ip.fw.dyn_ack_lifetime : No 300
774.It Em net.inet.ip.fw.dyn_syn_lifetime : No 20
775.It Em net.inet.ip.fw.dyn_fin_lifetime : No 20
776.It Em net.inet.ip.fw.dyn_rst_lifetime : No 5
777.It Em net.inet.ip.fw.dyn_short_lifetime : No 30
778These variables control the lifetime, in seconds, of dynamic
779rules.
780Upon the initial SYN exchange the lifetime is kept short,
781then increased after both SYN have been seen, then decreased
782again during the final FIN exchange or when a RST
783.El
b7080c8e
A
784.Sh EXAMPLES
785This command adds an entry which denies all tcp packets from
786.Em cracker.evil.org
787to the telnet port of
788.Em wolf.tambov.su
789from being forwarded by the host:
790.Pp
7ba0088d
A
791.Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet"
792.Pp
793This one disallows any connection from the entire crackers
794network to my host:
795.Pp
796.Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org"
797.Pp
ac2f15b3 798A fast and efficient way to limit access (not using dynamic rules)
7ba0088d 799is the use of the following rules:
b7080c8e 800.Pp
7ba0088d
A
801.Dl "ipfw add allow tcp from any to any established"
802.Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup"
803.Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup"
804.Dl "..."
805.Dl "ipfw add deny tcp from any to any"
806.Pp
807The first rule will be a quick match for normal TCP packets,
808but it will not match the initial SYN packet, which will be
809matched by the
810.Cm setup
811rules only for selected source/destination pairs.
812All other SYN packets will be rejected by the final
813.Cm deny
814rule.
815.Pp
816In order to protect a site from flood attacks involving fake
817TCP packets, it is safer to use dynamic rules:
818.Pp
819.Dl "ipfw add check-state"
820.Dl "ipfw add deny tcp from any to any established"
821.Dl "ipfw add allow tcp from my-net to any setup keep-state"
822.Pp
823This will let the firewall install dynamic rules only for
824those connection which start with a regular SYN packet coming
825from the inside of our network.
826Dynamic rules are checked when encountering the first
827.Cm check-state
828or
829.Cm keep-state
830rule.
831A
832.Cm check-state
833rule should be usually placed near the beginning of the
834ruleset to minimize the amount of work scanning the ruleset.
835Your mileage may vary.
836.Pp
837.Em BEWARE :
838stateful rules can be subject to denial-of-service attacks
839by a SYN-flood which opens a huge number of dynamic rules.
840The effects of such attacks can be partially limited by
841acting on a set of
842.Xr sysctl 8
843variables which control the operation of the firewall.
b7080c8e
A
844.Pp
845Here is a good usage of the
7ba0088d
A
846.Cm list
847command to see accounting records and timestamp information:
b7080c8e 848.Pp
7ba0088d 849.Dl ipfw -at list
b7080c8e
A
850.Pp
851or in short form without timestamps:
852.Pp
7ba0088d
A
853.Dl ipfw -a list
854.Pp
855Next rule diverts all incoming packets from 192.168.2.0/24
856to divert port 5000:
857.Pp
858.Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in
859.Pp
b7080c8e
A
860.Sh SEE ALSO
861.Xr cpp 1 ,
862.Xr m4 1 ,
863.Xr divert 4 ,
864.Xr ip 4 ,
865.Xr ipfirewall 4 ,
866.Xr protocols 5 ,
867.Xr services 5 ,
868.Xr init 8 ,
b7080c8e
A
869.Xr reboot 8 ,
870.Xr sysctl 8 ,
7ba0088d 871.Xr syslogd 8
b7080c8e 872.Sh BUGS
7ba0088d 873The syntax has grown over the years and it is not very clean.
b7080c8e
A
874.Pp
875.Em WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!
876.Pp
7ba0088d
A
877This program can put your computer in rather unusable state.
878When using it for the first time, work on the console of the
879computer, and do
b7080c8e
A
880.Em NOT
881do anything you don't understand.
882.Pp
7ba0088d
A
883When manipulating/adding chain entries, service and protocol names
884are not accepted.
b7080c8e
A
885.Pp
886Incoming packet fragments diverted by
7ba0088d
A
887.Cm divert
888or
889.Cm tee
890are reassembled before delivery to the socket.
b7080c8e 891.Pp
7ba0088d
A
892Packets that match a
893.Cm tee
894rule should not be immediately accepted, but should continue
895going through the rule list.
896This may be fixed in a later version.
b7080c8e
A
897.Sh AUTHORS
898.An Ugen J. S. Antsilevich ,
899.An Poul-Henning Kamp ,
900.An Alex Nash ,
7ba0088d
A
901.An Archie Cobbs ,
902.An Luigi Rizzo .
903.Pp
904.An -nosplit
b7080c8e
A
905API based upon code written by
906.An Daniel Boulet
907for BSDI.
908.Sh HISTORY
7ba0088d 909The
b7080c8e 910.Nm
7ba0088d 911utility first appeared in
b7080c8e 912.Fx 2.0 .
7ba0088d
A
913Stateful extensions were introduced in
914.Fx 4.0 .