186d7f5d3SJohn Marino#!/bin/sh 286d7f5d3SJohn Marino############ 386d7f5d3SJohn Marino# Setup system for IPv6 firewall service. 486d7f5d3SJohn Marino# $FreeBSD: src/etc/rc.firewall6,v 1.1.2.11 2003/02/10 05:45:06 trhodes Exp $ 586d7f5d3SJohn Marino# $DragonFly: src/etc/rc.firewall6,v 1.3 2008/08/10 21:29:16 hasso Exp $ 686d7f5d3SJohn Marino 786d7f5d3SJohn Marino# Suck in the configuration variables. 886d7f5d3SJohn Marinoif [ -z "${source_rc_confs_defined}" ]; then 986d7f5d3SJohn Marino if [ -r /etc/defaults/rc.conf ]; then 1086d7f5d3SJohn Marino . /etc/defaults/rc.conf 1186d7f5d3SJohn Marino source_rc_confs 1286d7f5d3SJohn Marino elif [ -r /etc/rc.conf ]; then 1386d7f5d3SJohn Marino . /etc/rc.conf 1486d7f5d3SJohn Marino fi 1586d7f5d3SJohn Marinofi 1686d7f5d3SJohn Marino 1786d7f5d3SJohn Marino############ 1886d7f5d3SJohn Marino# Define the firewall type in /etc/rc.conf. Valid values are: 1986d7f5d3SJohn Marino# open - will allow anyone in 2086d7f5d3SJohn Marino# client - will try to protect just this machine 2186d7f5d3SJohn Marino# simple - will try to protect a whole network 2286d7f5d3SJohn Marino# closed - totally disables IP services except via lo0 interface 2386d7f5d3SJohn Marino# UNKNOWN - disables the loading of firewall rules. 2486d7f5d3SJohn Marino# filename - will load the rules in the given filename (full path required) 2586d7f5d3SJohn Marino# 2686d7f5d3SJohn Marino# For ``client'' and ``simple'' the entries below should be customized 2786d7f5d3SJohn Marino# appropriately. 2886d7f5d3SJohn Marino 2986d7f5d3SJohn Marino############ 3086d7f5d3SJohn Marino# 3186d7f5d3SJohn Marino# If you don't know enough about packet filtering, we suggest that you 3286d7f5d3SJohn Marino# take time to read this book: 3386d7f5d3SJohn Marino# 3486d7f5d3SJohn Marino# Building Internet Firewalls, 2nd Edition 3586d7f5d3SJohn Marino# Brent Chapman and Elizabeth Zwicky 3686d7f5d3SJohn Marino# 3786d7f5d3SJohn Marino# O'Reilly & Associates, Inc 3886d7f5d3SJohn Marino# ISBN 1-56592-871-7 3986d7f5d3SJohn Marino# http://www.ora.com/ 4086d7f5d3SJohn Marino# http://www.oreilly.com/catalog/fire2/ 4186d7f5d3SJohn Marino# 4286d7f5d3SJohn Marino# For a more advanced treatment of Internet Security read: 4386d7f5d3SJohn Marino# 4486d7f5d3SJohn Marino# Firewalls & Internet Security 4586d7f5d3SJohn Marino# Repelling the wily hacker 4686d7f5d3SJohn Marino# William R. Cheswick, Steven M. Bellowin 4786d7f5d3SJohn Marino# 4886d7f5d3SJohn Marino# Addison-Wesley 4986d7f5d3SJohn Marino# ISBN 0-201-63357-4 5086d7f5d3SJohn Marino# http://www.awl.com/ 5186d7f5d3SJohn Marino# http://www.awlonline.com/product/0%2C2627%2C0201633574%2C00.html 5286d7f5d3SJohn Marino# 5386d7f5d3SJohn Marino 5486d7f5d3SJohn Marinosetup_local () { 5586d7f5d3SJohn Marino ############ 5686d7f5d3SJohn Marino # Only in rare cases do you want to change these rules 5786d7f5d3SJohn Marino # 5886d7f5d3SJohn Marino ${fw6cmd} add 100 pass all from any to any via lo0 5986d7f5d3SJohn Marino # 6086d7f5d3SJohn Marino # ND 6186d7f5d3SJohn Marino # 6286d7f5d3SJohn Marino # DAD 6386d7f5d3SJohn Marino ${fw6cmd} add pass ipv6-icmp from :: to ff02::/16 6486d7f5d3SJohn Marino # RS, RA, NS, NA, redirect... 6586d7f5d3SJohn Marino ${fw6cmd} add pass ipv6-icmp from fe80::/10 to fe80::/10 6686d7f5d3SJohn Marino ${fw6cmd} add pass ipv6-icmp from fe80::/10 to ff02::/16 6786d7f5d3SJohn Marino} 6886d7f5d3SJohn Marino 6986d7f5d3SJohn Marinoif [ -n "${1}" ]; then 7086d7f5d3SJohn Marino ipv6_firewall_type="${1}" 7186d7f5d3SJohn Marinofi 7286d7f5d3SJohn Marino 7386d7f5d3SJohn Marino############ 7486d7f5d3SJohn Marino# Set quiet mode if requested 7586d7f5d3SJohn Marino# 7686d7f5d3SJohn Marinocase ${ipv6_firewall_quiet} in 7786d7f5d3SJohn Marino[Yy][Ee][Ss]) 7886d7f5d3SJohn Marino fw6cmd="/sbin/ip6fw -q" 7986d7f5d3SJohn Marino ;; 8086d7f5d3SJohn Marino*) 8186d7f5d3SJohn Marino fw6cmd="/sbin/ip6fw" 8286d7f5d3SJohn Marino ;; 8386d7f5d3SJohn Marinoesac 8486d7f5d3SJohn Marino 8586d7f5d3SJohn Marino############ 8686d7f5d3SJohn Marino# Flush out the list before we begin. 8786d7f5d3SJohn Marino# 8886d7f5d3SJohn Marino${fw6cmd} -f flush 8986d7f5d3SJohn Marino 9086d7f5d3SJohn Marino############ 9186d7f5d3SJohn Marino# If you just configured ipfw in the kernel as a tool to solve network 9286d7f5d3SJohn Marino# problems or you just want to disallow some particular kinds of traffic 9386d7f5d3SJohn Marino# then you will want to change the default policy to open. You can also 9486d7f5d3SJohn Marino# do this as your only action by setting the ipv6_firewall_type to ``open''. 9586d7f5d3SJohn Marino# 9686d7f5d3SJohn Marino# ${fw6cmd} add 65000 pass all from any to any 9786d7f5d3SJohn Marino 9886d7f5d3SJohn Marino 9986d7f5d3SJohn Marino# Prototype setups. 10086d7f5d3SJohn Marino# 10186d7f5d3SJohn Marinocase ${ipv6_firewall_type} in 10286d7f5d3SJohn Marino[Oo][Pp][Ee][Nn]) 10386d7f5d3SJohn Marino setup_local 10486d7f5d3SJohn Marino ${fw6cmd} add 65000 pass all from any to any 10586d7f5d3SJohn Marino ;; 10686d7f5d3SJohn Marino 10786d7f5d3SJohn Marino[Cc][Ll][Ii][Ee][Nn][Tt]) 10886d7f5d3SJohn Marino ############ 10986d7f5d3SJohn Marino # This is a prototype setup that will protect your system somewhat 11086d7f5d3SJohn Marino # against people from outside your own network. 11186d7f5d3SJohn Marino ############ 11286d7f5d3SJohn Marino 11386d7f5d3SJohn Marino # set these to your network and prefixlen and ip 11486d7f5d3SJohn Marino # 11586d7f5d3SJohn Marino # This needs more work 11686d7f5d3SJohn Marino # 11786d7f5d3SJohn Marino net="2001:db8:2:1::" 11886d7f5d3SJohn Marino prefixlen="64" 11986d7f5d3SJohn Marino ip="2001:db8:2:1::1" 12086d7f5d3SJohn Marino 12186d7f5d3SJohn Marino setup_local 12286d7f5d3SJohn Marino 12386d7f5d3SJohn Marino # Allow any traffic to or from my own net. 12486d7f5d3SJohn Marino ${fw6cmd} add pass all from ${ip} to ${net}/${prefixlen} 12586d7f5d3SJohn Marino ${fw6cmd} add pass all from ${net}/${prefixlen} to ${ip} 12686d7f5d3SJohn Marino 12786d7f5d3SJohn Marino # Allow any link-local multicast traffic 12886d7f5d3SJohn Marino ${fw6cmd} add pass all from fe80::/10 to ff02::/16 12986d7f5d3SJohn Marino ${fw6cmd} add pass all from ${net}/${prefixlen} to ff02::/16 13086d7f5d3SJohn Marino 13186d7f5d3SJohn Marino # Allow TCP through if setup succeeded 13286d7f5d3SJohn Marino ${fw6cmd} add pass tcp from any to any established 13386d7f5d3SJohn Marino 13486d7f5d3SJohn Marino # Allow IP fragments to pass through 13586d7f5d3SJohn Marino ${fw6cmd} add pass all from any to any frag 13686d7f5d3SJohn Marino 13786d7f5d3SJohn Marino # Allow setup of incoming email 13886d7f5d3SJohn Marino ${fw6cmd} add pass tcp from any to ${ip} 25 setup 13986d7f5d3SJohn Marino 14086d7f5d3SJohn Marino # Allow setup of outgoing TCP connections only 14186d7f5d3SJohn Marino ${fw6cmd} add pass tcp from ${ip} to any setup 14286d7f5d3SJohn Marino 14386d7f5d3SJohn Marino # Disallow setup of all other TCP connections 14486d7f5d3SJohn Marino ${fw6cmd} add deny tcp from any to any setup 14586d7f5d3SJohn Marino 14686d7f5d3SJohn Marino # Allow DNS queries out in the world 14786d7f5d3SJohn Marino ${fw6cmd} add pass udp from any 53 to ${ip} 14886d7f5d3SJohn Marino ${fw6cmd} add pass udp from ${ip} to any 53 14986d7f5d3SJohn Marino 15086d7f5d3SJohn Marino # Allow NTP queries out in the world 15186d7f5d3SJohn Marino ${fw6cmd} add pass udp from any 123 to ${ip} 15286d7f5d3SJohn Marino ${fw6cmd} add pass udp from ${ip} to any 123 15386d7f5d3SJohn Marino 15486d7f5d3SJohn Marino # Allow ICMPv6 destination unreach 15586d7f5d3SJohn Marino ${fw6cmd} add pass ipv6-icmp from any to any icmptypes 1 15686d7f5d3SJohn Marino 15786d7f5d3SJohn Marino # Allow NS/NA/toobig (don't filter it out) 15886d7f5d3SJohn Marino ${fw6cmd} add pass ipv6-icmp from any to any icmptypes 2,135,136 15986d7f5d3SJohn Marino 16086d7f5d3SJohn Marino # Everything else is denied by default, unless the 16186d7f5d3SJohn Marino # IPV6FIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel 16286d7f5d3SJohn Marino # config file. 16386d7f5d3SJohn Marino ;; 16486d7f5d3SJohn Marino 16586d7f5d3SJohn Marino[Ss][Ii][Mm][Pp][Ll][Ee]) 16686d7f5d3SJohn Marino ############ 16786d7f5d3SJohn Marino # This is a prototype setup for a simple firewall. Configure this 16886d7f5d3SJohn Marino # machine as a named server and ntp server, and point all the machines 16986d7f5d3SJohn Marino # on the inside at this machine for those services. 17086d7f5d3SJohn Marino ############ 17186d7f5d3SJohn Marino 17286d7f5d3SJohn Marino # set these to your outside interface network and prefixlen and ip 17386d7f5d3SJohn Marino oif="ed0" 17486d7f5d3SJohn Marino onet="2001:db8:2:1::" 17586d7f5d3SJohn Marino oprefixlen="64" 17686d7f5d3SJohn Marino oip="2001:db8:2:1::1" 17786d7f5d3SJohn Marino 17886d7f5d3SJohn Marino # set these to your inside interface network and prefixlen and ip 17986d7f5d3SJohn Marino iif="ed1" 18086d7f5d3SJohn Marino inet="2001:db8:2:2::" 18186d7f5d3SJohn Marino iprefixlen="64" 18286d7f5d3SJohn Marino iip="2001:db8:2:2::1" 18386d7f5d3SJohn Marino 18486d7f5d3SJohn Marino setup_local 18586d7f5d3SJohn Marino 18686d7f5d3SJohn Marino # Stop spoofing 18786d7f5d3SJohn Marino ${fw6cmd} add deny all from ${inet}/${iprefixlen} to any in via ${oif} 18886d7f5d3SJohn Marino ${fw6cmd} add deny all from ${onet}/${oprefixlen} to any in via ${iif} 18986d7f5d3SJohn Marino 19086d7f5d3SJohn Marino # Stop site-local on the outside interface 19186d7f5d3SJohn Marino ${fw6cmd} add deny all from fec0::/10 to any via ${oif} 19286d7f5d3SJohn Marino ${fw6cmd} add deny all from any to fec0::/10 via ${oif} 19386d7f5d3SJohn Marino 19486d7f5d3SJohn Marino # Disallow "internal" addresses to appear on the wire. 19586d7f5d3SJohn Marino ${fw6cmd} add deny all from ::ffff:0.0.0.0/96 to any via ${oif} 19686d7f5d3SJohn Marino ${fw6cmd} add deny all from any to ::ffff:0.0.0.0/96 via ${oif} 19786d7f5d3SJohn Marino 19886d7f5d3SJohn Marino # Disallow packets to malicious IPv4 compatible prefix. 19986d7f5d3SJohn Marino ${fw6cmd} add deny all from ::224.0.0.0/100 to any via ${oif} 20086d7f5d3SJohn Marino ${fw6cmd} add deny all from any to ::224.0.0.0/100 via ${oif} 20186d7f5d3SJohn Marino ${fw6cmd} add deny all from ::127.0.0.0/104 to any via ${oif} 20286d7f5d3SJohn Marino ${fw6cmd} add deny all from any to ::127.0.0.0/104 via ${oif} 20386d7f5d3SJohn Marino ${fw6cmd} add deny all from ::0.0.0.0/104 to any via ${oif} 20486d7f5d3SJohn Marino ${fw6cmd} add deny all from any to ::0.0.0.0/104 via ${oif} 20586d7f5d3SJohn Marino ${fw6cmd} add deny all from ::255.0.0.0/104 to any via ${oif} 20686d7f5d3SJohn Marino ${fw6cmd} add deny all from any to ::255.0.0.0/104 via ${oif} 20786d7f5d3SJohn Marino 20886d7f5d3SJohn Marino ${fw6cmd} add deny all from ::0.0.0.0/96 to any via ${oif} 20986d7f5d3SJohn Marino ${fw6cmd} add deny all from any to ::0.0.0.0/96 via ${oif} 21086d7f5d3SJohn Marino 21186d7f5d3SJohn Marino # Disallow packets to malicious 6to4 prefix. 21286d7f5d3SJohn Marino ${fw6cmd} add deny all from 2002:e000::/20 to any via ${oif} 21386d7f5d3SJohn Marino ${fw6cmd} add deny all from any to 2002:e000::/20 via ${oif} 21486d7f5d3SJohn Marino ${fw6cmd} add deny all from 2002:7f00::/24 to any via ${oif} 21586d7f5d3SJohn Marino ${fw6cmd} add deny all from any to 2002:7f00::/24 via ${oif} 21686d7f5d3SJohn Marino ${fw6cmd} add deny all from 2002:0000::/24 to any via ${oif} 21786d7f5d3SJohn Marino ${fw6cmd} add deny all from any to 2002:0000::/24 via ${oif} 21886d7f5d3SJohn Marino ${fw6cmd} add deny all from 2002:ff00::/24 to any via ${oif} 21986d7f5d3SJohn Marino ${fw6cmd} add deny all from any to 2002:ff00::/24 via ${oif} 22086d7f5d3SJohn Marino 22186d7f5d3SJohn Marino ${fw6cmd} add deny all from 2002:0a00::/24 to any via ${oif} 22286d7f5d3SJohn Marino ${fw6cmd} add deny all from any to 2002:0a00::/24 via ${oif} 22386d7f5d3SJohn Marino ${fw6cmd} add deny all from 2002:ac10::/28 to any via ${oif} 22486d7f5d3SJohn Marino ${fw6cmd} add deny all from any to 2002:ac10::/28 via ${oif} 22586d7f5d3SJohn Marino ${fw6cmd} add deny all from 2002:c0a8::/32 to any via ${oif} 22686d7f5d3SJohn Marino ${fw6cmd} add deny all from any to 2002:c0a8::/32 via ${oif} 22786d7f5d3SJohn Marino 22886d7f5d3SJohn Marino ${fw6cmd} add deny all from ff05::/16 to any via ${oif} 22986d7f5d3SJohn Marino ${fw6cmd} add deny all from any to ff05::/16 via ${oif} 23086d7f5d3SJohn Marino 23186d7f5d3SJohn Marino # Allow TCP through if setup succeeded 23286d7f5d3SJohn Marino ${fw6cmd} add pass tcp from any to any established 23386d7f5d3SJohn Marino 23486d7f5d3SJohn Marino # Allow IP fragments to pass through 23586d7f5d3SJohn Marino ${fw6cmd} add pass all from any to any frag 23686d7f5d3SJohn Marino 23786d7f5d3SJohn Marino # Allow setup of incoming email 23886d7f5d3SJohn Marino ${fw6cmd} add pass tcp from any to ${oip} 25 setup 23986d7f5d3SJohn Marino 24086d7f5d3SJohn Marino # Allow access to our DNS 24186d7f5d3SJohn Marino ${fw6cmd} add pass tcp from any to ${oip} 53 setup 24286d7f5d3SJohn Marino ${fw6cmd} add pass udp from any to ${oip} 53 24386d7f5d3SJohn Marino ${fw6cmd} add pass udp from ${oip} 53 to any 24486d7f5d3SJohn Marino 24586d7f5d3SJohn Marino # Allow access to our WWW 24686d7f5d3SJohn Marino ${fw6cmd} add pass tcp from any to ${oip} 80 setup 24786d7f5d3SJohn Marino 24886d7f5d3SJohn Marino # Reject&Log all setup of incoming connections from the outside 24986d7f5d3SJohn Marino ${fw6cmd} add deny log tcp from any to any in via ${oif} setup 25086d7f5d3SJohn Marino 25186d7f5d3SJohn Marino # Allow setup of any other TCP connection 25286d7f5d3SJohn Marino ${fw6cmd} add pass tcp from any to any setup 25386d7f5d3SJohn Marino 25486d7f5d3SJohn Marino # Allow DNS queries out in the world 25586d7f5d3SJohn Marino ${fw6cmd} add pass udp from any 53 to ${oip} 25686d7f5d3SJohn Marino ${fw6cmd} add pass udp from ${oip} to any 53 25786d7f5d3SJohn Marino 25886d7f5d3SJohn Marino # Allow NTP queries out in the world 25986d7f5d3SJohn Marino ${fw6cmd} add pass udp from any 123 to ${oip} 26086d7f5d3SJohn Marino ${fw6cmd} add pass udp from ${oip} to any 123 26186d7f5d3SJohn Marino 26286d7f5d3SJohn Marino # Allow RIPng 26386d7f5d3SJohn Marino #${fw6cmd} add pass udp from fe80::/10 521 to ff02::9 521 26486d7f5d3SJohn Marino #${fw6cmd} add pass udp from fe80::/10 521 to fe80::/10 521 26586d7f5d3SJohn Marino 26686d7f5d3SJohn Marino # Allow ICMPv6 destination unreach 26786d7f5d3SJohn Marino ${fw6cmd} add pass ipv6-icmp from any to any icmptypes 1 26886d7f5d3SJohn Marino 26986d7f5d3SJohn Marino # Allow NS/NA/toobig (don't filter it out) 27086d7f5d3SJohn Marino ${fw6cmd} add pass ipv6-icmp from any to any icmptypes 2,135,136 27186d7f5d3SJohn Marino 27286d7f5d3SJohn Marino # Everything else is denied by default, unless the 27386d7f5d3SJohn Marino # IPV6FIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel 27486d7f5d3SJohn Marino # config file. 27586d7f5d3SJohn Marino ;; 27686d7f5d3SJohn Marino 27786d7f5d3SJohn Marino[Cc][Ll][Oo][Ss][Ee][Dd]) 27886d7f5d3SJohn Marino # Only enable the loopback interface 27986d7f5d3SJohn Marino ${fw6cmd} add 100 pass all from any to any via lo0 28086d7f5d3SJohn Marino ;; 28186d7f5d3SJohn Marino[Uu][Nn][Kk][Nn][Oo][Ww][Nn]) 28286d7f5d3SJohn Marino ;; 28386d7f5d3SJohn Marino*) 28486d7f5d3SJohn Marino if [ -r "${ipv6_firewall_type}" ]; then 28586d7f5d3SJohn Marino ${fw6cmd} ${ipv6_firewall_flags} ${ipv6_firewall_type} 28686d7f5d3SJohn Marino fi 28786d7f5d3SJohn Marino ;; 28886d7f5d3SJohn Marinoesac 289