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;
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
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;
36 mod state state INVALID DROP;
37 mod state state (ESTABLISHED RELATED) ACCEPT;
39 # allow local connections
43 proto icmp icmp-type echo-request ACCEPT;
46 interface $DEV_WORLD {
47 proto udp dport 500 ACCEPT;
48 proto (esp ah) ACCEPT;
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;
59 # some IRC servers want that
60 interface $DEV_WORLD {
61 proto tcp dport auth ACCEPT;
62 proto tcp dport (8080 3128) REJECT;
65 # the rest is dropped by the above policy (except additional
66 # FORWARD rules added by the function &FORWARD_TCP)
69 # outgoing connections are not limited
70 chain OUTPUT policy ACCEPT;
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
84 outerface $DEV_WORLD ACCEPT;
85 # report failure gracefully
86 REJECT reject-with icmp-net-prohibited;
89 # the rest is dropped by the above policy
95 # masquerade private IP addresses
96 saddr ($NET_PRIVATE $NET_DMZ) outerface $DEV_WORLD SNAT to $HOST_STATIC;
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);