Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Jan 2001 10:55:30 -0800 (PST)
From:      Benjamin Ossei <ben@cahostnet.net>
To:        questions@freebsd.org
Subject:   firewall config
Message-ID:  <20010129185530.BE45B3ED4@sitemail.everyone.net>

next in thread | raw e-mail | index | archive | help
I was wondering if someone could look over my firewall conguration to tell me if it will work for my scenerio.  I want to be able to provide www,dns,ftp,telnet,ssh to servers on the inside network using natd.  I will have one public ip address and will be using 192.168.1.0/24 for the internal network.  I am allowing ALL traffic outbound.  The config as this.

The part that really confuses me is the part on spoofing.  I will like to stop spoofing but I don't know if that rule will work. 

Thanks...

#########################################################
# Suck in the configuration variables.
if [ -r /etc/defaults/rc.conf ]; then
	. /etc/defaults/rc.conf
	source_rc_confs
elif [ -r /etc/rc.conf ]; then
	. /etc/rc.conf
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:
#
#	Building Internet Firewalls
#	Brent Chapman and Elizabeth Zwicky
#
#	O'Reilly & Associates, Inc
#	ISBN 1-56592-124-0
#	http://www.ora.com/
#
# For a more advanced treatment of Internet Security read:
#
#	Firewalls & Internet Security
#	Repelling the wily hacker
#	William R. Cheswick, Steven M. Bellowin
#
#	Addison-Wesley
#	ISBN 0-201-6337-4
#	http://www.awl.com/
#

if [ -n "${1}" ]; then
	firewall_type="${1}"
fi

############
# Set quiet mode if requested
#
case ${firewall_quiet} in
[Yy][Ee][Ss])
	fwcmd="/sbin/ipfw -q"
	;;
*)
	fwcmd="/sbin/ipfw"
	;;
esac

############
# Flush out the list before we begin.
#
${fwcmd} -f flush

############
# 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.
#
# 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
[Oo][Pp][Ee][Nn]|[Cc][Ll][Ii][Ee][Nn][Tt])
	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
esac

############
# 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 firewall_type to ``open''.
#
# ${fwcmd} add 65000 pass all from any to any

############
# 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
# 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


# Prototype setups.
#
case ${firewall_type} in
[Oo][Pp][Ee][Nn])
	${fwcmd} add 65000 pass all from any to any
	;;


[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.  It also allows outside
	# services such as mail, dns, ftp, and ssh to come inbound.  It allows all
	# traffic outbound.
	############

	# set these to your outside interface network and netmask and ip
	oif="xl0"
	onet="24.180.132.0"
	omask="255.255.255.0"
	oip="24.180.132.54"

	# set these to your inside interface network and netmask and ip
	iif="fxp0"
	inet="192.168.1.0"
	imask="255.255.255.0"
	iip="192.168.1.1"

	# 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
	${fwcmd} add deny all from any to 10.0.0.0/8 in via ${oif}
	${fwcmd} add deny all from any to 172.16.0.0/12 in via ${oif}
	${fwcmd} add deny all from any to 192.168.0.0/16 in 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 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}

	# 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 in via ${oif}
	${fwcmd} add deny all from 172.16.0.0/12 to any in via ${oif}
	${fwcmd} add deny all from 192.168.0.0/16 to any in 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 in via ${oif}
	${fwcmd} add deny all from 169.254.0.0/16 to any in via ${oif}
	${fwcmd} add deny all from 192.0.2.0/24 to any in via ${oif}
	${fwcmd} add deny all from 224.0.0.0/4 to any in via ${oif}
	${fwcmd} add deny all from 240.0.0.0/4 to any in via ${oif}

	# Allow TCP through if setup succeeded
	${fwcmd} add pass tcp from any to any established

	# Allow IP fragments to pass through
	${fwcmd} add pass all from any to any frag

	# Allow ALL outgoing traffic
	${fwcmd} add pass all from 192.168.1.0/24 to ${oip} out setup

	# Allow setup of incoming/Outgoing email
	${fwcmd} add pass tcp from any to ${oip} 25 setup
	${fwcmd} add pass tcp from ${oip} to any 25 out setup 

	# Allow access to our DNS
	${fwcmd} add pass tcp from any to ${oip} 53 setup
	${fwcmd} add pass udp from any to ${oip} 53
	${fwcmd} add pass udp from ${oip} 53 to any

	# Allow access to our WWW
	${fwcmd} add pass tcp from any to ${oip} 80 setup

	# Allow access to our FTP
	${fwcmd} add pass tcp from any to ${oip} 21 setup

	#Allow access to SSH
	${fwcmd} add pass tcp from any to ${oip} 22 setup
	
	#Allow access to TELNET from work
	${fwcmd} add pass tcp from 162.6.223.88 to ${oip} 23 setup

	# Allow setup of any other TCP connection
	${fwcmd} add pass tcp from any to any setup

	# Allow DNS queries out in the world
	${fwcmd} add pass udp from any 53 to ${oip}
	${fwcmd} add pass udp from ${oip} to any 53

	# Allow NTP queries out in the world
	${fwcmd} add pass udp from any 123 to ${oip}
	${fwcmd} add pass udp from ${oip} to any 123

	# These are split just for monitoring
      	$fwcmd add pass tcp from ${oip} to any out via ${oif} keep-state
      	$fwcmd add pass udp from ${oip} to any out via ${oif} keep-state
      	$fwcmd add pass icmp from ${oip} to any out via ${oif} keep-state
      	$fwcmd add pass ip from ${oip} to any out via ${oif} keep-state

      	$fwcmd add pass icmp from any to any icmptypes 0,3,11

      	$fwcmd add deny log tcp from any to any in via ${oif} setup
      	$fwcmd add deny log udp from any to any in via ${oif}

	# A TEMPORARY RULE - SO I DON'T LOCK MYSELF OUT
	${fwcmd} add pass all from any to any

	# 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])
	;;
*)
	if [ -r "${firewall_type}" ]; then
		${fwcmd} ${firewall_flags} ${firewall_type}
	fi
	;;
esac


_____________________________________________________________
========GET YOUR FREE E-MAIL============
http://freemail.cahostnet.net
Web Hosting http://www.cahostnet.com


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010129185530.BE45B3ED4>