2003-02-06 22:00:38 +00:00
|
|
|
#!/bin/sh -
|
2000-10-29 19:59:05 +00:00
|
|
|
############
|
|
|
|
# Setup system for IPv6 firewall service.
|
|
|
|
# $FreeBSD$
|
|
|
|
|
|
|
|
# Suck in the configuration variables.
|
|
|
|
if [ -z "${source_rc_confs_defined}" ]; then
|
|
|
|
if [ -r /etc/defaults/rc.conf ]; then
|
|
|
|
. /etc/defaults/rc.conf
|
|
|
|
source_rc_confs
|
|
|
|
elif [ -r /etc/rc.conf ]; then
|
|
|
|
. /etc/rc.conf
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
############
|
|
|
|
# Define the firewall type in /etc/rc.conf. Valid values are:
|
|
|
|
# open - will allow anyone in
|
|
|
|
# client - will try to protect just this machine
|
|
|
|
# simple - will try to protect a whole network
|
|
|
|
# closed - totally disables IP services except via lo0 interface
|
|
|
|
# UNKNOWN - disables the loading of firewall rules.
|
|
|
|
# filename - will load the rules in the given filename (full path required)
|
|
|
|
#
|
|
|
|
# For ``client'' and ``simple'' the entries below should be customized
|
|
|
|
# appropriately.
|
|
|
|
|
|
|
|
############
|
|
|
|
#
|
|
|
|
# If you don't know enough about packet filtering, we suggest that you
|
|
|
|
# take time to read this book:
|
|
|
|
#
|
2001-02-25 11:44:51 +00:00
|
|
|
# Building Internet Firewalls, 2nd Edition
|
2000-10-29 19:59:05 +00:00
|
|
|
# Brent Chapman and Elizabeth Zwicky
|
|
|
|
#
|
|
|
|
# O'Reilly & Associates, Inc
|
2001-02-25 11:44:51 +00:00
|
|
|
# ISBN 1-56592-871-7
|
2000-10-29 19:59:05 +00:00
|
|
|
# http://www.ora.com/
|
2001-02-25 11:44:51 +00:00
|
|
|
# http://www.oreilly.com/catalog/fire2/
|
2000-10-29 19:59:05 +00:00
|
|
|
#
|
|
|
|
# For a more advanced treatment of Internet Security read:
|
|
|
|
#
|
2008-01-12 19:02:09 +00:00
|
|
|
# Firewalls and Internet Security: Repelling the Wily Hacker, 2nd Edition
|
|
|
|
# William R. Cheswick, Steven M. Bellowin, Aviel D. Rubin
|
2000-10-29 19:59:05 +00:00
|
|
|
#
|
2008-01-12 19:02:09 +00:00
|
|
|
# Addison-Wesley / Prentice Hall
|
|
|
|
# ISBN 0-201-63466-X
|
|
|
|
# http://www.pearsonhighered.com/
|
|
|
|
# http://www.pearsonhighered.com/educator/academic/product/0,3110,020163466X,00.html
|
2000-10-29 19:59:05 +00:00
|
|
|
#
|
|
|
|
|
2002-02-21 13:14:19 +00:00
|
|
|
setup_local () {
|
|
|
|
############
|
|
|
|
# Only in rare cases do you want to change these rules
|
|
|
|
#
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add 100 pass ip6 from any to any via lo0
|
|
|
|
${fw6cmd} add 200 deny ip6 from any to ::1
|
|
|
|
${fw6cmd} add 300 deny ip6 from ::1 to any
|
2002-02-21 13:14:19 +00:00
|
|
|
#
|
|
|
|
# ND
|
|
|
|
#
|
|
|
|
# DAD
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from :: to ff02::/16 proto ipv6-icmp
|
2002-02-21 13:14:19 +00:00
|
|
|
# RS, RA, NS, NA, redirect...
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from fe80::/10 to fe80::/10 proto ipv6-icmp
|
|
|
|
${fw6cmd} add pass ip6 from fe80::/10 to ff02::/16 proto ipv6-icmp
|
2002-02-21 13:14:19 +00:00
|
|
|
}
|
|
|
|
|
2000-10-29 19:59:05 +00:00
|
|
|
if [ -n "${1}" ]; then
|
|
|
|
ipv6_firewall_type="${1}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
############
|
|
|
|
# Set quiet mode if requested
|
|
|
|
#
|
|
|
|
case ${ipv6_firewall_quiet} in
|
|
|
|
[Yy][Ee][Ss])
|
2006-05-12 19:17:34 +00:00
|
|
|
fw6cmd="/sbin/ipfw -q"
|
2000-10-29 19:59:05 +00:00
|
|
|
;;
|
|
|
|
*)
|
2006-05-12 19:17:34 +00:00
|
|
|
fw6cmd="/sbin/ipfw"
|
2000-10-29 19:59:05 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
############
|
|
|
|
# Flush out the list before we begin.
|
|
|
|
#
|
|
|
|
${fw6cmd} -f flush
|
|
|
|
|
|
|
|
############
|
|
|
|
# If you just configured ipfw in the kernel as a tool to solve network
|
|
|
|
# problems or you just want to disallow some particular kinds of traffic
|
|
|
|
# then you will want to change the default policy to open. You can also
|
|
|
|
# do this as your only action by setting the ipv6_firewall_type to ``open''.
|
|
|
|
#
|
|
|
|
# ${fw6cmd} add 65000 pass all from any to any
|
|
|
|
|
|
|
|
|
|
|
|
# Prototype setups.
|
|
|
|
#
|
|
|
|
case ${ipv6_firewall_type} in
|
|
|
|
[Oo][Pp][Ee][Nn])
|
2002-02-21 13:14:19 +00:00
|
|
|
setup_local
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add 65000 pass ip6 from any to any
|
2000-10-29 19:59:05 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
[Cc][Ll][Ii][Ee][Nn][Tt])
|
|
|
|
############
|
|
|
|
# This is a prototype setup that will protect your system somewhat
|
|
|
|
# against people from outside your own network.
|
|
|
|
############
|
|
|
|
|
|
|
|
# set these to your network and prefixlen and ip
|
|
|
|
#
|
|
|
|
# This needs more work
|
|
|
|
#
|
2004-08-03 08:58:34 +00:00
|
|
|
net="2001:db8:2:1::"
|
2000-10-29 19:59:05 +00:00
|
|
|
prefixlen="64"
|
2004-08-03 08:58:34 +00:00
|
|
|
ip="2001:db8:2:1::1"
|
2000-10-29 19:59:05 +00:00
|
|
|
|
2002-02-21 13:14:19 +00:00
|
|
|
setup_local
|
|
|
|
|
2000-10-29 19:59:05 +00:00
|
|
|
# Allow any traffic to or from my own net.
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from ${ip} to ${net}/${prefixlen}
|
|
|
|
${fw6cmd} add pass ip6 from ${net}/${prefixlen} to ${ip}
|
2000-10-29 19:59:05 +00:00
|
|
|
|
2001-07-21 19:59:35 +00:00
|
|
|
# Allow any link-local multicast traffic
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from fe80::/10 to ff02::/16
|
|
|
|
${fw6cmd} add pass ip6 from ${net}/${prefixlen} to ff02::/16
|
2001-07-21 19:59:35 +00:00
|
|
|
|
2000-10-29 19:59:05 +00:00
|
|
|
# Allow TCP through if setup succeeded
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any to any established proto tcp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Allow IP fragments to pass through
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any to any frag
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Allow setup of incoming email
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any to ${ip} 25 setup proto tcp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Allow setup of outgoing TCP connections only
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from ${ip} to any setup proto tcp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Disallow setup of all other TCP connections
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add deny ip6 from any to any setup proto tcp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Allow DNS queries out in the world
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any 53 to ${ip} proto udp
|
|
|
|
${fw6cmd} add pass ip6 from ${ip} to any 53 proto udp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Allow NTP queries out in the world
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any 123 to ${ip} proto udp
|
|
|
|
${fw6cmd} add pass ip6 from ${ip} to any 123 proto udp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
2001-07-24 13:37:06 +00:00
|
|
|
# Allow ICMPv6 destination unreach
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any to any icmp6types 1 proto ipv6-icmp
|
2001-07-24 13:37:06 +00:00
|
|
|
|
|
|
|
# Allow NS/NA/toobig (don't filter it out)
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any to any icmp6types 2,135,136 \
|
|
|
|
proto ipv6-icmp
|
2001-07-21 19:59:35 +00:00
|
|
|
|
2000-10-29 19:59:05 +00:00
|
|
|
# Everything else is denied by default, unless the
|
2001-06-22 06:25:54 +00:00
|
|
|
# IPV6FIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
|
2000-10-29 19:59:05 +00:00
|
|
|
# config file.
|
|
|
|
;;
|
|
|
|
|
|
|
|
[Ss][Ii][Mm][Pp][Ll][Ee])
|
|
|
|
############
|
|
|
|
# This is a prototype setup for a simple firewall. Configure this
|
2003-11-02 07:31:44 +00:00
|
|
|
# machine as a DNS and NTP server, and point all the machines
|
2000-10-29 19:59:05 +00:00
|
|
|
# on the inside at this machine for those services.
|
|
|
|
############
|
|
|
|
|
|
|
|
# set these to your outside interface network and prefixlen and ip
|
|
|
|
oif="ed0"
|
2004-08-03 08:58:34 +00:00
|
|
|
onet="2001:db8:2:1::"
|
2000-10-29 19:59:05 +00:00
|
|
|
oprefixlen="64"
|
2004-08-03 08:58:34 +00:00
|
|
|
oip="2001:db8:2:1::1"
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# set these to your inside interface network and prefixlen and ip
|
|
|
|
iif="ed1"
|
2004-08-03 08:58:34 +00:00
|
|
|
inet="2001:db8:2:2::"
|
2000-10-29 19:59:05 +00:00
|
|
|
iprefixlen="64"
|
2004-08-03 08:58:34 +00:00
|
|
|
iip="2001:db8:2:2::1"
|
2000-10-29 19:59:05 +00:00
|
|
|
|
2002-02-21 13:14:19 +00:00
|
|
|
setup_local
|
|
|
|
|
2000-10-29 19:59:05 +00:00
|
|
|
# Stop spoofing
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add deny ip6 from ${inet}/${iprefixlen} to any in via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from ${onet}/${oprefixlen} to any in via ${iif}
|
2000-10-29 19:59:05 +00:00
|
|
|
|
2005-10-05 07:00:42 +00:00
|
|
|
# Stop unique local unicast address on the outside interface
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add deny ip6 from fc00::/7 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to fc00::/7 via ${oif}
|
2005-10-05 07:00:42 +00:00
|
|
|
|
2000-10-29 19:59:05 +00:00
|
|
|
# Stop site-local on the outside interface
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add deny ip6 from fec0::/10 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to fec0::/10 via ${oif}
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Disallow "internal" addresses to appear on the wire.
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add deny ip6 from ::ffff:0.0.0.0/96 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to ::ffff:0.0.0.0/96 via ${oif}
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Disallow packets to malicious IPv4 compatible prefix.
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add deny ip6 from ::224.0.0.0/100 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to ::224.0.0.0/100 via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from ::127.0.0.0/104 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to ::127.0.0.0/104 via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from ::0.0.0.0/104 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to ::0.0.0.0/104 via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from ::255.0.0.0/104 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to ::255.0.0.0/104 via ${oif}
|
|
|
|
|
|
|
|
${fw6cmd} add deny ip6 from ::0.0.0.0/96 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to ::0.0.0.0/96 via ${oif}
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Disallow packets to malicious 6to4 prefix.
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add deny ip6 from 2002:e000::/20 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to 2002:e000::/20 via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from 2002:7f00::/24 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to 2002:7f00::/24 via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from 2002:0000::/24 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to 2002:0000::/24 via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from 2002:ff00::/24 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to 2002:ff00::/24 via ${oif}
|
|
|
|
|
|
|
|
${fw6cmd} add deny ip6 from 2002:0a00::/24 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to 2002:0a00::/24 via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from 2002:ac10::/28 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to 2002:ac10::/28 via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from 2002:c0a8::/32 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to 2002:c0a8::/32 via ${oif}
|
|
|
|
|
|
|
|
${fw6cmd} add deny ip6 from ff05::/16 to any via ${oif}
|
|
|
|
${fw6cmd} add deny ip6 from any to ff05::/16 via ${oif}
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Allow TCP through if setup succeeded
|
|
|
|
${fw6cmd} add pass tcp from any to any established
|
|
|
|
|
|
|
|
# Allow IP fragments to pass through
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any to any frag
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Allow setup of incoming email
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any to ${oip} 25 setup proto tcp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Allow access to our DNS
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any to ${oip} 53 setup proto tcp
|
|
|
|
${fw6cmd} add pass ip6 from any to ${oip} 53 proto udp
|
|
|
|
${fw6cmd} add pass ip6 from ${oip} 53 to any proto udp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Allow access to our WWW
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any to ${oip} 80 setup proto tcp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Reject&Log all setup of incoming connections from the outside
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add deny log ip6 from any to any in via ${oif} setup \
|
|
|
|
proto tcp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Allow setup of any other TCP connection
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any to any setup proto tcp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Allow DNS queries out in the world
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any 53 to ${oip} proto udp
|
|
|
|
${fw6cmd} add pass ip6 from ${oip} to any 53 proto udp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Allow NTP queries out in the world
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any 123 to ${oip} proto udp
|
|
|
|
${fw6cmd} add pass ip6 from ${oip} to any 123 proto udp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
2001-07-21 19:59:35 +00:00
|
|
|
# Allow RIPng
|
2006-05-12 19:17:34 +00:00
|
|
|
#${fw6cmd} add pass ip6 from fe80::/10 521 to ff02::9 521 proto udp
|
|
|
|
#${fw6cmd} add pass ip6 from fe80::/10 521 to fe80::/10 521 proto udp
|
2001-07-21 19:59:35 +00:00
|
|
|
|
2001-07-24 13:37:06 +00:00
|
|
|
# Allow ICMPv6 destination unreach
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any to any icmp6types 1 proto ipv6-icmp
|
2001-07-24 13:37:06 +00:00
|
|
|
|
|
|
|
# Allow NS/NA/toobig (don't filter it out)
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add pass ip6 from any to any icmp6types 2,135,136 \
|
|
|
|
proto ipv6-icmp
|
2000-10-29 19:59:05 +00:00
|
|
|
|
|
|
|
# Everything else is denied by default, unless the
|
2001-06-22 06:25:54 +00:00
|
|
|
# IPV6FIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
|
2000-10-29 19:59:05 +00:00
|
|
|
# config file.
|
|
|
|
;;
|
|
|
|
|
2002-02-21 13:14:19 +00:00
|
|
|
[Cc][Ll][Oo][Ss][Ee][Dd])
|
|
|
|
# Only enable the loopback interface
|
2006-05-12 19:17:34 +00:00
|
|
|
${fw6cmd} add 100 pass ip6 from any to any via lo0
|
2002-02-21 13:14:19 +00:00
|
|
|
;;
|
2000-10-29 19:59:05 +00:00
|
|
|
[Uu][Nn][Kk][Nn][Oo][Ww][Nn])
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -r "${ipv6_firewall_type}" ]; then
|
2001-04-13 01:40:27 +00:00
|
|
|
${fw6cmd} ${ipv6_firewall_flags} ${ipv6_firewall_type}
|
2000-10-29 19:59:05 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|