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_untrusted \
42 untrusted:172.29.198.0/25
43 defvpn $if_vpn safe 172.29.199.128/27 \
44 crybaby:172.29.199.129 \
46 defiface $if_iodine untrusted:172.29.198.128/28
47 defiface $if_its_mz safe:172.29.199.160/30
48 defiface $if_its_pi safe:192.168.0.0/24
49 defiface $if_trusted \
50 trusted:172.29.199.0/26 \
51 safe:172.29.199.64/27 \
55 ###--------------------------------------------------------------------------
56 ### Special forwarding exemptions.
58 ## Allow ping from safe/noloop to untrusted networks.
59 run iptables -A FORWARD -j ACCEPT \
60 -p icmp ! -f --icmp-type echo-request \
61 -m mark --mark $to_untrusted/$MASK_TO
62 run iptables -A FORWARD -j ACCEPT \
63 -p icmp ! -f --icmp-type echo-reply \
64 -m mark --mark $from_untrusted/$MASK_FROM \
65 -m state --state ESTABLISHED
66 run ip6tables -A FORWARD -j ACCEPT \
67 -p ipv6-icmp --icmpv6-type echo-request \
68 -m ipv6header --soft ! --header frag \
69 -m mark --mark $to_untrusted/$MASK_TO
70 run ip6tables -A FORWARD -j ACCEPT \
71 -p ipv6-icmp --icmpv6-type echo-reply \
72 -m ipv6header --soft ! --header frag \
73 -m mark --mark $from_untrusted/$MASK_FROM \
74 -m state --state ESTABLISHED
76 ## Allow SSH from safe/noloop to untrusted networks.
77 run iptables -A FORWARD -j ACCEPT \
78 -p tcp ! -f --destination-port $port_ssh \
79 -m mark --mark $to_untrusted/$MASK_TO
80 run iptables -A FORWARD -j ACCEPT \
81 -p tcp ! -f --source-port $port_ssh \
82 -m mark --mark $from_untrusted/$MASK_FROM \
83 -m state --state ESTABLISHED
84 run ip6tables -A FORWARD -j ACCEPT \
85 -p tcp --destination-port $port_ssh \
86 -m ipv6header --soft ! --header frag \
87 -m mark --mark $to_untrusted/$MASK_TO
88 run ip6tables -A FORWARD -j ACCEPT \
89 -p tcp --source-port $port_ssh \
90 -m ipv6header --soft ! --header frag \
91 -m mark --mark $from_untrusted/$MASK_FROM \
92 -m state --state ESTABLISHED
95 ###--------------------------------------------------------------------------
96 ### Kill things we don't understand properly.
98 ### I don't like having to do this, but since I don't know how to do proper
99 ### multicast filtering, I'm just going to ban it from being forwarded.
101 errorchain poorly-understood REJECT
103 ## Ban multicast destination addresses in forwarding.
104 run iptables -A FORWARD -g poorly-understood \
106 run ip6tables -A FORWARD -g poorly-understood \
110 ###--------------------------------------------------------------------------
111 ### Locally-bound packet inspection.
115 ## Track connections.
119 ## Allow incoming bootp. Bootp won't be forwarded, so this is obviously a
121 run iptables -A inbound -j ACCEPT \
122 -s 0.0.0.0 -d 255.255.255.255 \
123 -p udp --source-port $port_bootpc --destination-port $port_bootps
124 run iptables -A inbound -j ACCEPT \
126 -p udp --source-port $port_bootpc --destination-port $port_bootps
128 ## Allow incoming ping. This is the only ICMP left.
129 run ip46tables -A inbound -j ACCEPT -p icmp
132 ## Allow unusual things.
135 ## Inspect inbound packets from untrusted sources.
136 run ip46tables -A inbound -j forbidden
137 run ip46tables -A INPUT -m mark --mark $from_untrusted/$MASK_FROM -g inbound
139 ## Otherwise process as indicated by the mark.
140 for i in INPUT FORWARD; do
141 run ip46tables -A $i -m mark ! --mark 0/$MASK_MASK -j ACCEPT
145 ###----- That's all, folks --------------------------------------------------