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
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# Setup system for firewall service.
|
|
|
|
#
|
1998-02-10 01:45:57 +00:00
|
|
|
|
1999-02-10 18:08:16 +00:00
|
|
|
# Suck in the configuration variables.
|
1999-09-13 15:44:20 +00:00
|
|
|
if [ -r /etc/defaults/rc.conf ]; then
|
1999-02-10 18:08:16 +00:00
|
|
|
. /etc/defaults/rc.conf
|
2000-04-27 08:43:49 +00:00
|
|
|
source_rc_confs
|
1999-09-13 15:44:20 +00:00
|
|
|
elif [ -r /etc/rc.conf ]; then
|
1998-02-10 01:45:57 +00:00
|
|
|
. /etc/rc.conf
|
|
|
|
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:
|
|
|
|
# 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)
|
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:
|
|
|
|
#
|
1996-04-12 09:16:42 +00:00
|
|
|
# Building Internet Firewalls
|
|
|
|
# Brent Chapman and Elizabeth Zwicky
|
|
|
|
#
|
|
|
|
# O'Reilly & Associates, Inc
|
|
|
|
# ISBN 1-56592-124-0
|
1997-05-05 07:08:31 +00:00
|
|
|
# http://www.ora.com/
|
1996-04-12 09:16:42 +00:00
|
|
|
#
|
|
|
|
# For a more advanced treatment of Internet Security read:
|
|
|
|
#
|
1996-04-03 17:13:59 +00:00
|
|
|
# Firewalls & Internet Security
|
|
|
|
# Repelling the wily hacker
|
|
|
|
# William R. Cheswick, Steven M. Bellowin
|
|
|
|
#
|
|
|
|
# Addison-Wesley
|
|
|
|
# ISBN 0-201-6337-4
|
1997-05-05 07:08:31 +00:00
|
|
|
# http://www.awl.com/
|
1996-04-03 17:13:59 +00:00
|
|
|
#
|
|
|
|
|
1999-09-13 15:44:20 +00:00
|
|
|
if [ -n "${1}" ]; then
|
|
|
|
firewall_type="${1}"
|
1997-09-11 10:59:02 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
############
|
|
|
|
# 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
|
|
|
|
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.
|
|
|
|
#
|
|
|
|
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
|
|
|
|
${fwcmd} add 50 divert natd all from any to any via ${natd_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
|
|
|
|
|
|
|
############
|
1997-10-21 00:54:08 +00:00
|
|
|
# Only in rare cases do you want to change these rules
|
1999-09-13 15:44:20 +00:00
|
|
|
#
|
1999-08-25 16:01:45 +00:00
|
|
|
${fwcmd} add 100 pass all from any to any via lo0
|
|
|
|
${fwcmd} add 200 deny all from any to 127.0.0.0/8
|
1999-10-24 00:26:49 +00:00
|
|
|
# If you're using 'options BRIDGE', uncomment the following line to pass ARP
|
|
|
|
#${fwcmd} add 300 pass udp from 0.0.0.0 2054 to 0.0.0.0
|
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.
|
|
|
|
############
|
|
|
|
|
|
|
|
# set these to your network and netmask and ip
|
2000-01-28 11:30:28 +00:00
|
|
|
net="192.0.2.0"
|
1999-09-13 15:44:20 +00:00
|
|
|
mask="255.255.255.0"
|
2000-01-28 11:30:28 +00:00
|
|
|
ip="192.0.2.1"
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Allow any traffic to or from my own net.
|
|
|
|
${fwcmd} add pass all from ${ip} to ${net}:${mask}
|
|
|
|
${fwcmd} add pass all from ${net}:${mask} to ${ip}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
${fwcmd} add pass tcp from any to ${ip} 25 setup
|
|
|
|
|
|
|
|
# Allow setup of outgoing TCP connections only
|
|
|
|
${fwcmd} add pass tcp from ${ip} to any setup
|
|
|
|
|
|
|
|
# Disallow setup of all other TCP connections
|
|
|
|
${fwcmd} add deny tcp from any to any setup
|
|
|
|
|
|
|
|
# Allow DNS queries out in the world
|
2001-02-20 19:54:31 +00:00
|
|
|
${fwcmd} add pass udp from ${ip} to any 53 keep-state
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Allow NTP queries out in the world
|
2001-02-20 19:54:31 +00:00
|
|
|
${fwcmd} add pass udp from ${ip} 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
|
|
|
|
# machine as a named server and ntp server, and point all the machines
|
|
|
|
# on the inside at this machine for those services.
|
|
|
|
############
|
|
|
|
|
|
|
|
# set these to your outside interface network and netmask and ip
|
|
|
|
oif="ed0"
|
2000-01-28 11:30:28 +00:00
|
|
|
onet="192.0.2.0"
|
|
|
|
omask="255.255.255.240"
|
|
|
|
oip="192.0.2.1"
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# set these to your inside interface network and netmask and ip
|
|
|
|
iif="ed1"
|
2000-01-28 11:30:28 +00:00
|
|
|
inet="192.0.2.16"
|
|
|
|
imask="255.255.255.240"
|
|
|
|
iip="192.0.2.17"
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Stop spoofing
|
|
|
|
${fwcmd} add deny all from ${inet}:${imask} to any in via ${oif}
|
|
|
|
${fwcmd} add deny all from ${onet}:${omask} to any in via ${iif}
|
|
|
|
|
|
|
|
# Stop RFC1918 nets on the outside interface
|
2000-01-28 11:30:28 +00:00
|
|
|
${fwcmd} add deny all from any to 10.0.0.0/8 via ${oif}
|
|
|
|
${fwcmd} add deny all from any to 172.16.0.0/12 via ${oif}
|
|
|
|
${fwcmd} add deny all from any to 192.168.0.0/16 via ${oif}
|
|
|
|
|
2000-07-30 19:28:05 +00:00
|
|
|
# Stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1,
|
|
|
|
# DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E)
|
|
|
|
# on the outside interface
|
2000-01-28 11:30:28 +00:00
|
|
|
${fwcmd} add deny all from any to 0.0.0.0/8 via ${oif}
|
|
|
|
${fwcmd} add deny all from any to 169.254.0.0/16 via ${oif}
|
|
|
|
${fwcmd} add deny all from any to 192.0.2.0/24 via ${oif}
|
|
|
|
${fwcmd} add deny all from any to 224.0.0.0/4 via ${oif}
|
|
|
|
${fwcmd} add deny all from any to 240.0.0.0/4 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
|
|
|
|
${fwcmd} add divert natd all from any to any via ${natd_interface}
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Stop RFC1918 nets on the outside interface
|
|
|
|
${fwcmd} add deny all from 10.0.0.0/8 to any via ${oif}
|
|
|
|
${fwcmd} add deny all from 172.16.0.0/12 to any via ${oif}
|
|
|
|
${fwcmd} add deny all from 192.168.0.0/16 to any via ${oif}
|
|
|
|
|
|
|
|
# Stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1,
|
|
|
|
# DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E)
|
|
|
|
# on the outside interface
|
|
|
|
${fwcmd} add deny all from 0.0.0.0/8 to any via ${oif}
|
|
|
|
${fwcmd} add deny all from 169.254.0.0/16 to any via ${oif}
|
|
|
|
${fwcmd} add deny all from 192.0.2.0/24 to any via ${oif}
|
|
|
|
${fwcmd} add deny all from 224.0.0.0/4 to any via ${oif}
|
|
|
|
${fwcmd} add deny all from 240.0.0.0/4 to any via ${oif}
|
|
|
|
|
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
|
|
|
|
${fwcmd} add pass tcp from any to ${oip} 25 setup
|
|
|
|
|
|
|
|
# Allow access to our DNS
|
|
|
|
${fwcmd} add pass tcp from any to ${oip} 53 setup
|
1999-10-20 08:15:13 +00:00
|
|
|
${fwcmd} add pass udp from any to ${oip} 53
|
|
|
|
${fwcmd} add pass udp from ${oip} 53 to any
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Allow access to our WWW
|
|
|
|
${fwcmd} add pass tcp from any to ${oip} 80 setup
|
|
|
|
|
|
|
|
# Reject&Log all setup of incoming connections from the outside
|
|
|
|
${fwcmd} add deny log tcp from any to any in via ${oif} setup
|
|
|
|
|
|
|
|
# Allow setup of any other TCP connection
|
|
|
|
${fwcmd} add pass tcp from any to any setup
|
|
|
|
|
|
|
|
# Allow DNS queries out in the world
|
2001-02-20 19:54:31 +00:00
|
|
|
${fwcmd} add pass udp from ${oip} to any 53 keep-state
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Allow NTP queries out in the world
|
2001-02-20 19:54:31 +00:00
|
|
|
${fwcmd} add pass udp from ${oip} 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.
|
|
|
|
;;
|
|
|
|
|
|
|
|
[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
|