rc.firewall revision 33203
1############
2# Setup system for firewall service.
3# $Id: rc.firewall,v 1.15 1997/10/21 00:54:08 danny Exp $
4
5if [ -f /etc/rc.conf ]; then
6	. /etc/rc.conf
7fi
8
9############
10# Define the firewall type in /etc/rc.conf.  Valid values are:
11#   open     - will allow anyone in
12#   client   - will try to protect just this machine
13#   simple   - will try to protect a whole network
14#   closed   - totally disables IP services except via lo0 interface
15#   UNKNOWN  - disables the loading of firewall rules.
16#   filename - will load the rules in the given filename (full path required)
17#
18# For ``client'' and ``simple'' the entries below should be customized 
19# appropriately.
20
21############
22#
23# If you don't know enough about packet filtering, we suggest that you
24# take time to read this book:
25#
26#	Building Internet Firewalls
27#	Brent Chapman and Elizabeth Zwicky
28#
29#	O'Reilly & Associates, Inc
30#	ISBN 1-56592-124-0
31#	http://www.ora.com/
32#
33# For a more advanced treatment of Internet Security read:
34#
35#	Firewalls & Internet Security
36#	Repelling the wily hacker
37#	William R. Cheswick, Steven M. Bellowin
38#
39#	Addison-Wesley
40#	ISBN 0-201-6337-4
41#	http://www.awl.com/
42#
43
44if [ "x$1" != "x" ]; then
45	firewall_type=$1
46fi
47
48############
49# Set quiet mode if requested
50if [ "x$firewall_quiet" = "xYES" ]; then
51	fwcmd="/sbin/ipfw -q"
52else
53	fwcmd="/sbin/ipfw"
54fi
55
56############
57# Flush out the list before we begin.
58$fwcmd -f flush
59
60############
61# If you just configured ipfw in the kernel as a tool to solve network
62# problems or you just want to disallow some particular kinds of traffic
63# they you will want to change the default policy to open.  You can also
64# do this as your only action by setting the firewall_type to ``open''.
65
66# $fwcmd add 65000 pass all from any to any
67
68############
69# Only in rare cases do you want to change these rules
70$fwcmd add 1000 pass all from any to any via lo0
71$fwcmd add 1010 deny all from 127.0.0.0/8 to 127.0.0.0/8
72
73
74# Prototype setups.
75if [ "${firewall_type}" = "open" -o "${firewall_type}" = "OPEN" ]; then
76
77	$fwcmd add 65000 pass all from any to any
78
79elif [ "${firewall_type}" = "client" ]; then
80
81    ############
82    # This is a prototype setup that will protect your system somewhat against
83    # people from outside your own network.
84    ############
85
86    # set these to your network and netmask and ip
87    net="192.168.4.0"
88    mask="255.255.255.0"
89    ip="192.168.4.17"
90
91    # Allow any traffic to or from my own net.
92    $fwcmd add pass all from ${ip} to ${net}:${mask}
93    $fwcmd add pass all from ${net}:${mask} to ${ip}
94
95    # Allow TCP through if setup succeeded
96    $fwcmd add pass tcp from any to any established
97
98    # Allow setup of incoming email 
99    $fwcmd add pass tcp from any to ${ip} 25 setup
100
101    # Allow setup of outgoing TCP connections only
102    $fwcmd add pass tcp from ${ip} to any setup
103
104    # Disallow setup of all other TCP connections
105    $fwcmd add deny tcp from any to any setup
106
107    # Allow DNS queries out in the world
108    $fwcmd add pass udp from any 53 to ${ip}
109    $fwcmd add pass udp from ${ip} to any 53
110
111    # Allow NTP queries out in the world
112    $fwcmd add pass udp from any 123 to ${ip}
113    $fwcmd add pass udp from ${ip} to any 123
114
115    # Everything else is denied as default.
116
117elif [ "${firewall_type}" = "simple" ]; then
118
119    ############
120    # This is a prototype setup for a simple firewall.  Configure this machine 
121    # as a named server and ntp server, and point all the machines on the inside
122    # at this machine for those services.
123    ############
124
125    # set these to your outside interface network and netmask and ip
126    oif="ed0"
127    onet="192.168.4.0"
128    omask="255.255.255.0"
129    oip="192.168.4.17"
130
131    # set these to your inside interface network and netmask and ip
132    iif="ed1"
133    inet="192.168.3.0"
134    imask="255.255.255.0"
135    iip="192.168.3.17"
136
137    # Stop spoofing
138    $fwcmd add deny all from ${inet}:${imask} to any in via ${oif}
139    $fwcmd add deny all from ${onet}:${omask} to any in via ${iif}
140
141    # Stop RFC1918 nets on the outside interface
142    $fwcmd add deny all from 192.168.0.0:255.255.0.0 to any via ${oif}
143    $fwcmd add deny all from 172.16.0.0:255.240.0.0 to any via ${oif}
144    $fwcmd add deny all from 10.0.0.0:255.0.0.0 to any via ${oif}
145
146    # Allow TCP through if setup succeeded
147    $fwcmd add pass tcp from any to any established
148
149    # Allow setup of incoming email 
150    $fwcmd add pass tcp from any to ${oip} 25 setup
151
152    # Allow access to our DNS
153    $fwcmd add pass tcp from any to ${oip} 53 setup
154
155    # Allow access to our WWW
156    $fwcmd add pass tcp from any to ${oip} 80 setup
157
158    # Reject&Log all setup of incoming connections from the outside
159    $fwcmd add deny log tcp from any to any in via ${oif} setup
160
161    # Allow setup of any other TCP connection
162    $fwcmd add pass tcp from any to any setup
163
164    # Allow DNS queries out in the world
165    $fwcmd add pass udp from any 53 to ${oip}
166    $fwcmd add pass udp from ${oip} to any 53
167
168    # Allow NTP queries out in the world
169    $fwcmd add pass udp from any 123 to ${oip}
170    $fwcmd add pass udp from ${oip} to any 123
171
172    # Everything else is denied as default.
173
174elif [ "${firewall_type}" != "UNKNOWN" -a -r "${firewall_type}" ]; then
175	$fwcmd ${firewall_type}
176fi
177