]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.firewall6
Fix a KASSERT bug that showed up only in the LINT build, not the
[FreeBSD/FreeBSD.git] / etc / rc.firewall6
1 ############
2 # Setup system for IPv6 firewall service.
3 # $FreeBSD$
4
5 # Suck in the configuration variables.
6 if [ -z "${source_rc_confs_defined}" ]; then
7         if [ -r /etc/defaults/rc.conf ]; then
8                 . /etc/defaults/rc.conf
9                 source_rc_confs
10         elif [ -r /etc/rc.conf ]; then
11                 . /etc/rc.conf
12         fi
13 fi
14
15 ############
16 # Define the firewall type in /etc/rc.conf.  Valid values are:
17 #   open     - will allow anyone in
18 #   client   - will try to protect just this machine
19 #   simple   - will try to protect a whole network
20 #   closed   - totally disables IP services except via lo0 interface
21 #   UNKNOWN  - disables the loading of firewall rules.
22 #   filename - will load the rules in the given filename (full path required)
23 #
24 # For ``client'' and ``simple'' the entries below should be customized
25 # appropriately.
26
27 ############
28 #
29 # If you don't know enough about packet filtering, we suggest that you
30 # take time to read this book:
31 #
32 #       Building Internet Firewalls, 2nd Edition
33 #       Brent Chapman and Elizabeth Zwicky
34 #
35 #       O'Reilly & Associates, Inc
36 #       ISBN 1-56592-871-7
37 #       http://www.ora.com/
38 #       http://www.oreilly.com/catalog/fire2/
39 #
40 # For a more advanced treatment of Internet Security read:
41 #
42 #       Firewalls & Internet Security
43 #       Repelling the wily hacker
44 #       William R. Cheswick, Steven M. Bellowin
45 #
46 #       Addison-Wesley
47 #       ISBN 0-201-63357-4
48 #       http://www.awl.com/
49 #       http://www.awlonline.com/product/0%2C2627%2C0201633574%2C00.html
50 #
51
52 setup_local () {
53         ############
54         # Only in rare cases do you want to change these rules
55         #
56         ${fw6cmd} add 100 pass all from any to any via lo0
57         #
58         # ND
59         #
60         # DAD
61         ${fw6cmd} add pass ipv6-icmp from :: to ff02::/16
62         # RS, RA, NS, NA, redirect...
63         ${fw6cmd} add pass ipv6-icmp from fe80::/10 to fe80::/10
64         ${fw6cmd} add pass ipv6-icmp from fe80::/10 to ff02::/16
65 }
66
67 if [ -n "${1}" ]; then
68         ipv6_firewall_type="${1}"
69 fi
70
71 ############
72 # Set quiet mode if requested
73 #
74 case ${ipv6_firewall_quiet} in
75 [Yy][Ee][Ss])
76         fw6cmd="/sbin/ip6fw -q"
77         ;;
78 *)
79         fw6cmd="/sbin/ip6fw"
80         ;;
81 esac
82
83 ############
84 # Flush out the list before we begin.
85 #
86 ${fw6cmd} -f flush
87
88 ############
89 # If you just configured ipfw in the kernel as a tool to solve network
90 # problems or you just want to disallow some particular kinds of traffic
91 # then you will want to change the default policy to open.  You can also
92 # do this as your only action by setting the ipv6_firewall_type to ``open''.
93 #
94 # ${fw6cmd} add 65000 pass all from any to any
95
96
97 # Prototype setups.
98 #
99 case ${ipv6_firewall_type} in
100 [Oo][Pp][Ee][Nn])
101         setup_local
102         ${fw6cmd} add 65000 pass all from any to any
103         ;;
104
105 [Cc][Ll][Ii][Ee][Nn][Tt])
106         ############
107         # This is a prototype setup that will protect your system somewhat
108         # against people from outside your own network.
109         ############
110
111         # set these to your network and prefixlen and ip
112         #
113         # This needs more work
114         #
115         net="3ffe:505:2:1::"
116         prefixlen="64"
117         ip="3ffe:505:2:1::1"
118
119         setup_local
120
121         # Allow any traffic to or from my own net.
122         ${fw6cmd} add pass all from ${ip} to ${net}/${prefixlen}
123         ${fw6cmd} add pass all from ${net}/${prefixlen} to ${ip}
124
125         # Allow any link-local multicast traffic
126         ${fw6cmd} add pass all from fe80::/10 to ff02::/16
127         ${fw6cmd} add pass all from ${net}/${prefixlen} to ff02::/16
128
129         # Allow TCP through if setup succeeded
130         ${fw6cmd} add pass tcp from any to any established
131
132         # Allow IP fragments to pass through
133         ${fw6cmd} add pass all from any to any frag
134
135         # Allow setup of incoming email
136         ${fw6cmd} add pass tcp from any to ${ip} 25 setup
137
138         # Allow setup of outgoing TCP connections only
139         ${fw6cmd} add pass tcp from ${ip} to any setup
140
141         # Disallow setup of all other TCP connections
142         ${fw6cmd} add deny tcp from any to any setup
143
144         # Allow DNS queries out in the world
145         ${fw6cmd} add pass udp from any 53 to ${ip}
146         ${fw6cmd} add pass udp from ${ip} to any 53
147
148         # Allow NTP queries out in the world
149         ${fw6cmd} add pass udp from any 123 to ${ip}
150         ${fw6cmd} add pass udp from ${ip} to any 123
151
152         # Allow ICMPv6 destination unreach
153         ${fw6cmd} add pass ipv6-icmp from any to any icmptypes 1
154
155         # Allow NS/NA/toobig (don't filter it out)
156         ${fw6cmd} add pass ipv6-icmp from any to any icmptypes 2,135,136
157
158         # Everything else is denied by default, unless the
159         # IPV6FIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
160         # config file.
161         ;;
162
163 [Ss][Ii][Mm][Pp][Ll][Ee])
164         ############
165         # This is a prototype setup for a simple firewall.  Configure this
166         # machine as a named server and ntp server, and point all the machines
167         # on the inside at this machine for those services.
168         ############
169
170         # set these to your outside interface network and prefixlen and ip
171         oif="ed0"
172         onet="3ffe:505:2:1::"
173         oprefixlen="64"
174         oip="3ffe:505:2:1::1"
175
176         # set these to your inside interface network and prefixlen and ip
177         iif="ed1"
178         inet="3ffe:505:2:2::"
179         iprefixlen="64"
180         iip="3ffe:505:2:2::1"
181
182         setup_local
183
184         # Stop spoofing
185         ${fw6cmd} add deny all from ${inet}/${iprefixlen} to any in via ${oif}
186         ${fw6cmd} add deny all from ${onet}/${oprefixlen} to any in via ${iif}
187
188         # Stop site-local on the outside interface
189         ${fw6cmd} add deny all from fec0::/10 to any via ${oif}
190         ${fw6cmd} add deny all from any to fec0::/10 via ${oif}
191
192         # Disallow "internal" addresses to appear on the wire.
193         ${fw6cmd} add deny all from ::ffff:0.0.0.0/96 to any via ${oif}
194         ${fw6cmd} add deny all from any to ::ffff:0.0.0.0/96 via ${oif}
195
196         # Disallow packets to malicious IPv4 compatible prefix.
197         ${fw6cmd} add deny all from ::224.0.0.0/100 to any via ${oif}
198         ${fw6cmd} add deny all from any to ::224.0.0.0/100 via ${oif}
199         ${fw6cmd} add deny all from ::127.0.0.0/104 to any via ${oif}
200         ${fw6cmd} add deny all from any to ::127.0.0.0/104 via ${oif}
201         ${fw6cmd} add deny all from ::0.0.0.0/104 to any via ${oif}
202         ${fw6cmd} add deny all from any to ::0.0.0.0/104 via ${oif}
203         ${fw6cmd} add deny all from ::255.0.0.0/104 to any via ${oif}
204         ${fw6cmd} add deny all from any to ::255.0.0.0/104 via ${oif}
205
206         ${fw6cmd} add deny all from ::0.0.0.0/96 to any via ${oif}
207         ${fw6cmd} add deny all from any to ::0.0.0.0/96 via ${oif}
208
209         # Disallow packets to malicious 6to4 prefix.
210         ${fw6cmd} add deny all from 2002:e000::/20 to any via ${oif}
211         ${fw6cmd} add deny all from any to 2002:e000::/20 via ${oif}
212         ${fw6cmd} add deny all from 2002:7f00::/24 to any via ${oif}
213         ${fw6cmd} add deny all from any to 2002:7f00::/24 via ${oif}
214         ${fw6cmd} add deny all from 2002:0000::/24 to any via ${oif}
215         ${fw6cmd} add deny all from any to 2002:0000::/24 via ${oif}
216         ${fw6cmd} add deny all from 2002:ff00::/24 to any via ${oif}
217         ${fw6cmd} add deny all from any to 2002:ff00::/24 via ${oif}
218
219         ${fw6cmd} add deny all from 2002:0a00::/24 to any via ${oif}
220         ${fw6cmd} add deny all from any to 2002:0a00::/24 via ${oif}
221         ${fw6cmd} add deny all from 2002:ac10::/28 to any via ${oif}
222         ${fw6cmd} add deny all from any to 2002:ac10::/28 via ${oif}
223         ${fw6cmd} add deny all from 2002:c0a8::/32 to any via ${oif}
224         ${fw6cmd} add deny all from any to 2002:c0a8::/32 via ${oif}
225
226         ${fw6cmd} add deny all from ff05::/16 to any via ${oif}
227         ${fw6cmd} add deny all from any to ff05::/16 via ${oif}
228
229         # Allow TCP through if setup succeeded
230         ${fw6cmd} add pass tcp from any to any established
231
232         # Allow IP fragments to pass through
233         ${fw6cmd} add pass all from any to any frag
234
235         # Allow setup of incoming email
236         ${fw6cmd} add pass tcp from any to ${oip} 25 setup
237
238         # Allow access to our DNS
239         ${fw6cmd} add pass tcp from any to ${oip} 53 setup
240         ${fw6cmd} add pass udp from any to ${oip} 53
241         ${fw6cmd} add pass udp from ${oip} 53 to any
242
243         # Allow access to our WWW
244         ${fw6cmd} add pass tcp from any to ${oip} 80 setup
245
246         # Reject&Log all setup of incoming connections from the outside
247         ${fw6cmd} add deny log tcp from any to any in via ${oif} setup
248
249         # Allow setup of any other TCP connection
250         ${fw6cmd} add pass tcp from any to any setup
251
252         # Allow DNS queries out in the world
253         ${fw6cmd} add pass udp from any 53 to ${oip}
254         ${fw6cmd} add pass udp from ${oip} to any 53
255
256         # Allow NTP queries out in the world
257         ${fw6cmd} add pass udp from any 123 to ${oip}
258         ${fw6cmd} add pass udp from ${oip} to any 123
259
260         # Allow RIPng
261         #${fw6cmd} add pass udp from fe80::/10 521 to ff02::9 521
262         #${fw6cmd} add pass udp from fe80::/10 521 to fe80::/10 521
263
264         # Allow ICMPv6 destination unreach
265         ${fw6cmd} add pass ipv6-icmp from any to any icmptypes 1
266
267         # Allow NS/NA/toobig (don't filter it out)
268         ${fw6cmd} add pass ipv6-icmp from any to any icmptypes 2,135,136
269
270         # Everything else is denied by default, unless the
271         # IPV6FIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
272         # config file.
273         ;;
274
275 [Cc][Ll][Oo][Ss][Ee][Dd])
276         # Only enable the loopback interface
277         ${fw6cmd} add 100 pass all from any to any via lo0
278         ;;
279 [Uu][Nn][Kk][Nn][Oo][Ww][Nn])
280         ;;
281 *)
282         if [ -r "${ipv6_firewall_type}" ]; then
283                 ${fw6cmd} ${ipv6_firewall_flags} ${ipv6_firewall_type}
284         fi
285         ;;
286 esac