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