3 ### Local firewall configuration
5 ### (c) 2008 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This program is free software; you can redistribute it and/or modify
11 ### it under the terms of the GNU General Public License as published by
12 ### the Free Software Foundation; either version 2 of the License, or
13 ### (at your option) any later version.
15 ### This program is distributed in the hope that it will be useful,
16 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ### GNU General Public License for more details.
20 ### You should have received a copy of the GNU General Public License
21 ### along with this program; if not, write to the Free Software Foundation,
22 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ###--------------------------------------------------------------------------
25 ### Packet classification.
27 ## Define the available network classes.
29 defnetclass untrusted untrusted trusted
30 defnetclass trusted untrusted trusted safe noloop
31 defnetclass safe trusted safe noloop
32 defnetclass noloop trusted safe
35 ###--------------------------------------------------------------------------
39 ## Networks and routing.
41 defiface $if_trusted \
42 trusted:172.29.199.0/26 \
43 safe:172.29.199.64/27 \
45 defiface $if_untrusted \
46 untrusted:172.29.198.0/25
47 defvpn $if_vpn safe 172.29.199.128/27 \
48 crybaby:172.29.199.129
49 defiface $if_iodine untrusted:172.29.198.128/28
50 defiface $if_its_mz safe:172.29.199.160/30
51 defiface $if_its_pi safe:192.168.0.0/24
54 ###--------------------------------------------------------------------------
55 ### Special forwarding exemptions.
57 ## Allow ping from safe/noloop to untrusted networks.
58 run iptables -A FORWARD -j ACCEPT \
59 -p icmp ! -f --icmp-type echo-request \
60 -m mark --mark $to_untrusted/$MASK_TO
61 run iptables -A FORWARD -j ACCEPT \
62 -p icmp ! -f --icmp-type echo-reply \
63 -m mark --mark $from_untrusted/$MASK_FROM \
64 -m state --state ESTABLISHED
66 ## Allow SSH from safe/noloop to untrusted networks.
67 run iptables -A FORWARD -j ACCEPT \
68 -p tcp ! -f --destination-port $port_ssh \
69 -m mark --mark $to_untrusted/$MASK_TO
70 run iptables -A FORWARD -j ACCEPT \
71 -p tcp ! -f --source-port $port_ssh \
72 -m mark --mark $from_untrusted/$MASK_FROM \
73 -m state --state ESTABLISHED
76 ###--------------------------------------------------------------------------
77 ### Locally-bound packet inspection.
85 ## Allow incoming bootp. Bootp won't be forwarded, so this is obviously a
87 run iptables -A inbound -j ACCEPT \
88 -s 0.0.0.0 -d 255.255.255.255 \
89 -p udp --source-port $port_bootpc --destination-port $port_bootps
90 run iptables -A inbound -j ACCEPT \
92 -p udp --source-port $port_bootpc --destination-port $port_bootps
94 ## Allow incoming ping. This is the only ICMP left.
95 run iptables -A inbound -j ACCEPT -p icmp
98 ## Allow unusual things.
101 ## Inspect inbound packets from untrusted sources.
102 run iptables -A inbound -j forbidden
103 run iptables -A INPUT -m mark --mark $from_untrusted/$MASK_FROM -g inbound
105 ## Otherwise process as indicated by the mark.
106 for i in INPUT FORWARD; do
107 run iptables -A $i -m mark ! --mark 0/$MASK_MASK -j ACCEPT
111 ###----- That's all, folks --------------------------------------------------