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