2003-02-06 22:00:38 +00:00
|
|
|
#!/bin/sh -
|
2000-10-08 19:20:36 +00:00
|
|
|
# Copyright (c) 1996 Poul-Henning Kamp
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
# SUCH DAMAGE.
|
|
|
|
#
|
1999-08-27 23:37:10 +00:00
|
|
|
# $FreeBSD$
|
2000-10-08 19:20:36 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
#
|
2007-04-05 10:44:25 +00:00
|
|
|
# Setup system for ipfw(4) firewall service.
|
2000-10-08 19:20:36 +00:00
|
|
|
#
|
1998-02-10 01:45:57 +00:00
|
|
|
|
1999-02-10 18:08:16 +00:00
|
|
|
# Suck in the configuration variables.
|
2001-08-14 05:50:19 +00:00
|
|
|
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
|
1998-02-10 01:45:57 +00:00
|
|
|
fi
|
1996-04-03 17:13:59 +00:00
|
|
|
|
|
|
|
############
|
1997-09-11 10:59:02 +00:00
|
|
|
# Define the firewall type in /etc/rc.conf. Valid values are:
|
2006-10-28 20:08:12 +00:00
|
|
|
# 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
|
2012-01-07 16:10:32 +00:00
|
|
|
# workstation - will try to protect just this machine using stateful
|
2006-10-28 20:08:12 +00:00
|
|
|
# firewalling. See below for rc.conf variables used
|
|
|
|
# UNKNOWN - disables the loading of firewall rules.
|
|
|
|
# filename - will load the rules in the given filename (full path required)
|
1996-04-03 17:13:59 +00:00
|
|
|
#
|
1999-09-13 15:44:20 +00:00
|
|
|
# For ``client'' and ``simple'' the entries below should be customized
|
1997-09-11 10:59:02 +00:00
|
|
|
# appropriately.
|
1996-08-14 14:42:05 +00:00
|
|
|
|
1996-04-03 17:13:59 +00:00
|
|
|
############
|
|
|
|
#
|
|
|
|
# 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
|
1996-04-12 09:16:42 +00:00
|
|
|
# Brent Chapman and Elizabeth Zwicky
|
|
|
|
#
|
|
|
|
# O'Reilly & Associates, Inc
|
2001-02-25 11:44:51 +00:00
|
|
|
# ISBN 1-56592-871-7
|
1997-05-05 07:08:31 +00:00
|
|
|
# http://www.ora.com/
|
2001-02-25 11:44:51 +00:00
|
|
|
# http://www.oreilly.com/catalog/fire2/
|
1996-04-12 09:16:42 +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
|
1996-04-03 17:13:59 +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
|
1996-04-03 17:13:59 +00:00
|
|
|
#
|
|
|
|
|
2012-07-13 06:46:09 +00:00
|
|
|
setup_loopback() {
|
2002-02-21 13:14:19 +00:00
|
|
|
############
|
|
|
|
# Only in rare cases do you want to change these rules
|
|
|
|
#
|
|
|
|
${fwcmd} add 100 pass all from any to any via lo0
|
|
|
|
${fwcmd} add 200 deny all from any to 127.0.0.0/8
|
|
|
|
${fwcmd} add 300 deny ip from 127.0.0.0/8 to any
|
2009-12-02 15:05:26 +00:00
|
|
|
if [ $ipv6_available -eq 0 ]; then
|
|
|
|
${fwcmd} add 400 deny all from any to ::1
|
|
|
|
${fwcmd} add 500 deny all from ::1 to any
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-07-13 06:46:09 +00:00
|
|
|
setup_ipv6_mandatory() {
|
2009-12-02 15:05:26 +00:00
|
|
|
[ $ipv6_available -eq 0 ] || return 0
|
|
|
|
|
|
|
|
############
|
|
|
|
# Only in rare cases do you want to change these rules
|
|
|
|
#
|
|
|
|
# ND
|
|
|
|
#
|
|
|
|
# DAD
|
|
|
|
${fwcmd} add pass ipv6-icmp from :: to ff02::/16
|
|
|
|
# RS, RA, NS, NA, redirect...
|
|
|
|
${fwcmd} add pass ipv6-icmp from fe80::/10 to fe80::/10
|
|
|
|
${fwcmd} add pass ipv6-icmp from fe80::/10 to ff02::/16
|
|
|
|
|
2012-01-07 16:10:32 +00:00
|
|
|
# Allow ICMPv6 destination unreachable
|
2009-12-02 15:05:26 +00:00
|
|
|
${fwcmd} add pass ipv6-icmp from any to any icmp6types 1
|
|
|
|
|
|
|
|
# Allow NS/NA/toobig (don't filter it out)
|
|
|
|
${fwcmd} add pass ipv6-icmp from any to any icmp6types 2,135,136
|
2002-02-21 13:14:19 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 08:25:39 +00:00
|
|
|
. /etc/rc.subr
|
|
|
|
. /etc/network.subr
|
|
|
|
|
1999-09-13 15:44:20 +00:00
|
|
|
if [ -n "${1}" ]; then
|
|
|
|
firewall_type="${1}"
|
1997-09-11 10:59:02 +00:00
|
|
|
fi
|
2018-02-22 08:25:39 +00:00
|
|
|
if [ -z "${firewall_rc_config_load}" ]; then
|
|
|
|
load_rc_config ipfw
|
|
|
|
else
|
|
|
|
for i in ${firewall_rc_config_load}; do
|
|
|
|
load_rc_config $i
|
|
|
|
done
|
|
|
|
fi
|
1997-09-11 10:59:02 +00:00
|
|
|
|
2009-12-02 15:05:26 +00:00
|
|
|
afexists inet6
|
|
|
|
ipv6_available=$?
|
|
|
|
|
1997-09-11 10:59:02 +00:00
|
|
|
############
|
|
|
|
# Set quiet mode if requested
|
1999-09-13 15:44:20 +00:00
|
|
|
#
|
|
|
|
case ${firewall_quiet} in
|
|
|
|
[Yy][Ee][Ss])
|
1997-09-11 10:59:02 +00:00
|
|
|
fwcmd="/sbin/ipfw -q"
|
1999-09-13 15:44:20 +00:00
|
|
|
;;
|
|
|
|
*)
|
1997-09-11 10:59:02 +00:00
|
|
|
fwcmd="/sbin/ipfw"
|
1999-09-13 15:44:20 +00:00
|
|
|
;;
|
|
|
|
esac
|
1997-09-11 10:59:02 +00:00
|
|
|
|
1996-06-22 00:54:36 +00:00
|
|
|
############
|
|
|
|
# Flush out the list before we begin.
|
1999-09-13 15:44:20 +00:00
|
|
|
#
|
1999-08-25 16:01:45 +00:00
|
|
|
${fwcmd} -f flush
|
1996-06-22 00:54:36 +00:00
|
|
|
|
2006-10-28 20:08:12 +00:00
|
|
|
setup_loopback
|
2009-12-02 15:05:26 +00:00
|
|
|
setup_ipv6_mandatory
|
2006-10-28 20:08:12 +00:00
|
|
|
|
1998-04-18 10:27:19 +00:00
|
|
|
############
|
2000-08-04 14:02:11 +00:00
|
|
|
# Network Address Translation. All packets are passed to natd(8)
|
|
|
|
# before they encounter your remaining rules. The firewall rules
|
|
|
|
# will then be run again on each packet after translation by natd
|
|
|
|
# starting at the rule number following the divert rule.
|
1999-09-13 15:44:20 +00:00
|
|
|
#
|
2000-08-04 14:02:11 +00:00
|
|
|
# For ``simple'' firewall type the divert rule should be put to a
|
|
|
|
# different place to not interfere with address-checking rules.
|
2001-03-06 02:15:38 +00:00
|
|
|
#
|
2000-08-04 14:02:11 +00:00
|
|
|
case ${firewall_type} in
|
2000-08-30 13:14:32 +00:00
|
|
|
[Oo][Pp][Ee][Nn]|[Cc][Ll][Ii][Ee][Nn][Tt])
|
2000-08-04 14:02:11 +00:00
|
|
|
case ${natd_enable} in
|
|
|
|
[Yy][Ee][Ss])
|
|
|
|
if [ -n "${natd_interface}" ]; then
|
2005-11-18 02:23:59 +00:00
|
|
|
${fwcmd} add 50 divert natd ip4 from any to any via ${natd_interface}
|
2000-08-04 14:02:11 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2006-12-29 21:59:17 +00:00
|
|
|
case ${firewall_nat_enable} in
|
|
|
|
[Yy][Ee][Ss])
|
|
|
|
if [ -n "${firewall_nat_interface}" ]; then
|
2008-01-21 04:41:18 +00:00
|
|
|
if echo "${firewall_nat_interface}" | \
|
|
|
|
grep -q -E '^[0-9]+(\.[0-9]+){0,3}$'; then
|
|
|
|
firewall_nat_flags="ip ${firewall_nat_interface} ${firewall_nat_flags}"
|
|
|
|
else
|
|
|
|
firewall_nat_flags="if ${firewall_nat_interface} ${firewall_nat_flags}"
|
|
|
|
fi
|
|
|
|
${fwcmd} nat 123 config log ${firewall_nat_flags}
|
2006-12-29 21:59:17 +00:00
|
|
|
${fwcmd} add 50 nat 123 ip4 from any to any via ${firewall_nat_interface}
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
1999-09-13 15:44:20 +00:00
|
|
|
esac
|
1998-04-18 10:27:19 +00:00
|
|
|
|
1996-04-03 17:13:59 +00:00
|
|
|
############
|
|
|
|
# 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
|
1999-09-30 04:55:23 +00:00
|
|
|
# then you will want to change the default policy to open. You can also
|
1996-08-14 14:42:05 +00:00
|
|
|
# do this as your only action by setting the firewall_type to ``open''.
|
1999-09-13 15:44:20 +00:00
|
|
|
#
|
1999-08-25 16:01:45 +00:00
|
|
|
# ${fwcmd} add 65000 pass all from any to any
|
1996-04-03 17:13:59 +00:00
|
|
|
|
|
|
|
|
1996-08-14 14:42:05 +00:00
|
|
|
# Prototype setups.
|
1999-09-13 15:44:20 +00:00
|
|
|
#
|
|
|
|
case ${firewall_type} in
|
|
|
|
[Oo][Pp][Ee][Nn])
|
1999-08-25 16:01:45 +00:00
|
|
|
${fwcmd} add 65000 pass all from any to any
|
1999-09-13 15:44:20 +00:00
|
|
|
;;
|
1996-08-14 14:42:05 +00:00
|
|
|
|
1999-12-04 01:27:51 +00:00
|
|
|
[Cc][Ll][Ii][Ee][Nn][Tt])
|
1999-09-13 15:44:20 +00:00
|
|
|
############
|
|
|
|
# This is a prototype setup that will protect your system somewhat
|
|
|
|
# against people from outside your own network.
|
2008-08-15 19:20:59 +00:00
|
|
|
#
|
|
|
|
# Configuration:
|
2009-12-02 15:05:26 +00:00
|
|
|
# firewall_client_net: Network address of local IPv4 network.
|
|
|
|
# firewall_client_net_ipv6: Network address of local IPv6 network.
|
1999-09-13 15:44:20 +00:00
|
|
|
############
|
|
|
|
|
2008-08-15 19:20:59 +00:00
|
|
|
# set this to your local network
|
|
|
|
net="$firewall_client_net"
|
2009-12-02 15:05:26 +00:00
|
|
|
net6="$firewall_client_net_ipv6"
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2008-06-06 07:17:04 +00:00
|
|
|
# Allow limited broadcast traffic from my own net.
|
2008-08-15 19:14:25 +00:00
|
|
|
${fwcmd} add pass all from ${net} to 255.255.255.255
|
2008-06-06 07:17:04 +00:00
|
|
|
|
1999-09-13 15:44:20 +00:00
|
|
|
# Allow any traffic to or from my own net.
|
2008-08-15 19:14:25 +00:00
|
|
|
${fwcmd} add pass all from me to ${net}
|
|
|
|
${fwcmd} add pass all from ${net} to me
|
2009-12-02 15:05:26 +00:00
|
|
|
if [ -n "$net6" ]; then
|
2010-01-17 08:41:07 +00:00
|
|
|
${fwcmd} add pass all from me to ${net6}
|
|
|
|
${fwcmd} add pass all from ${net6} to me
|
2009-12-02 15:05:26 +00:00
|
|
|
# Allow any link-local multicast traffic
|
|
|
|
${fwcmd} add pass all from fe80::/10 to ff02::/16
|
|
|
|
${fwcmd} add pass all from ${net6} to ff02::/16
|
2010-01-09 19:16:27 +00:00
|
|
|
# Allow DHCPv6
|
2010-01-17 08:41:07 +00:00
|
|
|
${fwcmd} add pass udp from fe80::/10 to me 546
|
2009-12-02 15:05:26 +00:00
|
|
|
fi
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Allow TCP through if setup succeeded
|
|
|
|
${fwcmd} add pass tcp from any to any established
|
|
|
|
|
1999-11-04 10:13:59 +00:00
|
|
|
# Allow IP fragments to pass through
|
|
|
|
${fwcmd} add pass all from any to any frag
|
|
|
|
|
1999-09-13 15:44:20 +00:00
|
|
|
# Allow setup of incoming email
|
2006-10-28 20:08:12 +00:00
|
|
|
${fwcmd} add pass tcp from any to me 25 setup
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Allow setup of outgoing TCP connections only
|
2006-10-28 20:08:12 +00:00
|
|
|
${fwcmd} add pass tcp from me to any setup
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Disallow setup of all other TCP connections
|
|
|
|
${fwcmd} add deny tcp from any to any setup
|
|
|
|
|
|
|
|
# Allow DNS queries out in the world
|
2006-10-28 20:08:12 +00:00
|
|
|
${fwcmd} add pass udp from me to any 53 keep-state
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Allow NTP queries out in the world
|
2006-10-28 20:08:12 +00:00
|
|
|
${fwcmd} add pass udp from me to any 123 keep-state
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Everything else is denied by default, unless the
|
|
|
|
# IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
|
|
|
|
# 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
|
1999-09-13 15:44:20 +00:00
|
|
|
# on the inside at this machine for those services.
|
2008-08-15 19:20:59 +00:00
|
|
|
#
|
|
|
|
# Configuration:
|
2009-12-02 15:05:26 +00:00
|
|
|
# firewall_simple_iif: Inside IPv4 network interface.
|
|
|
|
# firewall_simple_inet: Inside IPv4 network address.
|
|
|
|
# firewall_simple_oif: Outside IPv4 network interface.
|
|
|
|
# firewall_simple_onet: Outside IPv4 network address.
|
|
|
|
# firewall_simple_iif_ipv6: Inside IPv6 network interface.
|
|
|
|
# firewall_simple_inet_ipv6: Inside IPv6 network prefix.
|
|
|
|
# firewall_simple_oif_ipv6: Outside IPv6 network interface.
|
|
|
|
# firewall_simple_onet_ipv6: Outside IPv6 network prefix.
|
1999-09-13 15:44:20 +00:00
|
|
|
############
|
2015-06-22 04:25:41 +00:00
|
|
|
BAD_ADDR_TBL=13
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2008-08-15 19:14:25 +00:00
|
|
|
# set these to your outside interface network
|
2008-08-15 19:20:59 +00:00
|
|
|
oif="$firewall_simple_oif"
|
|
|
|
onet="$firewall_simple_onet"
|
2009-12-02 15:05:26 +00:00
|
|
|
oif6="${firewall_simple_oif_ipv6:-$firewall_simple_oif}"
|
|
|
|
onet6="$firewall_simple_onet_ipv6"
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2008-08-15 19:14:25 +00:00
|
|
|
# set these to your inside interface network
|
2008-08-15 19:20:59 +00:00
|
|
|
iif="$firewall_simple_iif"
|
|
|
|
inet="$firewall_simple_inet"
|
2009-12-02 15:05:26 +00:00
|
|
|
iif6="${firewall_simple_iif_ipv6:-$firewall_simple_iif}"
|
|
|
|
inet6="$firewall_simple_inet_ipv6"
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Stop spoofing
|
2008-08-15 19:14:25 +00:00
|
|
|
${fwcmd} add deny all from ${inet} to any in via ${oif}
|
|
|
|
${fwcmd} add deny all from ${onet} to any in via ${iif}
|
2009-12-02 15:05:26 +00:00
|
|
|
if [ -n "$inet6" ]; then
|
|
|
|
${fwcmd} add deny all from ${inet6} to any in via ${oif6}
|
|
|
|
if [ -n "$onet6" ]; then
|
|
|
|
${fwcmd} add deny all from ${onet6} to any in \
|
|
|
|
via ${iif6}
|
|
|
|
fi
|
|
|
|
fi
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2015-06-29 07:43:09 +00:00
|
|
|
# Define stuff we should never send out or receive in.
|
1999-09-13 15:44:20 +00:00
|
|
|
# Stop RFC1918 nets on the outside interface
|
2015-06-22 04:25:41 +00:00
|
|
|
${fwcmd} table ${BAD_ADDR_TBL} flush
|
|
|
|
${fwcmd} table ${BAD_ADDR_TBL} add 10.0.0.0/8
|
|
|
|
${fwcmd} table ${BAD_ADDR_TBL} add 172.16.0.0/12
|
|
|
|
${fwcmd} table ${BAD_ADDR_TBL} add 192.168.0.0/16
|
2000-01-28 11:30:28 +00:00
|
|
|
|
2015-06-29 07:43:09 +00:00
|
|
|
# And stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1,
|
2000-07-30 19:28:05 +00:00
|
|
|
# DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E)
|
|
|
|
# on the outside interface
|
2015-06-22 04:25:41 +00:00
|
|
|
${fwcmd} table ${BAD_ADDR_TBL} add 0.0.0.0/8
|
|
|
|
${fwcmd} table ${BAD_ADDR_TBL} add 169.254.0.0/16
|
|
|
|
${fwcmd} table ${BAD_ADDR_TBL} add 192.0.2.0/24
|
|
|
|
${fwcmd} table ${BAD_ADDR_TBL} add 224.0.0.0/4
|
|
|
|
${fwcmd} table ${BAD_ADDR_TBL} add 240.0.0.0/4
|
|
|
|
|
|
|
|
${fwcmd} add deny all from any to "table($BAD_ADDR_TBL)" via ${oif}
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2000-08-04 14:02:11 +00:00
|
|
|
# Network Address Translation. This rule is placed here deliberately
|
|
|
|
# so that it does not interfere with the surrounding address-checking
|
|
|
|
# rules. If for example one of your internal LAN machines had its IP
|
|
|
|
# address set to 192.0.2.1 then an incoming packet for it after being
|
|
|
|
# translated by natd(8) would match the `deny' rule above. Similarly
|
|
|
|
# an outgoing packet originated from it before being translated would
|
|
|
|
# match the `deny' rule below.
|
|
|
|
case ${natd_enable} in
|
|
|
|
[Yy][Ee][Ss])
|
|
|
|
if [ -n "${natd_interface}" ]; then
|
2009-12-02 15:05:26 +00:00
|
|
|
${fwcmd} add divert natd ip4 from any to any via ${natd_interface}
|
2000-08-04 14:02:11 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2015-06-22 04:25:41 +00:00
|
|
|
${fwcmd} add deny all from "table($BAD_ADDR_TBL)" to any via ${oif}
|
2009-12-02 15:05:26 +00:00
|
|
|
if [ -n "$inet6" ]; then
|
|
|
|
# Stop unique local unicast address on the outside interface
|
|
|
|
${fwcmd} add deny all from fc00::/7 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to fc00::/7 via ${oif6}
|
|
|
|
|
|
|
|
# Stop site-local on the outside interface
|
|
|
|
${fwcmd} add deny all from fec0::/10 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to fec0::/10 via ${oif6}
|
|
|
|
|
|
|
|
# Disallow "internal" addresses to appear on the wire.
|
|
|
|
${fwcmd} add deny all from ::ffff:0.0.0.0/96 to any \
|
|
|
|
via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to ::ffff:0.0.0.0/96 \
|
|
|
|
via ${oif6}
|
|
|
|
|
|
|
|
# Disallow packets to malicious IPv4 compatible prefix.
|
|
|
|
${fwcmd} add deny all from ::224.0.0.0/100 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to ::224.0.0.0/100 via ${oif6}
|
|
|
|
${fwcmd} add deny all from ::127.0.0.0/104 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to ::127.0.0.0/104 via ${oif6}
|
|
|
|
${fwcmd} add deny all from ::0.0.0.0/104 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to ::0.0.0.0/104 via ${oif6}
|
|
|
|
${fwcmd} add deny all from ::255.0.0.0/104 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to ::255.0.0.0/104 via ${oif6}
|
|
|
|
|
|
|
|
${fwcmd} add deny all from ::0.0.0.0/96 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to ::0.0.0.0/96 via ${oif6}
|
|
|
|
|
|
|
|
# Disallow packets to malicious 6to4 prefix.
|
|
|
|
${fwcmd} add deny all from 2002:e000::/20 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to 2002:e000::/20 via ${oif6}
|
|
|
|
${fwcmd} add deny all from 2002:7f00::/24 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to 2002:7f00::/24 via ${oif6}
|
|
|
|
${fwcmd} add deny all from 2002:0000::/24 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to 2002:0000::/24 via ${oif6}
|
|
|
|
${fwcmd} add deny all from 2002:ff00::/24 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to 2002:ff00::/24 via ${oif6}
|
|
|
|
|
|
|
|
${fwcmd} add deny all from 2002:0a00::/24 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to 2002:0a00::/24 via ${oif6}
|
|
|
|
${fwcmd} add deny all from 2002:ac10::/28 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to 2002:ac10::/28 via ${oif6}
|
|
|
|
${fwcmd} add deny all from 2002:c0a8::/32 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to 2002:c0a8::/32 via ${oif6}
|
|
|
|
|
|
|
|
${fwcmd} add deny all from ff05::/16 to any via ${oif6}
|
|
|
|
${fwcmd} add deny all from any to ff05::/16 via ${oif6}
|
|
|
|
fi
|
|
|
|
|
1999-09-13 15:44:20 +00:00
|
|
|
# Allow TCP through if setup succeeded
|
|
|
|
${fwcmd} add pass tcp from any to any established
|
|
|
|
|
1999-11-04 10:13:59 +00:00
|
|
|
# Allow IP fragments to pass through
|
|
|
|
${fwcmd} add pass all from any to any frag
|
|
|
|
|
1999-09-13 15:44:20 +00:00
|
|
|
# Allow setup of incoming email
|
2008-08-15 18:58:15 +00:00
|
|
|
${fwcmd} add pass tcp from any to me 25 setup
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Allow access to our DNS
|
2008-08-15 18:58:15 +00:00
|
|
|
${fwcmd} add pass tcp from any to me 53 setup
|
|
|
|
${fwcmd} add pass udp from any to me 53
|
|
|
|
${fwcmd} add pass udp from me 53 to any
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Allow access to our WWW
|
2008-08-15 18:58:15 +00:00
|
|
|
${fwcmd} add pass tcp from any to me 80 setup
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Reject&Log all setup of incoming connections from the outside
|
2009-12-02 15:05:26 +00:00
|
|
|
${fwcmd} add deny log ip4 from any to any in via ${oif} setup proto tcp
|
|
|
|
if [ -n "$inet6" ]; then
|
|
|
|
${fwcmd} add deny log ip6 from any to any in via ${oif6} \
|
|
|
|
setup proto tcp
|
|
|
|
fi
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Allow setup of any other TCP connection
|
|
|
|
${fwcmd} add pass tcp from any to any setup
|
|
|
|
|
|
|
|
# Allow DNS queries out in the world
|
2008-08-15 18:58:15 +00:00
|
|
|
${fwcmd} add pass udp from me to any 53 keep-state
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Allow NTP queries out in the world
|
2008-08-15 18:58:15 +00:00
|
|
|
${fwcmd} add pass udp from me to any 123 keep-state
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Everything else is denied by default, unless the
|
|
|
|
# IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
|
|
|
|
# config file.
|
|
|
|
;;
|
|
|
|
|
2006-10-28 20:08:12 +00:00
|
|
|
[Ww][Oo][Rr][Kk][Ss][Tt][Aa][Tt][Ii][Oo][Nn])
|
|
|
|
# Configuration:
|
2014-10-17 00:31:51 +00:00
|
|
|
# firewall_myservices: List of ports/protocols on which this
|
|
|
|
# host offers services.
|
2010-04-08 15:19:57 +00:00
|
|
|
# firewall_allowservices: List of IPv4 and/or IPv6 addresses
|
2010-04-11 15:31:09 +00:00
|
|
|
# that have access to
|
2006-10-28 20:08:12 +00:00
|
|
|
# $firewall_myservices.
|
2010-04-08 15:19:57 +00:00
|
|
|
# firewall_trusted: List of IPv4 and/or IPv6 addresses
|
2010-04-11 15:31:09 +00:00
|
|
|
# that have full access to this host.
|
|
|
|
# Be very careful when setting this.
|
2010-04-08 15:19:57 +00:00
|
|
|
# This option can seriously degrade
|
|
|
|
# the level of protection provided by
|
|
|
|
# the firewall.
|
2006-10-28 20:08:12 +00:00
|
|
|
# firewall_logdeny: Boolean (YES/NO) specifying if the
|
|
|
|
# default denied packets should be
|
|
|
|
# logged (in /var/log/security).
|
|
|
|
# firewall_nologports: List of TCP/UDP ports for which
|
2012-01-07 16:10:32 +00:00
|
|
|
# denied incoming packets are not
|
2006-10-28 20:08:12 +00:00
|
|
|
# logged.
|
2009-12-02 15:05:26 +00:00
|
|
|
|
2006-10-28 20:08:12 +00:00
|
|
|
# Allow packets for which a state has been built.
|
|
|
|
${fwcmd} add check-state
|
|
|
|
|
|
|
|
# For services permitted below.
|
|
|
|
${fwcmd} add pass tcp from me to any established
|
|
|
|
|
|
|
|
# Allow any connection out, adding state for each.
|
|
|
|
${fwcmd} add pass tcp from me to any setup keep-state
|
|
|
|
${fwcmd} add pass udp from me to any keep-state
|
|
|
|
${fwcmd} add pass icmp from me to any keep-state
|
2009-12-02 15:05:26 +00:00
|
|
|
if [ $ipv6_available -eq 0 ]; then
|
2010-01-17 08:41:07 +00:00
|
|
|
${fwcmd} add pass ipv6-icmp from me to any keep-state
|
2009-12-02 15:05:26 +00:00
|
|
|
fi
|
2006-10-28 20:08:12 +00:00
|
|
|
|
|
|
|
# Allow DHCP.
|
|
|
|
${fwcmd} add pass udp from 0.0.0.0 68 to 255.255.255.255 67 out
|
|
|
|
${fwcmd} add pass udp from any 67 to me 68 in
|
|
|
|
${fwcmd} add pass udp from any 67 to 255.255.255.255 68 in
|
2009-12-02 15:05:26 +00:00
|
|
|
if [ $ipv6_available -eq 0 ]; then
|
2010-01-17 08:41:07 +00:00
|
|
|
${fwcmd} add pass udp from fe80::/10 to me 546 in
|
2009-12-02 15:05:26 +00:00
|
|
|
fi
|
2010-05-14 04:53:57 +00:00
|
|
|
# Some servers will ping the IP while trying to decide if it's
|
2006-10-28 20:08:12 +00:00
|
|
|
# still in use.
|
|
|
|
${fwcmd} add pass icmp from any to any icmptype 8
|
2009-12-02 15:05:26 +00:00
|
|
|
if [ $ipv6_available -eq 0 ]; then
|
|
|
|
${fwcmd} add pass ipv6-icmp from any to any icmp6type 128,129
|
|
|
|
fi
|
2006-10-28 20:08:12 +00:00
|
|
|
|
|
|
|
# Allow "mandatory" ICMP in.
|
|
|
|
${fwcmd} add pass icmp from any to any icmptype 3,4,11
|
2010-01-07 17:46:25 +00:00
|
|
|
if [ $ipv6_available -eq 0 ]; then
|
|
|
|
${fwcmd} add pass ipv6-icmp from any to any icmp6type 3
|
|
|
|
fi
|
|
|
|
|
2006-10-28 20:08:12 +00:00
|
|
|
# Add permits for this workstations published services below
|
|
|
|
# Only IPs and nets in firewall_allowservices is allowed in.
|
2010-05-14 04:53:57 +00:00
|
|
|
# If you really wish to let anyone use services on your
|
2006-10-28 20:08:12 +00:00
|
|
|
# workstation, then set "firewall_allowservices='any'" in /etc/rc.conf
|
|
|
|
#
|
|
|
|
# Note: We don't use keep-state as that would allow DoS of
|
2010-05-14 04:53:57 +00:00
|
|
|
# our statetable.
|
2006-10-28 20:08:12 +00:00
|
|
|
# You can add 'keep-state' to the lines for slightly
|
|
|
|
# better performance if you fell that DoS of your
|
|
|
|
# workstation won't be a problem.
|
|
|
|
#
|
|
|
|
for i in ${firewall_allowservices} ; do
|
|
|
|
for j in ${firewall_myservices} ; do
|
2014-10-17 00:31:51 +00:00
|
|
|
case $j in
|
|
|
|
[0-9A-Za-z]*/[Pp][Rr][Oo][Tt][Oo])
|
|
|
|
${fwcmd} add pass ${j%/[Pp][Rr][Oo][Tt][Oo]} from $i to me
|
|
|
|
;;
|
|
|
|
[0-9A-Za-z]*/[Tt][Cc][Pp])
|
|
|
|
${fwcmd} add pass tcp from $i to me ${j%/[Tt][Cc][Pp]}
|
|
|
|
;;
|
|
|
|
[0-9A-Za-z]*/[Uu][Dd][Pp])
|
|
|
|
${fwcmd} add pass udp from $i to me ${j%/[Uu][Dd][Pp]}
|
|
|
|
;;
|
|
|
|
*[0-9A-Za-z])
|
2014-10-20 04:14:35 +00:00
|
|
|
echo "Consider using ${j}/tcp in firewall_myservices." \
|
|
|
|
> /dev/stderr
|
2014-10-17 00:31:51 +00:00
|
|
|
${fwcmd} add pass tcp from $i to me $j
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid port in firewall_myservices: $j" > /dev/stderr
|
|
|
|
;;
|
|
|
|
esac
|
2006-10-28 20:08:12 +00:00
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
# Allow all connections from trusted IPs.
|
|
|
|
# Playing with the content of firewall_trusted could seriously
|
|
|
|
# degrade the level of protection provided by the firewall.
|
|
|
|
for i in ${firewall_trusted} ; do
|
|
|
|
${fwcmd} add pass ip from $i to me
|
|
|
|
done
|
2009-12-02 15:05:26 +00:00
|
|
|
|
2006-10-28 20:08:12 +00:00
|
|
|
${fwcmd} add 65000 count ip from any to any
|
|
|
|
|
|
|
|
# Drop packets to ports where we don't want logging
|
|
|
|
for i in ${firewall_nologports} ; do
|
|
|
|
${fwcmd} add deny { tcp or udp } from any to any $i in
|
|
|
|
done
|
|
|
|
|
2012-01-07 16:10:32 +00:00
|
|
|
# Broadcasts and multicasts
|
2006-10-28 20:08:12 +00:00
|
|
|
${fwcmd} add deny ip from any to 255.255.255.255
|
|
|
|
${fwcmd} add deny ip from any to 224.0.0.0/24 in # XXX
|
|
|
|
|
|
|
|
# Noise from routers
|
|
|
|
${fwcmd} add deny udp from any to any 520 in
|
|
|
|
|
|
|
|
# Noise from webbrowsing.
|
2012-01-07 16:10:32 +00:00
|
|
|
# The stateful filter is a bit aggressive, and will cause some
|
2006-10-28 20:08:12 +00:00
|
|
|
# connection teardowns to be logged.
|
|
|
|
${fwcmd} add deny tcp from any 80,443 to any 1024-65535 in
|
|
|
|
|
|
|
|
# Deny and (if wanted) log the rest unconditionally.
|
|
|
|
log=""
|
|
|
|
if [ ${firewall_logdeny:-x} = "YES" -o ${firewall_logdeny:-x} = "yes" ] ; then
|
|
|
|
log="log logamount 500" # The default of 100 is too low.
|
|
|
|
sysctl net.inet.ip.fw.verbose=1 >/dev/null
|
|
|
|
fi
|
|
|
|
${fwcmd} add deny $log ip from any to any
|
|
|
|
;;
|
|
|
|
|
2002-02-21 13:14:19 +00:00
|
|
|
[Cc][Ll][Oo][Ss][Ee][Dd])
|
2006-10-28 20:08:12 +00:00
|
|
|
${fwcmd} add 65000 deny ip from any to any
|
2002-02-21 13:14:19 +00:00
|
|
|
;;
|
1999-09-13 15:44:20 +00:00
|
|
|
[Uu][Nn][Kk][Nn][Oo][Ww][Nn])
|
|
|
|
;;
|
|
|
|
*)
|
2000-04-27 00:48:59 +00:00
|
|
|
if [ -r "${firewall_type}" ]; then
|
2000-02-06 19:25:00 +00:00
|
|
|
${fwcmd} ${firewall_flags} ${firewall_type}
|
1999-09-13 15:44:20 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|