2 # Setup system for firewall service.
5 # Suck in the configuration variables.
6 if [ -r /etc/defaults/rc.conf ]; then
7 . /etc/defaults/rc.conf
9 elif [ -r /etc/rc.conf ]; then
14 # Define the firewall type in /etc/rc.conf. Valid values are:
15 # open - will allow anyone in
16 # client - will try to protect just this machine
17 # simple - will try to protect a whole network
18 # closed - totally disables IP services except via lo0 interface
19 # UNKNOWN - disables the loading of firewall rules.
20 # filename - will load the rules in the given filename (full path required)
22 # For ``client'' and ``simple'' the entries below should be customized
27 # If you don't know enough about packet filtering, we suggest that you
28 # take time to read this book:
30 # Building Internet Firewalls
31 # Brent Chapman and Elizabeth Zwicky
33 # O'Reilly & Associates, Inc
37 # For a more advanced treatment of Internet Security read:
39 # Firewalls & Internet Security
40 # Repelling the wily hacker
41 # William R. Cheswick, Steven M. Bellowin
48 if [ -n "${1}" ]; then
53 # Set quiet mode if requested
55 case ${firewall_quiet} in
65 # Flush out the list before we begin.
70 # These rules are required for using natd. All packets are passed to
71 # natd before they encounter your remaining rules. The firewall rules
72 # will then be run again on each packet after translation by natd,
73 # minus any divert rules (see natd(8)).
75 case ${natd_enable} in
77 if [ -n "${natd_interface}" ]; then
78 ${fwcmd} add 50 divert natd all from any to any via ${natd_interface}
84 # If you just configured ipfw in the kernel as a tool to solve network
85 # problems or you just want to disallow some particular kinds of traffic
86 # then you will want to change the default policy to open. You can also
87 # do this as your only action by setting the firewall_type to ``open''.
89 # ${fwcmd} add 65000 pass all from any to any
92 # Only in rare cases do you want to change these rules
94 ${fwcmd} add 100 pass all from any to any via lo0
95 ${fwcmd} add 200 deny all from any to 127.0.0.0/8
96 # If you're using 'options BRIDGE', uncomment the following line to pass ARP
97 #${fwcmd} add 300 pass udp from 0.0.0.0 2054 to 0.0.0.0
102 case ${firewall_type} in
104 ${fwcmd} add 65000 pass all from any to any
107 [Cc][Ll][Ii][Ee][Nn][Tt])
109 # This is a prototype setup that will protect your system somewhat
110 # against people from outside your own network.
113 # set these to your network and netmask and ip
118 # Allow any traffic to or from my own net.
119 ${fwcmd} add pass all from ${ip} to ${net}:${mask}
120 ${fwcmd} add pass all from ${net}:${mask} to ${ip}
122 # Allow TCP through if setup succeeded
123 ${fwcmd} add pass tcp from any to any established
125 # Allow IP fragments to pass through
126 ${fwcmd} add pass all from any to any frag
128 # Allow setup of incoming email
129 ${fwcmd} add pass tcp from any to ${ip} 25 setup
131 # Allow setup of outgoing TCP connections only
132 ${fwcmd} add pass tcp from ${ip} to any setup
134 # Disallow setup of all other TCP connections
135 ${fwcmd} add deny tcp from any to any setup
137 # Allow DNS queries out in the world
138 ${fwcmd} add pass udp from any 53 to ${ip}
139 ${fwcmd} add pass udp from ${ip} to any 53
141 # Allow NTP queries out in the world
142 ${fwcmd} add pass udp from any 123 to ${ip}
143 ${fwcmd} add pass udp from ${ip} to any 123
145 # Everything else is denied by default, unless the
146 # IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
150 [Ss][Ii][Mm][Pp][Ll][Ee])
152 # This is a prototype setup for a simple firewall. Configure this
153 # machine as a named server and ntp server, and point all the machines
154 # on the inside at this machine for those services.
157 # set these to your outside interface network and netmask and ip
160 omask="255.255.255.240"
163 # set these to your inside interface network and netmask and ip
166 imask="255.255.255.240"
170 ${fwcmd} add deny all from ${inet}:${imask} to any in via ${oif}
171 ${fwcmd} add deny all from ${onet}:${omask} to any in via ${iif}
173 # Stop RFC1918 nets on the outside interface
174 ${fwcmd} add deny all from 10.0.0.0/8 to any via ${oif}
175 ${fwcmd} add deny all from any to 10.0.0.0/8 via ${oif}
176 ${fwcmd} add deny all from 172.16.0.0/12 to any via ${oif}
177 ${fwcmd} add deny all from any to 172.16.0.0/12 via ${oif}
178 ${fwcmd} add deny all from 192.168.0.0/16 to any via ${oif}
179 ${fwcmd} add deny all from any to 192.168.0.0/16 via ${oif}
181 # Stop draft-manning-dsua-01.txt nets on the outside interface
182 ${fwcmd} add deny all from 0.0.0.0/8 to any via ${oif}
183 ${fwcmd} add deny all from any to 0.0.0.0/8 via ${oif}
184 ${fwcmd} add deny all from 169.254.0.0/16 to any via ${oif}
185 ${fwcmd} add deny all from any to 169.254.0.0/16 via ${oif}
186 ${fwcmd} add deny all from 192.0.2.0/24 to any via ${oif}
187 ${fwcmd} add deny all from any to 192.0.2.0/24 via ${oif}
188 ${fwcmd} add deny all from 224.0.0.0/4 to any via ${oif}
189 ${fwcmd} add deny all from any to 224.0.0.0/4 via ${oif}
190 ${fwcmd} add deny all from 240.0.0.0/4 to any via ${oif}
191 ${fwcmd} add deny all from any to 240.0.0.0/4 via ${oif}
193 # Allow TCP through if setup succeeded
194 ${fwcmd} add pass tcp from any to any established
196 # Allow IP fragments to pass through
197 ${fwcmd} add pass all from any to any frag
199 # Allow setup of incoming email
200 ${fwcmd} add pass tcp from any to ${oip} 25 setup
202 # Allow access to our DNS
203 ${fwcmd} add pass tcp from any to ${oip} 53 setup
204 ${fwcmd} add pass udp from any to ${oip} 53
205 ${fwcmd} add pass udp from ${oip} 53 to any
207 # Allow access to our WWW
208 ${fwcmd} add pass tcp from any to ${oip} 80 setup
210 # Reject&Log all setup of incoming connections from the outside
211 ${fwcmd} add deny log tcp from any to any in via ${oif} setup
213 # Allow setup of any other TCP connection
214 ${fwcmd} add pass tcp from any to any setup
216 # Allow DNS queries out in the world
217 ${fwcmd} add pass udp from any 53 to ${oip}
218 ${fwcmd} add pass udp from ${oip} to any 53
220 # Allow NTP queries out in the world
221 ${fwcmd} add pass udp from any 123 to ${oip}
222 ${fwcmd} add pass udp from ${oip} to any 123
224 # Everything else is denied by default, unless the
225 # IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
229 [Uu][Nn][Kk][Nn][Oo][Ww][Nn])
232 if [ -r "${firewall_type}" ]; then
233 ${fwcmd} ${firewall_flags} ${firewall_type}