1996-04-03 19:13:59 +02:00
|
|
|
############
|
|
|
|
# Setup system for firewall service.
|
1999-08-28 01:37:10 +02:00
|
|
|
# $FreeBSD$
|
1998-02-10 02:45:57 +01:00
|
|
|
|
1999-02-10 19:08:16 +01:00
|
|
|
# Suck in the configuration variables.
|
|
|
|
if [ -f /etc/defaults/rc.conf ]; then
|
|
|
|
. /etc/defaults/rc.conf
|
|
|
|
elif [ -f /etc/rc.conf ]; then
|
1998-02-10 02:45:57 +01:00
|
|
|
. /etc/rc.conf
|
|
|
|
fi
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
############
|
1997-09-11 12:59:02 +02: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 19:13:59 +02:00
|
|
|
#
|
1997-09-11 12:59:02 +02:00
|
|
|
# For ``client'' and ``simple'' the entries below should be customized
|
|
|
|
# appropriately.
|
1996-08-14 16:42:05 +02:00
|
|
|
|
1996-04-03 19:13:59 +02:00
|
|
|
############
|
|
|
|
#
|
|
|
|
# If you don't know enough about packet filtering, we suggest that you
|
|
|
|
# take time to read this book:
|
|
|
|
#
|
1996-04-12 11:16:42 +02:00
|
|
|
# Building Internet Firewalls
|
|
|
|
# Brent Chapman and Elizabeth Zwicky
|
|
|
|
#
|
|
|
|
# O'Reilly & Associates, Inc
|
|
|
|
# ISBN 1-56592-124-0
|
1997-05-05 09:08:31 +02:00
|
|
|
# http://www.ora.com/
|
1996-04-12 11:16:42 +02:00
|
|
|
#
|
|
|
|
# For a more advanced treatment of Internet Security read:
|
|
|
|
#
|
1996-04-03 19:13:59 +02:00
|
|
|
# Firewalls & Internet Security
|
|
|
|
# Repelling the wily hacker
|
|
|
|
# William R. Cheswick, Steven M. Bellowin
|
|
|
|
#
|
|
|
|
# Addison-Wesley
|
|
|
|
# ISBN 0-201-6337-4
|
1997-05-05 09:08:31 +02:00
|
|
|
# http://www.awl.com/
|
1996-04-03 19:13:59 +02:00
|
|
|
#
|
|
|
|
|
1999-08-25 18:01:45 +02:00
|
|
|
if [ -n "$1" ]; then
|
1997-09-11 12:59:02 +02:00
|
|
|
firewall_type=$1
|
|
|
|
fi
|
|
|
|
|
|
|
|
############
|
|
|
|
# Set quiet mode if requested
|
1999-08-25 18:01:45 +02:00
|
|
|
if [ "${firewall_quiet}" = "YES" ]; then
|
1997-09-11 12:59:02 +02:00
|
|
|
fwcmd="/sbin/ipfw -q"
|
|
|
|
else
|
|
|
|
fwcmd="/sbin/ipfw"
|
|
|
|
fi
|
|
|
|
|
1996-06-22 02:54:36 +02:00
|
|
|
############
|
|
|
|
# Flush out the list before we begin.
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} -f flush
|
1996-06-22 02:54:36 +02:00
|
|
|
|
1998-04-18 12:27:19 +02:00
|
|
|
############
|
|
|
|
# These rules are required for using natd. All packets are passed to
|
|
|
|
# natd before they encounter your remaining rules. The firewall rules
|
|
|
|
# will then be run again on each packet after translation by natd,
|
|
|
|
# minus any divert rules (see natd(8)).
|
1999-08-25 18:01:45 +02:00
|
|
|
if [ "${natd_enable}" = "YES" -a "${natd_interface}" != "X" ]; then
|
|
|
|
${fwcmd} add divert natd all from any to any via ${natd_interface}
|
1998-04-18 12:27:19 +02:00
|
|
|
fi
|
|
|
|
|
1996-04-03 19:13:59 +02: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
|
1996-08-14 16:42:05 +02:00
|
|
|
# they you will want to change the default policy to open. You can also
|
|
|
|
# do this as your only action by setting the firewall_type to ``open''.
|
1996-04-03 19:13:59 +02:00
|
|
|
|
1999-08-25 18:01:45 +02:00
|
|
|
# ${fwcmd} add 65000 pass all from any to any
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
############
|
1997-10-21 02:54:08 +02:00
|
|
|
# Only in rare cases do you want to change these rules
|
1999-08-25 18:01:45 +02: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
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
|
1996-08-14 16:42:05 +02:00
|
|
|
# Prototype setups.
|
1997-10-21 02:54:08 +02:00
|
|
|
if [ "${firewall_type}" = "open" -o "${firewall_type}" = "OPEN" ]; then
|
1997-09-11 12:59:02 +02:00
|
|
|
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add 65000 pass all from any to any
|
1996-08-14 16:42:05 +02:00
|
|
|
|
1997-09-11 12:59:02 +02:00
|
|
|
elif [ "${firewall_type}" = "client" ]; then
|
1996-08-14 16:42:05 +02:00
|
|
|
|
|
|
|
############
|
|
|
|
# This is a prototype setup that will protect your system somewhat against
|
|
|
|
# people from outside your own network.
|
|
|
|
############
|
|
|
|
|
1996-04-03 19:13:59 +02:00
|
|
|
# set these to your network and netmask and ip
|
|
|
|
net="192.168.4.0"
|
|
|
|
mask="255.255.255.0"
|
|
|
|
ip="192.168.4.17"
|
|
|
|
|
|
|
|
# Allow any traffic to or from my own net.
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass all from ${ip} to ${net}:${mask}
|
|
|
|
${fwcmd} add pass all from ${net}:${mask} to ${ip}
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Allow TCP through if setup succeeded
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass tcp from any to any established
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Allow setup of incoming email
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass tcp from any to ${ip} 25 setup
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Allow setup of outgoing TCP connections only
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass tcp from ${ip} to any setup
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Disallow setup of all other TCP connections
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add deny tcp from any to any setup
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Allow DNS queries out in the world
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass udp from any 53 to ${ip}
|
|
|
|
${fwcmd} add pass udp from ${ip} to any 53
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Allow NTP queries out in the world
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass udp from any 123 to ${ip}
|
|
|
|
${fwcmd} add pass udp from ${ip} to any 123
|
1996-04-03 19:13:59 +02:00
|
|
|
|
1997-05-05 09:08:31 +02:00
|
|
|
# Everything else is denied as default.
|
1996-04-03 19:13:59 +02:00
|
|
|
|
1997-09-11 12:59:02 +02:00
|
|
|
elif [ "${firewall_type}" = "simple" ]; then
|
1996-08-14 16:42:05 +02:00
|
|
|
|
|
|
|
############
|
|
|
|
# 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.
|
|
|
|
############
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# set these to your outside interface network and netmask and ip
|
|
|
|
oif="ed0"
|
|
|
|
onet="192.168.4.0"
|
|
|
|
omask="255.255.255.0"
|
|
|
|
oip="192.168.4.17"
|
|
|
|
|
|
|
|
# set these to your inside interface network and netmask and ip
|
|
|
|
iif="ed1"
|
|
|
|
inet="192.168.3.0"
|
|
|
|
imask="255.255.255.0"
|
|
|
|
iip="192.168.3.17"
|
|
|
|
|
|
|
|
# Stop spoofing
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add deny all from ${inet}:${imask} to any in via ${oif}
|
|
|
|
${fwcmd} add deny all from ${onet}:${omask} to any in via ${iif}
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Stop RFC1918 nets on the outside interface
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add deny all from 192.168.0.0:255.255.0.0 to any via ${oif}
|
|
|
|
${fwcmd} add deny all from any to 192.168.0.0:255.255.0.0 via ${oif}
|
|
|
|
${fwcmd} add deny all from 172.16.0.0:255.240.0.0 to any via ${oif}
|
|
|
|
${fwcmd} add deny all from any to 172.16.0.0:255.240.0.0 via ${oif}
|
|
|
|
${fwcmd} add deny all from 10.0.0.0:255.0.0.0 to any via ${oif}
|
|
|
|
${fwcmd} add deny all from any to 10.0.0.0:255.0.0.0 via ${oif}
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Allow TCP through if setup succeeded
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass tcp from any to any established
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Allow setup of incoming email
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass tcp from any to ${oip} 25 setup
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Allow access to our DNS
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass tcp from any to ${oip} 53 setup
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Allow access to our WWW
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass tcp from any to ${oip} 80 setup
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Reject&Log all setup of incoming connections from the outside
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add deny log tcp from any to any in via ${oif} setup
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Allow setup of any other TCP connection
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass tcp from any to any setup
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Allow DNS queries out in the world
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass udp from any 53 to ${oip}
|
|
|
|
${fwcmd} add pass udp from ${oip} to any 53
|
1996-04-03 19:13:59 +02:00
|
|
|
|
|
|
|
# Allow NTP queries out in the world
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} add pass udp from any 123 to ${oip}
|
|
|
|
${fwcmd} add pass udp from ${oip} to any 123
|
1996-04-03 19:13:59 +02:00
|
|
|
|
1997-05-05 09:08:31 +02:00
|
|
|
# Everything else is denied as default.
|
|
|
|
|
1997-10-21 02:54:08 +02:00
|
|
|
elif [ "${firewall_type}" != "UNKNOWN" -a -r "${firewall_type}" ]; then
|
1999-08-25 18:01:45 +02:00
|
|
|
${fwcmd} ${firewall_type}
|
1997-05-05 09:08:31 +02:00
|
|
|
fi
|