Commit | Line | Data |
---|---|---|
775bd287 | 1 | ### -*-sh-*- |
bfdc045d MW |
2 | ### |
3 | ### Local firewall configuration | |
4 | ### | |
5 | ### (c) 2008 Mark Wooding | |
6 | ### | |
7 | ||
8 | ###----- Licensing notice --------------------------------------------------- | |
9 | ### | |
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. | |
14 | ### | |
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. | |
19 | ### | |
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. | |
23 | ||
24 | ###-------------------------------------------------------------------------- | |
25 | ### Packet classification. | |
26 | ||
27 | ## Define the available network classes. | |
28 | m4_divert(42)m4_dnl | |
29 | defnetclass untrusted untrusted trusted | |
30 | defnetclass trusted untrusted trusted safe noloop | |
31 | defnetclass safe trusted safe noloop | |
32 | defnetclass noloop trusted safe | |
33 | m4_divert(-1)m4_dnl | |
34 | ||
35 | ###-------------------------------------------------------------------------- | |
36 | ### Network layout. | |
37 | ||
38 | m4_divert(46)m4_dnl | |
39 | ## Networks and routing. | |
40 | ||
bfdc045d | 41 | defiface $if_untrusted \ |
f98dfdf6 | 42 | untrusted:172.29.198.0/25 |
bfdc045d | 43 | defvpn $if_vpn safe 172.29.199.128/27 \ |
9ec5456a MW |
44 | crybaby:172.29.199.129 \ |
45 | terror:172.29.199.130 | |
f98dfdf6 | 46 | defiface $if_iodine untrusted:172.29.198.128/28 |
bfdc045d MW |
47 | defiface $if_its_mz safe:172.29.199.160/30 |
48 | defiface $if_its_pi safe:192.168.0.0/24 | |
422ec1b2 MW |
49 | defiface $if_trusted \ |
50 | trusted:172.29.199.0/26 \ | |
51 | safe:172.29.199.64/27 \ | |
52 | untrusted:default | |
bfdc045d MW |
53 | |
54 | m4_divert(60)m4_dnl | |
55 | ###-------------------------------------------------------------------------- | |
56 | ### Special forwarding exemptions. | |
57 | ||
58 | ## Allow ping from safe/noloop to untrusted networks. | |
59 | run iptables -A FORWARD -j ACCEPT \ | |
ecdca131 | 60 | -p icmp ! -f --icmp-type echo-request \ |
bfdc045d MW |
61 | -m mark --mark $to_untrusted/$MASK_TO |
62 | run iptables -A FORWARD -j ACCEPT \ | |
ecdca131 | 63 | -p icmp ! -f --icmp-type echo-reply \ |
bfdc045d MW |
64 | -m mark --mark $from_untrusted/$MASK_FROM \ |
65 | -m state --state ESTABLISHED | |
0291d6d5 MW |
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 | |
bfdc045d MW |
75 | |
76 | ## Allow SSH from safe/noloop to untrusted networks. | |
77 | run iptables -A FORWARD -j ACCEPT \ | |
12ac65a1 | 78 | -p tcp ! -f --destination-port $port_ssh \ |
bfdc045d MW |
79 | -m mark --mark $to_untrusted/$MASK_TO |
80 | run iptables -A FORWARD -j ACCEPT \ | |
ecdca131 | 81 | -p tcp ! -f --source-port $port_ssh \ |
bfdc045d MW |
82 | -m mark --mark $from_untrusted/$MASK_FROM \ |
83 | -m state --state ESTABLISHED | |
0291d6d5 MW |
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 | |
bfdc045d MW |
93 | |
94 | m4_divert(80)m4_dnl | |
95 | ###-------------------------------------------------------------------------- | |
96 | ### Locally-bound packet inspection. | |
97 | ||
98 | clearchain inbound | |
99 | ||
100 | ## Track connections. | |
ecdca131 | 101 | commonrules inbound |
bfdc045d MW |
102 | conntrack inbound |
103 | ||
104 | ## Allow incoming bootp. Bootp won't be forwarded, so this is obviously a | |
105 | ## local request. | |
106 | run iptables -A inbound -j ACCEPT \ | |
107 | -s 0.0.0.0 -d 255.255.255.255 \ | |
108 | -p udp --source-port $port_bootpc --destination-port $port_bootps | |
109 | run iptables -A inbound -j ACCEPT \ | |
110 | -s 172.29.198.0/23 \ | |
111 | -p udp --source-port $port_bootpc --destination-port $port_bootps | |
112 | ||
113 | ## Allow incoming ping. This is the only ICMP left. | |
0291d6d5 | 114 | run ip46tables -A inbound -j ACCEPT -p icmp |
bfdc045d MW |
115 | |
116 | m4_divert(88)m4_dnl | |
117 | ## Allow unusual things. | |
118 | openports inbound | |
119 | ||
120 | ## Inspect inbound packets from untrusted sources. | |
0291d6d5 MW |
121 | run ip46tables -A inbound -j forbidden |
122 | run ip46tables -A INPUT -m mark --mark $from_untrusted/$MASK_FROM -g inbound | |
bfdc045d MW |
123 | |
124 | ## Otherwise process as indicated by the mark. | |
125 | for i in INPUT FORWARD; do | |
0291d6d5 | 126 | run ip46tables -A $i -m mark ! --mark 0/$MASK_MASK -j ACCEPT |
bfdc045d MW |
127 | done |
128 | ||
129 | m4_divert(-1) | |
130 | ###----- That's all, folks -------------------------------------------------- |