rc.firewall revision 56736
1############
2# Setup system for firewall service.
3# $FreeBSD: head/etc/rc.firewall 56736 2000-01-28 11:30:28Z rgrimes $
4
5# Suck in the configuration variables.
6if [ -r /etc/defaults/rc.conf ]; then
7	. /etc/defaults/rc.conf
8elif [ -r /etc/rc.conf ]; then
9	. /etc/rc.conf
10fi
11
12############
13# Define the firewall type in /etc/rc.conf.  Valid values are:
14#   open     - will allow anyone in
15#   client   - will try to protect just this machine
16#   simple   - will try to protect a whole network
17#   closed   - totally disables IP services except via lo0 interface
18#   UNKNOWN  - disables the loading of firewall rules.
19#   filename - will load the rules in the given filename (full path required)
20#
21# For ``client'' and ``simple'' the entries below should be customized
22# appropriately.
23
24############
25#
26# If you don't know enough about packet filtering, we suggest that you
27# take time to read this book:
28#
29#	Building Internet Firewalls
30#	Brent Chapman and Elizabeth Zwicky
31#
32#	O'Reilly & Associates, Inc
33#	ISBN 1-56592-124-0
34#	http://www.ora.com/
35#
36# For a more advanced treatment of Internet Security read:
37#
38#	Firewalls & Internet Security
39#	Repelling the wily hacker
40#	William R. Cheswick, Steven M. Bellowin
41#
42#	Addison-Wesley
43#	ISBN 0-201-6337-4
44#	http://www.awl.com/
45#
46
47if [ -n "${1}" ]; then
48	firewall_type="${1}"
49fi
50
51############
52# Set quiet mode if requested
53#
54case ${firewall_quiet} in
55[Yy][Ee][Ss])
56	fwcmd="/sbin/ipfw -q"
57	;;
58*)
59	fwcmd="/sbin/ipfw"
60	;;
61esac
62
63############
64# Flush out the list before we begin.
65#
66${fwcmd} -f flush
67
68############
69# These rules are required for using natd.  All packets are passed to
70# natd before they encounter your remaining rules.  The firewall rules
71# will then be run again on each packet after translation by natd,
72# minus any divert rules (see natd(8)).
73#
74case ${natd_enable} in
75[Yy][Ee][Ss])
76	if [ -n "${natd_interface}" ]; then
77	      ${fwcmd} add divert natd all from any to any via ${natd_interface}
78	fi
79	;;
80esac
81
82############
83# If you just configured ipfw in the kernel as a tool to solve network
84# problems or you just want to disallow some particular kinds of traffic
85# then you will want to change the default policy to open.  You can also
86# do this as your only action by setting the firewall_type to ``open''.
87#
88# ${fwcmd} add 65000 pass all from any to any
89
90############
91# Only in rare cases do you want to change these rules
92#
93${fwcmd} add 100 pass all from any to any via lo0
94${fwcmd} add 200 deny all from any to 127.0.0.0/8
95# If you're using 'options BRIDGE', uncomment the following line to pass ARP
96#${fwcmd} add 300 pass udp from 0.0.0.0 2054 to 0.0.0.0
97
98
99# Prototype setups.
100#
101case ${firewall_type} in
102[Oo][Pp][Ee][Nn])
103	${fwcmd} add 65000 pass all from any to any
104	;;
105
106[Cc][Ll][Ii][Ee][Nn][Tt])
107	############
108	# This is a prototype setup that will protect your system somewhat
109	# against people from outside your own network.
110	############
111
112	# set these to your network and netmask and ip
113	net="192.0.2.0"
114	mask="255.255.255.0"
115	ip="192.0.2.1"
116
117	# Allow any traffic to or from my own net.
118	${fwcmd} add pass all from ${ip} to ${net}:${mask}
119	${fwcmd} add pass all from ${net}:${mask} to ${ip}
120
121	# Allow TCP through if setup succeeded
122	${fwcmd} add pass tcp from any to any established
123
124	# Allow IP fragments to pass through
125	${fwcmd} add pass all from any to any frag
126
127	# Allow setup of incoming email
128	${fwcmd} add pass tcp from any to ${ip} 25 setup
129
130	# Allow setup of outgoing TCP connections only
131	${fwcmd} add pass tcp from ${ip} to any setup
132
133	# Disallow setup of all other TCP connections
134	${fwcmd} add deny tcp from any to any setup
135
136	# Allow DNS queries out in the world
137	${fwcmd} add pass udp from any 53 to ${ip}
138	${fwcmd} add pass udp from ${ip} to any 53
139
140	# Allow NTP queries out in the world
141	${fwcmd} add pass udp from any 123 to ${ip}
142	${fwcmd} add pass udp from ${ip} to any 123
143
144	# Everything else is denied by default, unless the
145	# IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
146	# config file.
147	;;
148
149[Ss][Ii][Mm][Pp][Ll][Ee])
150	############
151	# This is a prototype setup for a simple firewall.  Configure this
152	# machine as a named server and ntp server, and point all the machines
153	# on the inside at this machine for those services.
154	############
155
156	# set these to your outside interface network and netmask and ip
157	oif="ed0"
158	onet="192.0.2.0"
159	omask="255.255.255.240"
160	oip="192.0.2.1"
161
162	# set these to your inside interface network and netmask and ip
163	iif="ed1"
164	inet="192.0.2.16"
165	imask="255.255.255.240"
166	iip="192.0.2.17"
167
168	# Stop spoofing
169	${fwcmd} add deny all from ${inet}:${imask} to any in via ${oif}
170	${fwcmd} add deny all from ${onet}:${omask} to any in via ${iif}
171
172	# Stop RFC1918 nets on the outside interface
173	${fwcmd} add deny all from 10.0.0.0/8 to any via ${oif}
174	${fwcmd} add deny all from any to 10.0.0.0/8 via ${oif}
175	${fwcmd} add deny all from 172.16.0.0/12 to any via ${oif}
176	${fwcmd} add deny all from any to 172.16.0.0/12 via ${oif}
177	${fwcmd} add deny all from 192.168.0.0/16 to any via ${oif}
178	${fwcmd} add deny all from any to 192.168.0.0/16 via ${oif}
179
180	# Stop draft-manning-dsua-01.txt nets on the outside interface
181	${fwcmd} add deny all from 0.0.0.0/8 to any via ${oif}
182	${fwcmd} add deny all from any to 0.0.0.0/8 via ${oif}
183	${fwcmd} add deny all from 169.254.0.0/16 to any via ${oif}
184	${fwcmd} add deny all from any to 169.254.0.0/16 via ${oif}
185	${fwcmd} add deny all from 192.0.2.0/24 to any via ${oif}
186	${fwcmd} add deny all from any to 192.0.2.0/24 via ${oif}
187	${fwcmd} add deny all from 224.0.0.0/4 to any via ${oif}
188	${fwcmd} add deny all from any to 224.0.0.0/4 via ${oif}
189	${fwcmd} add deny all from 240.0.0.0/4 to any via ${oif}
190	${fwcmd} add deny all from any to 240.0.0.0/4 via ${oif}
191
192	# Allow TCP through if setup succeeded
193	${fwcmd} add pass tcp from any to any established
194
195	# Allow IP fragments to pass through
196	${fwcmd} add pass all from any to any frag
197
198	# Allow setup of incoming email
199	${fwcmd} add pass tcp from any to ${oip} 25 setup
200
201	# Allow access to our DNS
202	${fwcmd} add pass tcp from any to ${oip} 53 setup
203	${fwcmd} add pass udp from any to ${oip} 53
204	${fwcmd} add pass udp from ${oip} 53 to any
205
206	# Allow access to our WWW
207	${fwcmd} add pass tcp from any to ${oip} 80 setup
208
209	# Reject&Log all setup of incoming connections from the outside
210	${fwcmd} add deny log tcp from any to any in via ${oif} setup
211
212	# Allow setup of any other TCP connection
213	${fwcmd} add pass tcp from any to any setup
214
215	# Allow DNS queries out in the world
216	${fwcmd} add pass udp from any 53 to ${oip}
217	${fwcmd} add pass udp from ${oip} to any 53
218
219	# Allow NTP queries out in the world
220	${fwcmd} add pass udp from any 123 to ${oip}
221	${fwcmd} add pass udp from ${oip} to any 123
222
223	# Everything else is denied by default, unless the
224	# IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
225	# config file.
226	;;
227
228[Uu][Nn][Kk][Nn][Oo][Ww][Nn])
229	;;
230*)
231	if [ -r "${firewall_type}" ]; then
232		${fwcmd} ${firewall_type}
233	fi
234	;;
235esac
236