support netfilter module "osf"
[ferm.git] / doc / ferm.pod
blobff4e4ee2c10b3a7b94db3818e13e621c474e9467
2 # ferm pod manual file
6 # ferm, a firewall setup program that makes firewall rules easy!
8 # Copyright (C) 2001-2012 Max Kellermann, Auke Kok
10 # Comments, questions, greetings and additions to this program
11 # may be sent to <ferm@foo-projects.org>
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30 =head1 NAME
32 B<ferm> - a firewall rule parser for linux
34 =head1 SYNOPSIS
36 B<ferm> I<options> I<inputfile>
38 =head1 DESCRIPTION
40 B<ferm> is a frontend for B<iptables>. It reads the rules from a
41 structured configuration file and calls iptables(8) to insert them
42 into the running kernel.
44 B<ferm>'s goal is to make firewall rules easy to write and easy to
45 read. It tries to reduce the tedious task of writing down rules, thus
46 enabling the firewall administrator to spend more time on developing
47 good rules than the proper implementation of the rule.
49 To achieve this, B<ferm> uses a simple but powerful configuration
50 language, which allows variables, functions, arrays, blocks. It also
51 allows you to include other files, allowing you to create libraries of
52 commonly used structures and functions.
54 B<ferm>, pronounced "firm", stands for "For Easy Rule Making".
57 =head1 CAUTION
59 This manual page does I<not> indend to teach you how firewalling works
60 and how to write good rules.  There is already enough documentation on
61 this topic.
64 =head1 INTRODUCTION
66 Let's start with a simple example:
68     chain INPUT {
69         proto tcp ACCEPT;
70     }
72 This will add a rule to the predefined input chain, matching and
73 accepting all tcp packets.  Ok, let's make it more complicated:
75     chain (INPUT OUTPUT) {
76         proto (udp tcp) ACCEPT;
77     }
79 This will insert 4 rules, namely 2 in chain input, and 2 in chain
80 output, matching and accepting both udp and tcp packets.  Normally you
81 would type this:
83    iptables -A INPUT -p tcp -j ACCEPT
84    iptables -A OUTPUT -p tcp -j ACCEPT
85    iptables -A INPUT -p udp -j ACCEPT
86    iptables -A OUTPUT -p udp -j ACCEPT
88 Note how much less typing we need to do? :-)
90 Basically, this is all there is to it, although you can make it quite
91 more complex. Something to look at:
93    chain INPUT {
94        policy ACCEPT;
95        daddr 10.0.0.0/8 proto tcp dport ! ftp jump mychain sport :1023 TOS 4 settos 8 mark 2;
96        daddr 10.0.0.0/8 proto tcp dport ftp REJECT;
97    }
99 My point here is, that *you* need to make nice rules, keep
100 them readable to you and others, and not make it into a mess.
102 It would aid the reader if the resulting firewall rules were placed
103 here for reference. Also, you could include the nested version with
104 better readability.
106 Try using comments to show what you are doing:
108     # this line enables transparent http-proxying for the internal network:
109     proto tcp if eth0 daddr ! 192.168.0.0/255.255.255.0
110         dport http REDIRECT to-ports 3128;
112 You will be thankful for it later!
114     chain INPUT {
115         policy ACCEPT;
116         interface (eth0 ppp0) {
117             # deny access to notorius hackers, return here if no match
118             # was found to resume normal firewalling
119             jump badguys;
121             protocol tcp jump fw_tcp;
122             protocol udp jump fw_udp;
123         }
124     }
126 The more you nest, the better it looks. Make sure the order you
127 specify is correct, you would not want to do this:
129     chain FORWARD {
130         proto ! udp DROP;
131         proto tcp dport ftp ACCEPT;
132     }
134 because the second rule will never match. Best way is to specify
135 first everyting that is allowed, and then deny everything else.
136 Look at the examples for more good snapshots. Most people do
137 something like this:
139     proto tcp {
140         dport (
141             ssh http ftp
142         ) ACCEPT;
143         dport 1024:65535 ! syn ACCEPT;
144         DROP;
145     }
147 =head1 STRUCTURE OF A FIREWALL FILE
149 The structure of a proper firewall file looks like  simplified
150 C-code. Only a few syntactic characters are used in ferm-
151 configuration files. Besides these special caracters, ferm
152 uses 'keys' and 'values', think of them as options and
153 parameters, or as variables and values, whatever.
155 With these words, you define the characteristics of your firewall.
156 Every firewall consists of two things: First, look if network
157 traffic matches certain conditions, and second, what to do
158 with that traffic.
160 You may specify conditions that are valid for the kernel
161 interface program you are using, probably iptables(8). For
162 instance, in iptables, when you are trying to match tcp
163 packets, you would say:
165     iptables --protocol tcp
167 In ferm, this will become:
169     protocol tcp;
171 Just typing this in ferm doesn't do anything, you need to tell
172 ferm (actually, you need to tell iptables(8) and the kernel) what
173 to do with any traffic that matches this condition:
175     iptables --protocol tcp -j ACCEPT
177 Or, translated to B<ferm>:
179     protocol tcp ACCEPT;
181 The B<;> character is at the end of every ferm rule. Ferm ignores line
182 breaks, meaning the above example is identical to the following:
184     protocol tcp
185       ACCEPT;
187 Here's a list of the special characters:
189 =over 8
191 =item B<;>
193 This character finalizes a rule.
195 Separated by semicolons, you may write multiple rules in one line,
196 although this decreases readability:
198     protocol tcp ACCEPT; protocol udp DROP;
200 =item B<{}>
202 The nesting symbol defines a 'block' of rules.
204 The curly brackets contain any number of nested rules. All matches
205 before the block are carried forward to these.
207 The closing curly bracket finalizes the rule set. You should not write
208 a ';' after that, because that would be an empty rule.
210 Example:
212     chain INPUT proto icmp {
213         icmp-type echo-request ACCEPT;
214         DROP;
215     }
217 This block shows two rules inside a block, which will both be merged
218 with anything in front of it, so you will get two rules:
220     iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
221     iptables -A INPUT -p icmp -j DROP
223 There can be multiple nesting levels:
225     chain INPUT {
226         proto icmp {
227             icmp-type echo-request ACCEPT;
228             DROP;
229         }
230         daddr 172.16.0.0/12 REJECT;
231     }
233 Note that the 'REJECT' rule is not affected by 'proto icmp', although
234 there is no ';' after the closing curly brace. Translated to iptables:
236     iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
237     iptables -A INPUT -p icmp -j DROP
238     iptables -A INPUT -d 172.16.0.0/12 -j REJECT
240 =item B<$>
242 Variable expansion. Replaces '$FOO' by the value of the variable. See
243 the section I<VARIABLES> for details.
245 =item B<&>
247 Function call. See the section I<FUNCTIONS> for details.
249 =item B<()>
251 The array symbol. Using the parentheses, you can define
252 a 'list' of values that should be applied for the key to the
253 left of it.
255 Example:
257     protocol ( tcp udp icmp )
259 this will result in three rules:
261     ... -p tcp ...
262     ... -p udp ...
263     ... -p icmp ...
265 Only values can be 'listed', so you cannot do something like this:
267     proto tcp ( ACCEPT LOG );
269 but you can do this:
271     chain (INPUT OUTPUT FORWARD) proto (icmp udp tcp) DROP;
273 (which will result in nine rules!)
275 Values are separated by spaces. The array symbol is both left- and
276 right-associative, in contrast with the nesting block, which is
277 left-associative only.
279 =item C< # >
281 The comment symbol. Anything that follows this symbol up to
282 the end of line is ignored.
284 =item C<`command`>
286 Execute the command in a shell, and insert the process output. See the
287 section I<backticks> for details.
289 =item C<'string'>
291 Quote a string which may contain whitespaces, the dollar sign etc.
293     LOG log-prefix ' hey, this is my log prefix!';
295 =item C<"string">
297 Quote a string (see above), but variable references with a dollar sign
298 are evaluated:
300     DNAT to "$myhost:$myport";
302 =back
305 =head2 Keywords
307 In the previous section, we already introduced some basic keywords
308 like "chain", "protocol" and "ACCEPT". Let's explore their nature.
310 There are three kinds of keywords:
312 =over 8
314 =item
316 B<location> keywords define where a rule will be created. Example:
317 "table", "chain".
319 =item
321 B<match> keywords perform a test on all passing packets. The current
322 rule is without effect if one (or more) of the matches does not
323 pass. Example: "proto", "daddr".
325 Most matches are followed by a parameter: "proto tcp", "daddr
326 172.16.0.0/12".
328 =item
330 B<target> keywords state what to do with a packet. Example: "ACCEPT",
331 "REJECT", "jump".
333 Some targets define more keywords to specify details: "REJECT
334 reject-with icmp-net-unreachable".
336 =back
338 Every rule consists of a B<location> and a B<target>, plus any number
339 of B<matches>:
341     table filter                  # location
342     proto tcp dport (http https)  # match
343     ACCEPT;                       # target
345 Strictly speaking, there is a fourth kind: B<ferm> keywords (which
346 control ferm's internal behaviour), but they will be explained later.
349 =head2 Parameters
351 Many keywords take parameters. These can be specified as literals,
352 variable references or lists (arrays):
354     proto udp
355     saddr $TRUSTED_HOSTS;
356     proto tcp dport (http https ssh);
357     LOG log-prefix "funky wardriver alert: ";
359 Some of them can be negated (lists cannot be negated):
361     proto !esp;
362     proto udp dport !domain;
364 Keywords which take no parameters are negated by a prefixed '!':
366     proto tcp !syn;
368 Read iptables(8) to see where the B<!> can be used.
371 =head1 BASIC KEYWORDS
374 =head2 Location keywords
376 =over 8
378 =item B<domain [ip|ip6]>
380 Set the domain. "ip" is default and means "IPv4" (iptables). "ip6" is
381 for IPv6 support, using "ip6tables".
383 =item B<table [filter|nat|mangle]>
385 Specifies which netfilter table this rule will be inserted to:
386 "filter" (default), "nat" or "mangle".
388 =item B<chain [chain-name]>
390 Specifies the netfilter chain (within the current table) this rule
391 will be inserted to. Common predefined chain names are "INPUT",
392 "OUTPUT", "FORWARD", "PREROUTING", "POSTROUTING", depending on the
393 table. See the netfilter documentation for details.
395 If you specify a non-existing chain here, ferm will add the rule to a
396 custom chain with that name.
398 =item B<policy [ACCEPT|DROP|..]>
400 Specifies the default policy for the current chain (built-in
401 only). Can be one of the built-in targets (ACCEPT, DROP, REJECT,
402 ...). A packet that matches no rules in a chain will be treated as
403 specified by the policy.
405 To avoid ambiguity, always specify the policies of all predefined
406 chains explicitly.
408 =item B<@subchain ["CHAIN-NAME"] { ... }>
410 Works like the normal block operators (i.e. without the I<@subchain>
411 keyword), except that B<ferm> moves rules within the curly braces into
412 a new custom chain. The name for this chain is chosen automatically by
413 ferm.
415 In many cases, this is faster than just a block, because the kernel
416 may skip a huge block of rules when a precondition is false. Imagine
417 the following example:
419  table filter chain INPUT {
420      saddr (1.2.3.4 2.3.4.5 3.4.5.6 4.5.6.7 5.6.7.8) {
421          proto tcp dport (http https ssh) ACCEPT;
422          proto udp dport domain ACCEPT;
423      }
426 This generates 20 rules. When a packet arrives which does not pass the
427 B<saddr> match, it nonetheless checks all 20 rules. With B<@subchain>,
428 this check is done once, resulting in faster network filtering and
429 less CPU load:
431  table filter chain INPUT {
432      saddr (1.2.3.4 2.3.4.5 3.4.5.6 4.5.6.7 5.6.7.8) @subchain {
433          proto tcp dport (http https ssh) ACCEPT;
434          proto udp dport domain ACCEPT;
435      }
438 Optionally, you may define the name of the sub chain:
440  saddr (1.2.3.4 2.3.4.5 3.4.5.6) @subchain "foobar" {
441      proto tcp dport (http https ssh) ACCEPT;
442      proto udp dport domain ACCEPT;
445 The name can either be a quoted string literal, or an expanded ferm
446 expression such as @cat("interface_", $iface) or @substr($var,0,20).
448 You can achieve the same by explicitly declaring a custom chain, but
449 you may feel that using B<@subchain> requires less typing.
452 =back
455 =head2 Basic iptables match keywords
457 =over 8
459 =item B<interface [interface-name]>
461 Define the interface name, your outside network card, like eth0,
462 or dialup like ppp1, or whatever device you want to match for
463 passing packets. It is equivalent to the C<-i> switch in
464 iptables(8).
466 =item B<outerface [interface-name]>
468 Same as interface, only for matching the outgoing interface
469 for a packet, as in iptables(8).
471 =item B<protocol [protocol-name|protocol-number]>
473 Currently supported by the kernel are tcp, udp and icmp, or
474 their respective numbers.
476 =item B<saddr|daddr [address-spec]>
478 Matches on packets originating from the specified address (saddr) or
479 targeted at the address (daddr).
481 Examples:
483     saddr 192.168/8 ACCEPT; # (identical to the next one:)
484     saddr 192.168.0.0/255.255.255.0 ACCEPT;
485     daddr my.domain.com ACCEPT;
487 =item B<fragment>
489 Specify that only fragmented IP packets should be matched.
490 When packets are larger that the maximum packet size your
491 system can handle (called Maximum Transmission Unit or MTU)
492 they will be chopped into bits and sent one by one as single
493 packets. See ifconfig(8) if you want to find the MTU for
494 your system (the default is usually 1500 bytes).
496 Fragments are frequently used in DOS attacks, because there
497 is no way of finding out the origin of a fragment packet.
499 =item B<sport|dport [port-spec]>
501 Matches on packets on the specified TCP or UDP port. "sport" matches
502 the source port, and dport matches the destination port.
504 This match can be used only after you specified "protocol tcp" or
505 "protocol udp", because only these two protocols actually have ports.
507 And some examples of valid ports/ranges:
509     dport 80 ACCEPT;
510     dport http ACCEPT;
511     dport ssh:http ACCEPT;
512     dport 0:1023 ACCEPT; # equivalent to :1023
513     dport 1023:65535 ACCEPT;
515 =item B<syn>
517 Specify that the SYN flag in a tcp package should be matched,
518 which are used to build new tcp connections. You can identify
519 incoming connections with this, and decide wether you want
520 to allow it or not. Packets that do not have this flag are
521 probably from an already established connection, so it's
522 considered reasonably safe to let these through.
524 =item B<module [module-name]>
526 Load an iptables module. Most modules provide more match
527 keywords. We'll get to that later.
529 =back
532 =head2 Basic target keywords
534 =over 8
536 =item B<jump [custom-chain-name]>
538 Jumps to a custom chain. If no rule in the custom chain matched,
539 netfilter returns to the next rule in the previous chain.
541 =item B<realgoto [custom-chain-name]>
543 Go to a custom chain.  Unlike the B<jump> option, B<RETURN> will not
544 continue processing in this chain but instead in the chain that called
545 us via B<jump>.
547 The keyword B<realgoto> was chosen during the transition period,
548 because B<goto> (already deprecated) used to be an alias for B<jump>.
550 =item B<ACCEPT>
552 Accepts matching packets.
554 =item B<DROP>
556 Drop matching packets without further notice.
558 =item B<REJECT>
560 Rejects matching packets, i.e. send an ICMP packet to the sender,
561 which is port-unreachable by default. You may specify another ICMP
562 type.
564     REJECT; # default to icmp-port-unreachable
565     REJECT reject-with icmp-net-unreachable;
567 Type "iptables -j REJECT -h" for details.
569 =item B<RETURN>
571 Finish the current chain and return to the calling chain (if "jump
572 [custom-chain-name]" was used).
574 =item B<NOP>
576 No action at all.
578 =back
581 =head1 ADDITIONAL KEYWORDS
583 Netfilter is modular. Modules may provide additional targets and match
584 keywords. The list of netfilter modules is constantly growing, and
585 ferm tries to keep up with supporting them all. This chapter describes
586 modules which are currently supported.
589 =head2 iptables match modules
591 =over 8
593 =item B<account>
595 Account traffic for all hosts in defined network/netmask.  This is one
596 of the match modules which behave like a target, i.e. you will mostly
597 have to use the B<NOP> target.
599     mod account aname mynetwork aaddr 192.168.1.0/24 ashort NOP;
601 =item B<addrtype>
603 Check the address type; either source address or destination address.
605     mod addrtype src-type BROADCAST;
606     mod addrtype dst-type LOCAL;
608 Type "iptables -m addrtype -h" for details.
610 =item B<ah>
612 Checks the SPI header in an AH packet.
614     mod ah ahspi 0x101;
615     mod ah ahspi ! 0x200:0x2ff;
617 Additional arguments for IPv6:
619     mod ah ahlen 32 ACCEPT;
620     mod ah ahlen !32 ACCEPT;
621     mod ah ahres ACCEPT;
623 =item B<comment>
625 Adds a comment of up to 256 characters to a rule, without an effect.
626 Note that unlike ferm comments ('#'), this one will show up in
627 "iptables -L".
629     mod comment comment "This is my comment." ACCEPT;
631 =item B<condition>
633 Matches if a value in /proc/net/ipt_condition/NAME is 1 (path is
634 /proc/net/ip6t_condition/NAME for the ip6 domain).
636     mod condition condition (abc def) ACCEPT;
637     mod condition condition !foo ACCEPT;
639 =item B<connbytes>
641 Match by how many bytes or packets a connection (or one of the two
642 flows constituting the connection) have tranferred so far, or by
643 average bytes per packet.
645     mod connbytes connbytes 65536: connbytes-dir both connbytes-mode bytes ACCEPT;
646     mod connbytes connbytes !1024:2048 connbytes-dir reply connbytes-mode packets ACCEPT;
648 Valid values for I<connbytes-dir>: I<original>, I<reply>, I<both>; for
649 I<connbytes-mode>: I<packets>, I<bytes>, I<avgpkt>.
651 =item B<connlimit>
653 Allows you to restrict the number of parallel TCP connections to a
654 server per client IP address (or address block).
656     mod connlimit connlimit-above 4 REJECT;
657     mod connlimit connlimit-above !4 ACCEPT;
658     mod connlimit connlimit-above 4 connlimit-mask 24 REJECT;
660 =item B<connmark>
662 Check the mark field associated with the connection, set by the
663 CONNMARK target.
665     mod connmark mark 64;
666     mod connmark mark 6/7;
668 =item B<conntrack>
670 Check connection tracking information.
672     mod conntrack ctstate (ESTABLISHED RELATED);
673     mod conntrack ctproto tcp;
674     mod conntrack ctorigsrc 192.168.0.2;
675     mod conntrack ctorigdst 1.2.3.0/24;
676     mod conntrack ctorigsrcport 67;
677     mod conntrack ctorigdstport 22;
678     mod conntrack ctreplsrc 2.3.4.5;
679     mod conntrack ctrepldst ! 3.4.5.6;
680     mod conntrack ctstatus ASSURED;
681     mod conntrack ctexpire 60;
682     mod conntrack ctexpire 180:240;
684 Type "iptables -m conntrack -h" for details.
686 =item B<dccp>
688 Check DCCP (Datagram Congestion Control Protocol) specific attributes.
689 This module is automatically loaded when you use "protocol dccp".
691     proto dccp sport 1234 dport 2345 ACCEPT;
692     proto dccp dccp-types (SYNCACK ACK) ACCEPT;
693     proto dccp dccp-types !REQUEST DROP;
694     proto dccp dccp-option 2 ACCEPT;
696 =item B<dscp>
698 Match the 6 bit DSCP field within the TOS field.
700     mod dscp dscp 11;
701     mod dscp dscp-class AF41;
703 =item B<ecn>
705 Match the ECN bits of an IPv4 TCP header.
707     mod ecn ecn-tcp-cwr;
708     mod ecn ecn-tcp-ece;
709     mod ecn ecn-ip-ect 2;
711 Type "iptables -m ecn -h" for details.
713 =item B<esp>
715 Checks the SPI header in an ESP packet.
717     mod esp espspi 0x101;
718     mod esp espspi ! 0x200:0x2ff;
720 =item B<eui64>
722 "This module matches the EUI-64 part of a stateless autoconfigured
723 IPv6 address.  It compares the EUI-64 derived from the source MAC
724 address in Ehternet frame with the lower 64 bits of the IPv6 source
725 address.  But "Universal/Local" bit is not compared.  This module
726 doesn't match other link layer frame, and is only valid in the
727 PREROUTING, INPUT and FORWARD chains."
729     mod eui64 ACCEPT;
731 =item B<fuzzy>
733 "This module matches a rate limit based on a fuzzy logic controller [FLC]."
735     mod fuzzy lower-limit 10 upper-limit 20 ACCEPT;
737 =item B<hbh>
739 Matches the Hop-by-Hop Options header (ip6).
741     mod hbh hbh-len 8 ACCEPT;
742     mod hbh hbh-len !8 ACCEPT;
743     mod hbh hbh-opts (1:4 2:8) ACCEPT;
745 =item B<hl>
747 Matches the Hop Limit field (ip6).
749     mod hl hl-eq (8 10) ACCEPT;
750     mod hl hl-eq !5 ACCEPT;
751     mod hl hl-gt 15 ACCEPT;
752     mod hl hl-lt 2 ACCEPT;
754 =item B<helper>
756 Checks which conntrack helper module tracks this connection.  The port
757 may be specified with "-portnr".
759     mod helper helper irc ACCEPT;
760     mod helper helper ftp-21 ACCEPT;
762 =item B<icmp>
764 Check ICMP specific attributes.  This module is automatically loaded
765 when you use "protocol icmp".
767     proto icmp icmp-type echo-request ACCEPT;
769 This option can also be used in be I<ip6> domain, although this is
770 called B<icmpv6> in F<ip6tables>.
772 Use "iptables -p icmp C<-h>" to obtain a list of valid ICMP types.
774 =item B<iprange>
776 Match a range of IPv4 addresses.
778     mod iprange src-range 192.168.2.0-192.168.3.255;
779     mod iprange dst-range ! 192.168.6.0-192.168.6.255;
781 =item B<ipv4options>
783 Match on IPv4 header options like source routing, record route,
784 timestamp and router-alert.
786     mod ipv4options ssrr ACCEPT;
787     mod ipv4options lsrr ACCEPT;
788     mod ipv4options no-srr ACCEPT;
789     mod ipv4options !rr ACCEPT;
790     mod ipv4options !ts ACCEPT;
791     mod ipv4options !ra ACCEPT;
792     mod ipv4options !any-opt ACCEPT;
794 =item B<ipv6header>
796 Matches the IPv6 extension header (ip6).
798     mod ipv6header header !(hop frag) ACCEPT;
799     mod ipv6header header (auth dst) ACCEPT;
801 =item B<hashlimit>
803 Similar to 'mod limit', but adds the ability to add per-destination or
804 per-port limits managed in a hash table.
806     mod hashlimit  hashlimit 10/minute  hashlimit-burst 30/minute
807       hashlimit-mode dstip  hashlimit-name foobar  ACCEPT;
809 Possible values for hashlimit-mode: dstip dstport srcip srcport (or a
810 list with more than one of these).
812 There are more possible settings, type "iptables -m hashlimit -h" for
813 documentation.
815 =item B<length>
817 Check the package length.
819     mod length length 128; # exactly 128 bytes
820     mod length length 512:768; # range
821     mod length length ! 256; # negated
823 =item B<limit>
825 Limits the packet rate.
827     mod limit limit 1/second;
828     mod limit limit 15/minute limit-burst 10;
830 Type "iptables -m limit -h" for details.
832 =item B<mac>
834 Match the source MAC address.
836     mod mac mac-source 01:23:45:67:89;
838 =item B<mark>
840 Matches packets based on their netfilter mark field. This may be a 32
841 bit integer between 0 and 4294967295.
843     mod mark mark 42;
845 =item B<mh>
847 Matches the mobility header (domain I<ip6>).
849     proto mh mh-type binding-update ACCEPT;
851 =item B<multiport>
853 Match a set of source or destination ports (UDP and TCP only).
855     mod multiport source-ports (https ftp);
856     mod multiport destination-ports (mysql domain);
858 This rule has a big advantage over "dport" and "sport": it generates
859 only one rule for up to 15 ports instead of one rule for every port.
861 =item B<nth>
863 Match every 'n'th packet.
865     mod nth every 3;
866     mod nth counter 5 every 2;
867     mod nth start 2 every 3;
868     mod nth start 5 packet 2 every 6;
870 Type "iptables -m nth -h" for details.
872 =item B<osf>
874 Match packets depending on the operating system of the sender.
876     mod osf genre Linux;
877     mod osf ! genre FreeBSD ttl 1 log 1;
879 Type "iptables -m osf -h" for details.
881 =item B<owner>
883 Check information about the packet creator, namely user id, group id,
884 process id, session id and command name.
886     mod owner uid-owner 0;
887     mod owner gid-owner 1000;
888     mod owner pid-owner 5432;
889     mod owner sid-owner 6543;
890     mod owner cmd-owner "sendmail";
892 ("cmd-owner", "pid-owner" and "sid-owner" require special kernel
893 patches not included in the vanilla Linux kernel)
895 =item B<physdev>
897 Matches the physical device on which a packet entered or is about to
898 leave the machine. This is useful for bridged interfaces.
900     mod physdev physdev-in ppp1;
901     mod physdev physdev-out eth2;
902     mod physdev physdev-is-in;
903     mod physdev physdev-is-out;
904     mod physdev physdev-is-bridged;
906 =item B<pkttype>
908 Check the link-layer packet type.
910     mod pkttype pkt-type unicast;
911     mod pkttype pkt-type broadcase;
912     mod pkttype pkt-type multicast;
914 =item B<policy>
916 Matches IPsec policy being applied to this packet.
918     mod policy dir out pol ipsec ACCEPT;
919     mod policy strict reqid 23 spi 0x10 proto ah ACCEPT;
920     mod policy mode tunnel tunnel-src 192.168.1.2 ACCEPT;
921     mod policy mode tunnel tunnel-dst 192.168.2.1 ACCEPT;
922     mod policy strict next reqid 24 spi 0x11 ACCEPT;
924 Note that the keyword I<proto> is also used as a shorthand version of
925 I<protocol> (built-in match module).  You can fix this conflict by
926 always using the long keyword I<protocol>.
928 =item B<psd>
930 Detect TCP/UDP port scans.
932     mod psd psd-weight-threshold 21 psd-delay-threshold 300
933       psd-lo-ports-weight 3 psd-hi-ports-weight 1 DROP;
935 =item B<quota>
937 Implements network quotas by decrementing a byte counter with each packet.
939     mod quota quota 65536 ACCEPT;
941 =item B<random>
943 Match a random percentage of all packets.
945     mod random average 70;
947 =item B<realm>
949 Match the routing realm. Useful in environments using BGP.
951     mod realm realm 3;
953 =item B<recent>
955 Temporarily mark source IP addresses.
957     mod recent set;
958     mod recent rcheck seconds 60;
959     mod recent set rsource name "badguy";
960     mod recent set rdest;
961     mod recent rcheck rsource name "badguy" seconds 60;
962     mod recent update seconds 120 hitcount 3 rttl;
964 This netfilter module has a design flaw: although it is implemented as
965 a match module, it has target-like behaviour when using the "set"
966 keyword.
968 L<http://snowman.net/projects/ipt_recent/>
970 =item B<rt>
972 Match the IPv6 routing header (ip6 only).
974     mod rt rt-type 2 rt-len 20 ACCEPT;
975     mod rt rt-type !2 rt-len !20 ACCEPT;
976     mod rt rt-segsleft 2:3 ACCEPT;
977     mod rt rt-segsleft !4:5 ACCEPT;
978     mod rt rt-0-res rt-0-addrs (::1 ::2) rt-0-not-strict ACCEPT;
980 =item B<sctp>
982 Check SCTP (Stream Control Transmission Protocol) specific attributes.
983 This module is automatically loaded when you use "protocol sctp".
985     proto sctp sport 1234 dport 2345 ACCEPT;
986     proto sctp chunk-types only DATA:Be ACCEPT;
987     proto sctp chunk-types any (INIT INIT_ACK) ACCEPT;
988     proto sctp chunk-types !all (HEARTBEAT) ACCEPT;
990 Use "iptables -p sctp C<-h>" to obtain a list of valid chunk types.
992 =item B<set>
994 Checks the source or destination IP/Port/MAC against a set.
996     mod set set badguys src DROP;
998 See L<http://ipset.netfilter.org/> for more information.
1000 =item B<state>
1002 Checks the connection tracking state.
1004     mod state state INVALID DROP;
1005     mod state state (ESTABLISHED RELATED) ACCEPT;
1007 Type "iptables -m state -h" for details.
1009 =item B<statistic>
1011 Successor of B<nth> and B<random>, currently undocumented in the
1012 iptables(8) man page.
1014     mod statistic mode random probability 0.8 ACCEPT;
1015     mod statistic mode nth every 5 packet 0 DROP;
1017 =item B<string>
1019 Matches a string.
1021     mod string string "foo bar" ACCEPT;
1022     mod string algo kmp from 64 to 128 hex-string "deadbeef" ACCEPT;
1024 =item B<tcp>
1026 Checks TCP specific attributes. This module is automatically loaded
1027 when you use "protocol tcp".
1029     proto tcp sport 1234;
1030     proto tcp dport 2345;
1031     proto tcp tcp-flags (SYN ACK) SYN;
1032     proto tcp tcp-flags ! (SYN ACK) SYN;
1033     proto tcp tcp-flags ALL (RST ACK);
1034     proto tcp syn;
1035     proto tcp tcp-option 2;
1036     proto tcp mss 512;
1038 Type "iptables -p tcp -h" for details.
1040 =item B<tcpmss>
1042 Check the TCP MSS field of a SYN or SYN/ACK packet.
1044     mod tcpmss mss 123 ACCEPT;
1045     mod tcpmss mss 234:567 ACCEPT;
1047 =item B<time>
1049 Check if the time a packet arrives is in given range.
1051     mod time timestart 12:00;
1052     mod time timestop 13:30;
1053     mod time days (Mon Wed Fri);
1054     mod time datestart 2005:01:01;
1055     mod time datestart 2005:01:01:23:59:59;
1056     mod time datestop 2005:04:01;
1057     mod time monthday (30 31);
1058     mod time weekdays (Wed Thu);
1059     mod time timestart 12:00 utc;
1060     mod time timestart 12:00 localtz;
1062 Type "iptables -m time -h" for details.
1064 =item B<tos>
1066 Matches a packet on the specified TOS-value.
1068     mod tos tos Minimize-Cost ACCEPT;
1069     mod tos tos !Normal-Service ACCEPT;
1071 Type "iptables -m tos -h" for details.
1073 =item B<ttl>
1075 Matches the ttl (time to live) field in the IP header.
1077     mod ttl ttl-eq 12; # ttl equals
1078     mod ttl ttl-gt 10; # ttl greater than
1079     mod ttl ttl-lt 16; # ttl less than
1081 =item B<u32>
1083 Compares raw data from the packet.  You can specify more than one
1084 filter in a ferm list; these are not expanded into multiple rules.
1086     mod u32 u32 '6&0xFF=1' ACCEPT;
1087     mod u32 u32 ('27&0x8f=7' '31=0x527c4833') DROP;
1089 =item B<unclean>
1091 Matches packets which seem malformed or unusual. This match has no
1092 further parameters.
1094 =back
1097 =head2 iptables target modules
1099 The following additional targets are available in ferm, provided that
1100 you enabled them in your kernel:
1102 =over 8
1104 =item B<CLASSIFY>
1106 Set the CBQ class.
1108     CLASSIFY set-class 3:50;
1110 =item B<CLUSTERIP>
1112 Configure a simple cluster of nodes that share a certain IP and MAC
1113 address.  Connections are statically distributed between the nodes.
1115     CLUSTERIP new hashmode sourceip clustermac 00:12:34:45:67:89
1116       total-nodes 4 local-node 2 hash-init 12345;
1118 =item B<CONNMARK>
1120 Sets the netfilter mark value associated with a connection.
1122     CONNMARK set-mark 42;
1123     CONNMARK save-mark;
1124     CONNMARK restore-mark;
1125     CONNMARK save-mark mask 0x7fff;
1126     CONNMARK restore-mark mask 0x8000;
1128 =item B<CONNSECMARK>
1130 This module copies security markings from packets to connections (if
1131 unlabeled), and from connections back to packets (also only if
1132 unlabeled).  Typically used in conjunction with SECMARK, it is only
1133 valid in the mangle table.
1135     CONNSECMARK save;
1136     CONNSECMARK restore;
1138 =item B<DNAT to [ip-address|ip-range|ip-port-range]>
1140 Change the destination address of the packet.
1142     DNAT to 10.0.0.4;
1143     DNAT to 10.0.0.4:80;
1144     DNAT to 10.0.0.4:1024-2048;
1145     DNAT to 10.0.1.1-10.0.1.20;
1147 =item B<ECN>
1149 This target allows to selectively work around known ECN blackholes.
1150 It can only be used in the mangle table.
1152     ECN ecn-tcp-remove;
1154 =item B<HL>
1156 Modify the IPv6 Hop Limit field (ip6/mangle only).
1158     HL hl-set 5;
1159     HL hl-dec 2;
1160     HL hl-inc 1;
1162 =item B<IPV4OPTSSTRIP>
1164 Strip all the IP options from a packet.  This module does not take any
1165 options.
1167     IPV4OPTSSTRIP;
1169 =item B<LOG>
1171 Log all packets that match this rule in the kernel log. Be carefull
1172 with log flooding. Note that this is a "non-terminating target",
1173 i.e. rule traversal continues at the next rule.
1175     LOG log-level warning log-prefix "Look at this: ";
1176     LOG log-tcp-sequence log-tcp-options;
1177     LOG log-ip-options;
1179 =item B<MARK>
1181 Sets the netfilter mark field for the packet (a 32 bit integer between
1182 0 and 4294967295):
1184     MARK set-mark 42;
1185     MARK set-xmark 7/3;
1186     MARK and-mark 31;
1187     MARK or-mark 1;
1188     MARK xor-mark 12;
1190 =item B<MASQUERADE>
1192 Masquerades matching packets. Optionally followed by a port or
1193 port-range for iptables. Specify as "123", "123-456" or "123:456".
1194 The port range parameter specifies what local ports masqueraded
1195 connections should originate from.
1197     MASQUERADE;
1198     MASQUERADE to-ports 1234:2345;
1199     MASQUERADE to-ports 1234:2345 random;
1201 =item B<MIRROR>
1203 Experimental demonstration target which inverts the source and
1204 destination fields in the IP header.
1206     MIRROR;
1208 =item B<NETMAP>
1210 Map a whole network onto another network in the B<nat> table.
1212     NETMAP to 192.168.2.0/24;
1214 =item B<NOTRACK>
1216 Disable connection tracking for all packets matching that rule.
1218     proto tcp dport (135:139 445) NOTRACK;
1220 =item B<NFLOG>
1222 Log packets over netlink; this is the successor of I<ULOG>.
1224     NFLOG nflog-group 5 nflog-prefix "Look at this: ";
1225     NFLOG nflog-range 256;
1226     NFLOG nflog-threshold 10;
1228 =item B<NFQUEUE>
1230 Userspace queueing, requires nfnetlink_queue kernel support.
1232     proto tcp dport ftp NFQUEUE queue-num 20;
1234 =item B<QUEUE>
1236 Userspace queueing, the predecessor to B<NFQUEUE>.  All packets go to
1237 queue 0.
1239     proto tcp dport ftp QUEUE;
1241 =item B<REDIRECT to-ports [ports]>
1243 Transparent proxying: alter the destination IP of the packet to the
1244 machine itself.
1246     proto tcp dport http REDIRECT to-ports 3128;
1247     proto tcp dport http REDIRECT to-ports 3128 random;
1249 =item B<SAME>
1251 Similar to SNAT, but a client is mapped to the same source IP for all
1252 its connections.
1254     SAME to 1.2.3.4-1.2.3.7;
1255     SAME to 1.2.3.8-1.2.3.15 nodst;
1256     SAME to 1.2.3.16-1.2.3.31 random;
1258 =item B<SECMARK>
1260 This is used to set the security mark value associated with the packet
1261 for use by security subsystems such as SELinux.  It is only valid in
1262 the mangle table.
1264     SECMARK selctx "system_u:object_r:httpd_packet_t:s0";
1266 =item B<SET [add-set|del-set] [setname] [flag(s)]>
1268 Add the IP to the specified set. See L<http://ipset.netfilter.org/>
1270     proto icmp icmp-type echo-request SET add-set badguys src;
1272 =item B<SNAT to [ip-address|ip-range|ip-port-range]>
1274 Change the source address of the packet.
1276     SNAT to 1.2.3.4;
1277     SNAT to 1.2.3.4:20000-30000;
1278     SNAT to 1.2.3.4 random;
1280 =item B<TCPMSS>
1282 Alter the MSS value of TCP SYN packets.
1284     TCPMSS set-mss 1400;
1285     TCPMSS clamp-mss-to-pmtu;
1287 =item B<TOS set-tos [value]>
1289 Set the tcp package Type Of Service bit to this value.  This will be
1290 used by whatever traffic scheduler is willing to, mostly your own
1291 linux-machine, but maybe more. The original tos-bits are blanked and
1292 overwritten by this value.
1294     TOS set-tos Maximize-Throughput;
1295     TOS and-tos 7;
1296     TOS or-tos 1;
1297     TOS xor-tos 4;
1299 Type "iptables -j TOS -h" for details.
1301 =item B<TTL>
1303 Modify the TTL header field.
1305     TTL ttl-set 16;
1306     TTL ttl-dec 1; # decrease by 1
1307     TTL ttl-inc 4; # increase by 4
1309 =item B<ULOG>
1311 Log packets to a userspace program.
1313     ULOG ulog-nlgroup 5 ulog-prefix "Look at this: ";
1314     ULOG ulog-cprange 256;
1315     ULOG ulog-qthreshold 10;
1317 =back
1319 =head1 OTHER DOMAINS
1321 Since version 2.0, B<ferm> supports not only I<ip> and I<ip6>, but
1322 also I<arp> (ARP tables) and I<eb> (ethernet bridging tables).  The
1323 concepts are similar to I<iptables>.
1325 =head2 arptables keywords
1327 =over 8
1329 =item B<source-ip>, B<destination-ip>
1331 Matches the source or destination IPv4 address.  Same as B<saddr> and
1332 B<daddr> in the I<ip> domain.
1334 =item B<source-mac>, B<destination-mac>
1336 Matches the source or destination MAC address.
1338 =item B<interface>, B<outerface>
1340 Input and output interface.
1342 =item B<h-length>
1344 Hardware length of the packet.
1346     chain INPUT h-length 64 ACCEPT;
1348 =item B<opcode>
1350 Operation code, for details see the iptables(8).
1352     opcode 9 ACCEPT;
1354 =item B<h-type>
1356 Hardware type.
1358     h-type 1 ACCEPT;
1360 =item B<proto-type>
1362 Protocol type.
1364     proto-type 0x800 ACCEPT;
1366 =item B<Mangling>
1368 The keywords B<mangle-ip-s>, B<mangle-ip-d>, B<mangle-mac-s>,
1369 B<mangle-mac-d>, B<mangle-target> may be used for ARP mangling.  See
1370 iptables(8) for details.
1372 =back
1374 =head2 ebtables keywords
1376 =over 8
1378 =item B<proto>
1380 Matches the protocol which created the frame, e.g. I<IPv4> or B<PPP>.
1381 For a list, see F</etc/ethertypes>.
1383 =item B<interface>, B<outerface>
1385 Physical input and output interface.
1387 =item B<logical-in>, B<logical-out>
1389 The logical bridge interface.
1391 =item B<saddr>, B<daddr>
1393 Matches source or destination MAC address.
1395 =item B<Match modules>
1397 The following match modules are supported: 802.3, arp, ip, mark_m,
1398 pkttype, stp, vlan, log.
1400 =item B<Target extensions>
1402 The following target extensions are supported: arpreply, dnat, mark,
1403 redirect, snat.
1405 Please note that there is a conflict between I<--mark> from the
1406 I<mark_m> match module and I<-j mark>.  Since both would be
1407 implemented with the ferm keyword B<mark>, we decided to solve this by
1408 writing the target's name in uppercase, like in the other domains.
1409 The following example rewrites mark 1 to 2:
1411     mark 1 MARK 2;
1413 =back
1415 =head1 ADVANCED FEATURES
1417 =head2 Variables
1419 In complex firewall files, it is helpful to use variables, e.g. to
1420 give a network interface a meaningful name.
1422 To set variables, write:
1424     @def $DEV_INTERNET = eth0;
1425     @def $PORTS = (http ftp);
1426     @def $MORE_PORTS = ($PORTS 8080);
1428 In the real ferm code, variables are used like any other keyword
1429 parameter:
1431     chain INPUT interface $DEV_INTERNET proto tcp dport $MORE_PORTS ACCEPT;
1433 Note that variables can only be used in keyword parameters
1434 ("192.168.1.1", "http"); they cannot contain ferm keywords like
1435 "proto" or "interface".
1437 Variables are only valid in the current block:
1439     @def $DEV_INTERNET = eth1;
1440     chain INPUT {
1441         proto tcp {
1442             @def $DEV_INTERNET = ppp0;
1443             interface $DEV_INTERNET dport http ACCEPT;
1444         }
1445         interface $DEV_INTERNET DROP;
1446     }
1448 will be expanded to:
1450     chain INPUT {
1451         proto tcp {
1452             interface ppp0 dport http ACCEPT;
1453         }
1454         interface eth1 DROP;
1455     }
1457 The "def $DEV_INTERNET = ppp0" is only valid in the "proto tcp" block;
1458 the parent block still knows "set $DEV_INTERNET = eth1".
1460 Include files are special - variables declared in an included file are
1461 still available in the calling block. This is useful when you include
1462 a file which only declares variables.
1464 =head2 Automatic variables
1466 Some variables are set internally by ferm. Ferm scripts can use them
1467 just like any other variable.
1469 =over 8
1471 =item B<$FILENAME>
1473 The name of the configuration file relative to the directory ferm was
1474 started in.
1476 =item B<$FILEBNAME>
1478 The base name of the configuration file.
1480 =item B<$DIRNAME>
1482 The directory of the configuration file.
1484 =item B<$DOMAIN>
1486 The current domain.  One of I<ip>, I<ip6>, I<arp>, I<eb>.
1488 =item B<$TABLE>
1490 The current netfilter table.
1492 =item B<$CHAIN>
1494 The current netfilter chain.
1496 =item B<$LINE>
1498 The line of the current script.  It can be used like this:
1500     @def &log($msg) = {
1501              LOG log-prefix "rule=$msg:$LINE ";
1502     }
1503     .
1504     .
1505     .
1506     &log("log message");
1508 =back
1510 =head2 Functions
1512 Functions are similar to variables, except that they may have
1513 parameters, and they provide ferm commands, not values.
1515     @def &FOO() = proto (tcp udp) dport domain;
1516     &FOO() ACCEPT;
1518     @def &TCP_TUNNEL($port, $dest) = {
1519         table filter chain FORWARD interface ppp0 proto tcp dport $port daddr $dest outerface eth0 ACCEPT;
1520         table nat chain PREROUTING interface ppp0 proto tcp dport $port daddr 1.2.3.4 DNAT to $dest;
1521     }
1523     &TCP_TUNNEL(http, 192.168.1.33);
1524     &TCP_TUNNEL(ftp, 192.168.1.30);
1525     &TCP_TUNNEL((ssh smtp), 192.168.1.2);
1527 A function call which contains a block (like '{...}') must be the last
1528 command in a ferm rule, i.e. it must be followed by ';'. The '&FOO()'
1529 example does not contain a block, thus you may write 'ACCEPT' after
1530 the call. To circumvent this, you can reorder the keywords:
1532     @def &IPSEC() = { proto (esp ah); proto udp dport 500; }
1533     chain INPUT ACCEPT &IPSEC();
1535 =head2 Backticks
1537 With backticks, you may use the output of an external command:
1539     @def $DNSSERVERS = `grep nameserver /etc/resolv.conf | awk '{print $2}'`;
1540     chain INPUT proto tcp saddr $DNSSERVERS ACCEPT;
1542 The command is executed with the shell (F</bin/sh>), just like
1543 backticks in perl.  ferm does not do any variable expansion here.
1545 The output is then tokenized, and saved as a ferm list (array). Lines
1546 beginning with '#' are ignored; the other lines may contain any number
1547 of values, separated by whitespace.
1549 =head2 Includes
1551 The B<@include> keyword allows you to include external files:
1553     @include 'vars.ferm';
1555 The file name is relative to the calling file, e.g. when including
1556 from F</etc/ferm/ferm.conf>, the above statement includes
1557 F</etc/ferm/vars.ferm>. Variables and functions declared in an
1558 included file are still available in the calling file.
1560 B<include> works within a block:
1562     chain INPUT {
1563         @include 'input.ferm';
1564     }
1566 If you specify a directory (with a trailing '/'), all files in this
1567 directory are included, sorted alphabetically:
1569     @include 'ferm.d/';
1571 With a trailing pipe symbol, B<ferm> executes a shell command and
1572 parses its output:
1574     @include '/root/generate_ferm_rules.sh $HOSTNAME|'
1576 =head2 Conditionals
1578 The keyword B<@if> introduces a conditional expression:
1580     @if $condition DROP;
1582 A value is evaluated true just like in Perl: zero, empty list, empty
1583 string are false, everything else is true.  Examples for true values:
1585     (a b); 1; 'foo'; (0 0)
1587 Examples for false values:
1589     (); 0; '0'; ''
1591 There is also B<@else>:
1593     @if $condition DROP; @else REJECT;
1595 Note the semicolon before the B<@else>.
1597 It is possible to use curly braces after either B<@if> or B<@else>:
1599     @if $condition {
1600         MARK set-mark 2;
1601         RETURN;
1602     } @else {
1603         MARK set-mark 3;
1604     }
1606 Since the closing curly brace also finishes the command, there is no
1607 need for semicolon.
1609 There is no B<@elsif>, use B<@else @if> instead.
1611 Example:
1613     @def $have_ipv6 = `test -f /proc/net/ip6_tables_names && echo 1 || echo`;
1614     @if $have_ipv6 {
1615         domain ip6 {
1616             # ....
1617         }
1618     }
1620 =head2 Hooks
1622 To run custom commands, you may install hooks:
1624     @hook pre "echo 0 >/proc/sys/net/ipv4/conf/eth0/forwarding";
1625     @hook post "echo 1 >/proc/sys/net/ipv4/conf/eth0/forwarding";
1626     @hook flush "echo 0 >/proc/sys/net/ipv4/conf/eth0/forwarding";
1628 The specified command is executed using the shell.  "pre" means run
1629 the command before applying the firewall rules, and "post" means run
1630 the command afterwards.  "flush" hooks are run after ferm has flushed
1631 the firewall rules (option --flush).  You may install any number of
1632 hooks.
1634 =head1 BUILT-IN FUNCTIONS
1636 There are several built-in functions which you might find useful.
1638 =head2 @eq(a,b)
1640 Tests two values for equality.  Example:
1642     @if @eq($DOMAIN, ip6) DROP;
1644 =head2 @ne(a,b)
1646 Similar to @eq, this tests for non-equality.
1648 =head2 @not(x)
1650 Negates a boolean value.
1652 =head2 @resolve((hostname1 hostname2 ...), [type])
1654 Usually, host names are resolved by iptables.  To let ferm resolve
1655 host names, use the function @resolve:
1657     saddr @resolve(my.host.foo) proto tcp dport ssh ACCEPT;
1658     saddr @resolve((another.host.foo third.host.foo)) proto tcp dport openvpn ACCEPT;
1659     daddr @resolve(ipv6.google.com, AAAA) proto tcp dport http ACCEPT;
1661 Note the double parentheses in the second line: the inner pair for
1662 creating a ferm list, and the outer pair as function parameter
1663 delimiters.
1665 The second parameter is optional, and specifies the DNS record type.
1666 The default is "A".
1668 Be careful with resolved host names in firewall configuration.  DNS
1669 requests may block the firewall configuration for a long time, leaving
1670 the machine vulnerable, or they may fail.
1672 =head2 @cat(a, b, ...)
1674 Concatenate all parameters into one string.
1676 =head2 @substr(expression, offset, length)
1678 Extracts a substring out of expression and returns it.  First
1679 character is at offset 0. If OFFSET is negative, starts that far from
1680 the end of the string.  
1682 =head2 @length(expression)
1684 Returns the length in characters of the value of EXPR.
1686 =head2 @basename(path)
1688 Return the base name of the file for a given path
1689 (File::Spec::splitpath).
1691 =head2 @dirname(path)
1693 Return the name of the last directory for a given path, assuming the
1694 last component is a file name (File::Spec::splitpath).
1696 =head2 @ipfilter(list)
1698 Filters out the IP addresses that obviously do not match the current
1699 domain.  That is useful to create common variables and rules for IPv4
1700 and IPv6:
1702     @def $TRUSTED_HOSTS = (192.168.0.40 2001:abcd:ef::40);
1704     domain (ip ip6) chain INPUT {
1705         saddr @ipfilter($TRUSTED_HOSTS) proto tcp dport ssh ACCEPT;
1706     }
1708 =head1 RECIPES
1710 The F<./examples/> directory contains numerous ferm configuration
1711 which can be used to begin a new firewall. This sections contains more
1712 samples, recipes and tricks.
1714 =head2 Easy port forwarding
1716 Ferm function make routine tasks quick and easy:
1718     @def &FORWARD_TCP($proto, $port, $dest) = {
1719         table filter chain FORWARD interface $DEV_WORLD outerface $DEV_DMZ daddr $dest proto $proto dport $port ACCEPT;
1720         table nat chain PREROUTING interface $DEV_WORLD daddr $HOST_STATIC proto $proto dport $port DNAT to $dest;
1721     }
1723     &FORWARD_TCP(tcp, http, 192.168.1.2);
1724     &FORWARD_TCP(tcp, smtp, 192.168.1.3);
1725     &FORWARD_TCP((tcp udp), domain, 192.168.1.4);
1727 =head2 Remote B<ferm>
1729 If the target machine is not able to run B<ferm> for some reason
1730 (maybe an embedded device without Perl), you can edit the B<ferm>
1731 configuration file on another computer and let B<ferm> generate a
1732 shell script there.
1734 Example for OpenWRT:
1736     ferm --remote --shell mywrt/ferm.conf >mywrt/firewall.user
1737     chmod +x mywrt/firewall.user
1738     scp mywrt/firewall.user mywrt.local.net:/etc/
1739     ssh mywrt.local.net /etc/firewall.user
1741 =head1 OPTIONS
1743 =over 12
1745 =item B<--noexec>
1747 Do not execute the iptables(8) commands, but skip instead. This way
1748 you can parse your data, use B<--lines> to view the output.
1750 =item B<--flush>
1752 Clears the firewall rules and sets the policy of all chains to ACCEPT.
1753 B<ferm> needs a configuration file for that to determine which domains
1754 and tables are affected.
1756 =item B<--lines>
1758 Show the firewall lines that were generated from the rules. They
1759 will be shown just before they are executed, so if you get error
1760 messages from iptables(8) etc., you can see which rule caused
1761 the error.
1763 =item B<--interactive>
1765 Apply the firewall rules and ask the user for confirmation.  Reverts
1766 to the previous ruleset if there is no valid user response within 30
1767 seconds (see B<--timeout>).  This is useful for remote firewall
1768 administration: you can test the rules without fearing to lock
1769 yourself out.
1771 =item B<--timeout S>
1773 If B<--interactive> is used, then roll back if there is no valid user
1774 response after this number of seconds.  The default is 30.
1776 =item B<--help>
1778 Show a brief list of available commandline options.
1780 =item B<--version>
1782 Shows the version number of the program.
1784 =item B<--fast>
1786 Enable fast mode: ferm generates an iptables-save(8) file, and
1787 installs it with iptables-restore(8). This is much faster, because
1788 ferm calls iptables(8) once for every rule by default.
1790 Fast mode is enabled by default since B<ferm> 2.0, deprecating this
1791 option.
1793 =item B<--slow>
1795 Disable fast mode, i.e. run iptables(8) for every rule, and don't use
1796 iptables-restore(8).
1798 =item B<--shell>
1800 Generate a shell script which calls iptables-restore(8) and prints it.
1801 Implies --fast --lines.
1803 =item B<--remote>
1805 Generate rules for a remote machine.  Implies B<--noexec> and
1806 B<--lines>.  Can be combined with B<--shell>.
1808 =item B<--domain {ip|ip6}>
1810 Handle only the specified domain. B<ferm> output may be empty if the
1811 domain is not configured in the input file.
1813 =item B<--def '$name=value'>
1815 Override a variable defined in the configuration file.
1817 =back
1820 =head1 SEE ALSO
1822 iptables(8)
1825 =head1 REQUIREMENTS
1827 =head2 Operating system
1829 Linux 2.4 or newer, with netfilter support and all netfilter modules
1830 used by your firewall script
1832 =head2 Software
1834 iptables and perl 5.6
1836 =head1 BUGS
1838 Bugs? What bugs?
1840 If you find a bug, please tell us: ferm@foo-projects.org
1842 =head1 COPYRIGHT
1844 Copyright (C) 2001-2012 Max Kellermann <max@foo-projects.org>, Auke
1845 Kok <sofar@foo-projects.org>
1847 This program is free software; you can redistribute it and/or modify
1848 it under the terms of the GNU General Public License as published by
1849 the Free Software Foundation; either version 2 of the License, or (at
1850 your option) any later version.
1852 This program is distributed in the hope that it will be useful, but
1853 WITHOUT ANY WARRANTY; without even the implied warranty of
1854 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1855 General Public License for more details.
1857 You should have received a copy of the GNU General Public License
1858 along with this program; if not, write to the Free Software
1859 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
1862 =head1 AUTHOR
1864 Max Kellermann <max@foo-projects.org>, Auke Kok
1865 <sofar@foo-projects.org>
1867 =cut