Automatically apply @ipfilter on dual-stack config
[ferm.git] / examples / dmz_router.ferm
blob1949e01d85caa45f33512ef8aa8573b1f1cf5b4a
1 # -*- shell-script -*-
3 # Ferm example script
5 # Firewall configuration for a router with a static IP and a demilitarized
6 # zone on the third device.
8 # Author: Max Kellermann <max@duempel.org>
11 @def $DEV_PRIVATE = eth0;
12 @def $DEV_WORLD = eth1;
13 @def $DEV_DMZ = eth2;
15 @def $NET_PRIVATE = 192.168.0.0/24;
16 @def $NET_DMZ = 192.168.1.0/24;
18 # internal IPs of the admins
19 @def $HOST_ADMIN = (192.168.0.4 192.168.0.10);
21 # our static IP address
22 @def $HOST_STATIC = 193.43.91.203;
24 # convenience function which creates both the nat/DNAT and the filter/FORWARD
25 # rule
26 @def &FORWARD_TCP($proto, $port, $dest) = {
27     table filter chain FORWARD interface $DEV_WORLD outerface $DEV_DMZ daddr $dest proto $proto dport $port ACCEPT;
28     table nat chain PREROUTING interface $DEV_WORLD daddr $HOST_STATIC proto $proto dport $port DNAT to $dest;
31 table filter {
32     chain INPUT {
33         policy DROP;
35         # connection tracking
36         mod state state INVALID DROP;
37         mod state state (ESTABLISHED RELATED) ACCEPT;
39         # allow local connections
40         interface lo ACCEPT;
42         # respond to ping
43         proto icmp icmp-type echo-request ACCEPT;
45         # for IPsec
46         interface $DEV_WORLD {
47             proto udp dport 500 ACCEPT;
48             proto (esp ah) ACCEPT;
49         }
51         # allow SSH connections from the administrator's workstation
52         interface $DEV_PRIVATE saddr $HOST_ADMIN proto tcp dport ssh ACCEPT;
54         # we provide DNS for the internal net
55         interface ($DEV_PRIVATE $DEV_DMZ) {
56             proto (udp tcp) dport domain ACCEPT;
57         }
59         # some IRC servers want that
60         interface $DEV_WORLD {
61             proto tcp dport auth ACCEPT;
62             proto tcp dport (8080 3128) REJECT;
63         }
65         # the rest is dropped by the above policy (except additional
66         # FORWARD rules added by the function &FORWARD_TCP)
67     }
69     # outgoing connections are not limited
70     chain OUTPUT policy ACCEPT;
72     chain FORWARD {
73         policy DROP;
75         # connection tracking
76         mod state state INVALID DROP;
77         mod state state (ESTABLISHED RELATED) ACCEPT;
79         # the internal net may go everywhere
80         interface $DEV_PRIVATE ACCEPT;
82         # the DMZ may only access the internet
83         interface $DEV_DMZ {
84             outerface $DEV_WORLD ACCEPT;
85             # report failure gracefully
86             REJECT reject-with icmp-net-prohibited;
87         }
89         # the rest is dropped by the above policy
90     }
93 table nat {
94     chain POSTROUTING {
95         # masquerade private IP addresses
96         saddr ($NET_PRIVATE $NET_DMZ) outerface $DEV_WORLD SNAT to $HOST_STATIC;
97     }
100 # forward connections to servers located in the DMZ
101 &FORWARD_TCP(tcp, http, 192.168.1.2);
102 &FORWARD_TCP(tcp, smtp, 192.168.1.3);
103 &FORWARD_TCP((tcp udp), domain, 192.168.1.4);