Ignore machine-check MSRs
[freebsd-src/fkvm-freebsd.git] / etc / rc.firewall6
blob7498bbc68f5d734aa7874fb68b7843aba5e806fa
1 #!/bin/sh -
2 ############
3 # Setup system for IPv6 firewall service.
4 # $FreeBSD$
6 # Suck in the configuration variables.
7 if [ -z "${source_rc_confs_defined}" ]; then
8 if [ -r /etc/defaults/rc.conf ]; then
9 . /etc/defaults/rc.conf
10 source_rc_confs
11 elif [ -r /etc/rc.conf ]; then
12 . /etc/rc.conf
16 ############
17 # Define the firewall type in /etc/rc.conf. Valid values are:
18 # open - will allow anyone in
19 # client - will try to protect just this machine
20 # simple - will try to protect a whole network
21 # closed - totally disables IP services except via lo0 interface
22 # UNKNOWN - disables the loading of firewall rules.
23 # filename - will load the rules in the given filename (full path required)
25 # For ``client'' and ``simple'' the entries below should be customized
26 # appropriately.
28 ############
30 # If you don't know enough about packet filtering, we suggest that you
31 # take time to read this book:
33 # Building Internet Firewalls, 2nd Edition
34 # Brent Chapman and Elizabeth Zwicky
36 # O'Reilly & Associates, Inc
37 # ISBN 1-56592-871-7
38 # http://www.ora.com/
39 # http://www.oreilly.com/catalog/fire2/
41 # For a more advanced treatment of Internet Security read:
43 # Firewalls and Internet Security: Repelling the Wily Hacker, 2nd Edition
44 # William R. Cheswick, Steven M. Bellowin, Aviel D. Rubin
46 # Addison-Wesley / Prentice Hall
47 # ISBN 0-201-63466-X
48 # http://www.pearsonhighered.com/
49 # http://www.pearsonhighered.com/educator/academic/product/0,3110,020163466X,00.html
52 setup_local () {
53 ############
54 # Only in rare cases do you want to change these rules
56 ${fw6cmd} add 100 pass ip6 from any to any via lo0
57 ${fw6cmd} add 200 deny ip6 from any to ::1
58 ${fw6cmd} add 300 deny ip6 from ::1 to any
60 # ND
62 # DAD
63 ${fw6cmd} add pass ip6 from :: to ff02::/16 proto ipv6-icmp
64 # RS, RA, NS, NA, redirect...
65 ${fw6cmd} add pass ip6 from fe80::/10 to fe80::/10 proto ipv6-icmp
66 ${fw6cmd} add pass ip6 from fe80::/10 to ff02::/16 proto ipv6-icmp
69 if [ -n "${1}" ]; then
70 ipv6_firewall_type="${1}"
73 ############
74 # Set quiet mode if requested
76 case ${ipv6_firewall_quiet} in
77 [Yy][Ee][Ss])
78 fw6cmd="/sbin/ipfw -q"
81 fw6cmd="/sbin/ipfw"
83 esac
85 ############
86 # Flush out the list before we begin.
88 ${fw6cmd} -f flush
90 ############
91 # If you just configured ipfw in the kernel as a tool to solve network
92 # problems or you just want to disallow some particular kinds of traffic
93 # then you will want to change the default policy to open. You can also
94 # do this as your only action by setting the ipv6_firewall_type to ``open''.
96 # ${fw6cmd} add 65000 pass all from any to any
99 # Prototype setups.
101 case ${ipv6_firewall_type} in
102 [Oo][Pp][Ee][Nn])
103 setup_local
104 ${fw6cmd} add 65000 pass ip6 from any to any
107 [Cc][Ll][Ii][Ee][Nn][Tt])
108 ############
109 # This is a prototype setup that will protect your system somewhat
110 # against people from outside your own network.
111 ############
113 # set these to your network and prefixlen and ip
115 # This needs more work
117 net="2001:db8:2:1::"
118 prefixlen="64"
119 ip="2001:db8:2:1::1"
121 setup_local
123 # Allow any traffic to or from my own net.
124 ${fw6cmd} add pass ip6 from ${ip} to ${net}/${prefixlen}
125 ${fw6cmd} add pass ip6 from ${net}/${prefixlen} to ${ip}
127 # Allow any link-local multicast traffic
128 ${fw6cmd} add pass ip6 from fe80::/10 to ff02::/16
129 ${fw6cmd} add pass ip6 from ${net}/${prefixlen} to ff02::/16
131 # Allow TCP through if setup succeeded
132 ${fw6cmd} add pass ip6 from any to any established proto tcp
134 # Allow IP fragments to pass through
135 ${fw6cmd} add pass ip6 from any to any frag
137 # Allow setup of incoming email
138 ${fw6cmd} add pass ip6 from any to ${ip} 25 setup proto tcp
140 # Allow setup of outgoing TCP connections only
141 ${fw6cmd} add pass ip6 from ${ip} to any setup proto tcp
143 # Disallow setup of all other TCP connections
144 ${fw6cmd} add deny ip6 from any to any setup proto tcp
146 # Allow DNS queries out in the world
147 ${fw6cmd} add pass ip6 from any 53 to ${ip} proto udp
148 ${fw6cmd} add pass ip6 from ${ip} to any 53 proto udp
150 # Allow NTP queries out in the world
151 ${fw6cmd} add pass ip6 from any 123 to ${ip} proto udp
152 ${fw6cmd} add pass ip6 from ${ip} to any 123 proto udp
154 # Allow ICMPv6 destination unreach
155 ${fw6cmd} add pass ip6 from any to any icmp6types 1 proto ipv6-icmp
157 # Allow NS/NA/toobig (don't filter it out)
158 ${fw6cmd} add pass ip6 from any to any icmp6types 2,135,136 \
159 proto ipv6-icmp
161 # Everything else is denied by default, unless the
162 # IPV6FIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
163 # config file.
166 [Ss][Ii][Mm][Pp][Ll][Ee])
167 ############
168 # This is a prototype setup for a simple firewall. Configure this
169 # machine as a DNS and NTP server, and point all the machines
170 # on the inside at this machine for those services.
171 ############
173 # set these to your outside interface network and prefixlen and ip
174 oif="ed0"
175 onet="2001:db8:2:1::"
176 oprefixlen="64"
177 oip="2001:db8:2:1::1"
179 # set these to your inside interface network and prefixlen and ip
180 iif="ed1"
181 inet="2001:db8:2:2::"
182 iprefixlen="64"
183 iip="2001:db8:2:2::1"
185 setup_local
187 # Stop spoofing
188 ${fw6cmd} add deny ip6 from ${inet}/${iprefixlen} to any in via ${oif}
189 ${fw6cmd} add deny ip6 from ${onet}/${oprefixlen} to any in via ${iif}
191 # Stop unique local unicast address on the outside interface
192 ${fw6cmd} add deny ip6 from fc00::/7 to any via ${oif}
193 ${fw6cmd} add deny ip6 from any to fc00::/7 via ${oif}
195 # Stop site-local on the outside interface
196 ${fw6cmd} add deny ip6 from fec0::/10 to any via ${oif}
197 ${fw6cmd} add deny ip6 from any to fec0::/10 via ${oif}
199 # Disallow "internal" addresses to appear on the wire.
200 ${fw6cmd} add deny ip6 from ::ffff:0.0.0.0/96 to any via ${oif}
201 ${fw6cmd} add deny ip6 from any to ::ffff:0.0.0.0/96 via ${oif}
203 # Disallow packets to malicious IPv4 compatible prefix.
204 ${fw6cmd} add deny ip6 from ::224.0.0.0/100 to any via ${oif}
205 ${fw6cmd} add deny ip6 from any to ::224.0.0.0/100 via ${oif}
206 ${fw6cmd} add deny ip6 from ::127.0.0.0/104 to any via ${oif}
207 ${fw6cmd} add deny ip6 from any to ::127.0.0.0/104 via ${oif}
208 ${fw6cmd} add deny ip6 from ::0.0.0.0/104 to any via ${oif}
209 ${fw6cmd} add deny ip6 from any to ::0.0.0.0/104 via ${oif}
210 ${fw6cmd} add deny ip6 from ::255.0.0.0/104 to any via ${oif}
211 ${fw6cmd} add deny ip6 from any to ::255.0.0.0/104 via ${oif}
213 ${fw6cmd} add deny ip6 from ::0.0.0.0/96 to any via ${oif}
214 ${fw6cmd} add deny ip6 from any to ::0.0.0.0/96 via ${oif}
216 # Disallow packets to malicious 6to4 prefix.
217 ${fw6cmd} add deny ip6 from 2002:e000::/20 to any via ${oif}
218 ${fw6cmd} add deny ip6 from any to 2002:e000::/20 via ${oif}
219 ${fw6cmd} add deny ip6 from 2002:7f00::/24 to any via ${oif}
220 ${fw6cmd} add deny ip6 from any to 2002:7f00::/24 via ${oif}
221 ${fw6cmd} add deny ip6 from 2002:0000::/24 to any via ${oif}
222 ${fw6cmd} add deny ip6 from any to 2002:0000::/24 via ${oif}
223 ${fw6cmd} add deny ip6 from 2002:ff00::/24 to any via ${oif}
224 ${fw6cmd} add deny ip6 from any to 2002:ff00::/24 via ${oif}
226 ${fw6cmd} add deny ip6 from 2002:0a00::/24 to any via ${oif}
227 ${fw6cmd} add deny ip6 from any to 2002:0a00::/24 via ${oif}
228 ${fw6cmd} add deny ip6 from 2002:ac10::/28 to any via ${oif}
229 ${fw6cmd} add deny ip6 from any to 2002:ac10::/28 via ${oif}
230 ${fw6cmd} add deny ip6 from 2002:c0a8::/32 to any via ${oif}
231 ${fw6cmd} add deny ip6 from any to 2002:c0a8::/32 via ${oif}
233 ${fw6cmd} add deny ip6 from ff05::/16 to any via ${oif}
234 ${fw6cmd} add deny ip6 from any to ff05::/16 via ${oif}
236 # Allow TCP through if setup succeeded
237 ${fw6cmd} add pass tcp from any to any established
239 # Allow IP fragments to pass through
240 ${fw6cmd} add pass ip6 from any to any frag
242 # Allow setup of incoming email
243 ${fw6cmd} add pass ip6 from any to ${oip} 25 setup proto tcp
245 # Allow access to our DNS
246 ${fw6cmd} add pass ip6 from any to ${oip} 53 setup proto tcp
247 ${fw6cmd} add pass ip6 from any to ${oip} 53 proto udp
248 ${fw6cmd} add pass ip6 from ${oip} 53 to any proto udp
250 # Allow access to our WWW
251 ${fw6cmd} add pass ip6 from any to ${oip} 80 setup proto tcp
253 # Reject&Log all setup of incoming connections from the outside
254 ${fw6cmd} add deny log ip6 from any to any in via ${oif} setup \
255 proto tcp
257 # Allow setup of any other TCP connection
258 ${fw6cmd} add pass ip6 from any to any setup proto tcp
260 # Allow DNS queries out in the world
261 ${fw6cmd} add pass ip6 from any 53 to ${oip} proto udp
262 ${fw6cmd} add pass ip6 from ${oip} to any 53 proto udp
264 # Allow NTP queries out in the world
265 ${fw6cmd} add pass ip6 from any 123 to ${oip} proto udp
266 ${fw6cmd} add pass ip6 from ${oip} to any 123 proto udp
268 # Allow RIPng
269 #${fw6cmd} add pass ip6 from fe80::/10 521 to ff02::9 521 proto udp
270 #${fw6cmd} add pass ip6 from fe80::/10 521 to fe80::/10 521 proto udp
272 # Allow ICMPv6 destination unreach
273 ${fw6cmd} add pass ip6 from any to any icmp6types 1 proto ipv6-icmp
275 # Allow NS/NA/toobig (don't filter it out)
276 ${fw6cmd} add pass ip6 from any to any icmp6types 2,135,136 \
277 proto ipv6-icmp
279 # Everything else is denied by default, unless the
280 # IPV6FIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
281 # config file.
284 [Cc][Ll][Oo][Ss][Ee][Dd])
285 # Only enable the loopback interface
286 ${fw6cmd} add 100 pass ip6 from any to any via lo0
288 [Uu][Nn][Kk][Nn][Oo][Ww][Nn])
291 if [ -r "${ipv6_firewall_type}" ]; then
292 ${fw6cmd} ${ipv6_firewall_flags} ${ipv6_firewall_type}
295 esac