rc.firewall revision 52404
1############
2# Setup system for firewall service.
3# $FreeBSD: head/etc/rc.firewall 52404 1999-10-20 08:15:13Z ru $
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
96
97# Prototype setups.
98#
99case ${firewall_type} in
100[Oo][Pp][Ee][Nn])
101	${fwcmd} add 65000 pass all from any to any
102	;;
103[Cc][Ll][Ii][Ee][Nn][Tt])
104
105	############
106	# This is a prototype setup that will protect your system somewhat
107	# against people from outside your own network.
108	############
109
110	# set these to your network and netmask and ip
111	net="192.168.4.0"
112	mask="255.255.255.0"
113	ip="192.168.4.17"
114
115	# Allow any traffic to or from my own net.
116	${fwcmd} add pass all from ${ip} to ${net}:${mask}
117	${fwcmd} add pass all from ${net}:${mask} to ${ip}
118
119	# Allow TCP through if setup succeeded
120	${fwcmd} add pass tcp from any to any established
121
122	# Allow setup of incoming email
123	${fwcmd} add pass tcp from any to ${ip} 25 setup
124
125	# Allow setup of outgoing TCP connections only
126	${fwcmd} add pass tcp from ${ip} to any setup
127
128	# Disallow setup of all other TCP connections
129	${fwcmd} add deny tcp from any to any setup
130
131	# Allow DNS queries out in the world
132	${fwcmd} add pass udp from any 53 to ${ip}
133	${fwcmd} add pass udp from ${ip} to any 53
134
135	# Allow NTP queries out in the world
136	${fwcmd} add pass udp from any 123 to ${ip}
137	${fwcmd} add pass udp from ${ip} to any 123
138
139	# Everything else is denied by default, unless the
140	# IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
141	# config file.
142	;;
143
144[Ss][Ii][Mm][Pp][Ll][Ee])
145
146	############
147	# This is a prototype setup for a simple firewall.  Configure this
148	# machine as a named server and ntp server, and point all the machines
149	# on the inside at this machine for those services.
150	############
151
152	# set these to your outside interface network and netmask and ip
153	oif="ed0"
154	onet="192.168.4.0"
155	omask="255.255.255.0"
156	oip="192.168.4.17"
157
158	# set these to your inside interface network and netmask and ip
159	iif="ed1"
160	inet="192.168.3.0"
161	imask="255.255.255.0"
162	iip="192.168.3.17"
163
164	# Stop spoofing
165	${fwcmd} add deny all from ${inet}:${imask} to any in via ${oif}
166	${fwcmd} add deny all from ${onet}:${omask} to any in via ${iif}
167
168	# Stop RFC1918 nets on the outside interface
169	${fwcmd} add deny all from 192.168.0.0:255.255.0.0 to any via ${oif}
170	${fwcmd} add deny all from any to 192.168.0.0:255.255.0.0 via ${oif}
171	${fwcmd} add deny all from 172.16.0.0:255.240.0.0 to any via ${oif}
172	${fwcmd} add deny all from any to 172.16.0.0:255.240.0.0 via ${oif}
173	${fwcmd} add deny all from 10.0.0.0:255.0.0.0 to any via ${oif}
174	${fwcmd} add deny all from any to 10.0.0.0:255.0.0.0 via ${oif}
175
176	# Allow TCP through if setup succeeded
177	${fwcmd} add pass tcp from any to any established
178
179	# Allow setup of incoming email
180	${fwcmd} add pass tcp from any to ${oip} 25 setup
181
182	# Allow access to our DNS
183	${fwcmd} add pass tcp from any to ${oip} 53 setup
184	${fwcmd} add pass udp from any to ${oip} 53
185	${fwcmd} add pass udp from ${oip} 53 to any
186
187	# Allow access to our WWW
188	${fwcmd} add pass tcp from any to ${oip} 80 setup
189
190	# Reject&Log all setup of incoming connections from the outside
191	${fwcmd} add deny log tcp from any to any in via ${oif} setup
192
193	# Allow setup of any other TCP connection
194	${fwcmd} add pass tcp from any to any setup
195
196	# Allow DNS queries out in the world
197	${fwcmd} add pass udp from any 53 to ${oip}
198	${fwcmd} add pass udp from ${oip} to any 53
199
200	# Allow NTP queries out in the world
201	${fwcmd} add pass udp from any 123 to ${oip}
202	${fwcmd} add pass udp from ${oip} to any 123
203
204	# Everything else is denied by default, unless the
205	# IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
206	# config file.
207	;;
208
209[Uu][Nn][Kk][Nn][Oo][Ww][Nn])
210	;;
211*)
212	if [ -r "${firewall_type}" ]; then
213		${fwcmd} ${firewall_type}
214	fi
215	;;
216esac
217