]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.firewall
Introduce /etc/defaults/periodic.conf, similar in concept to rc.conf.
[FreeBSD/FreeBSD.git] / etc / rc.firewall
1 ############
2 # Setup system for firewall service.
3 # $FreeBSD$
4
5 # Suck in the configuration variables.
6 if [ -r /etc/defaults/rc.conf ]; then
7         . /etc/defaults/rc.conf
8         source_rc_confs
9 elif [ -r /etc/rc.conf ]; then
10         . /etc/rc.conf
11 fi
12
13 ############
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)
21 #
22 # For ``client'' and ``simple'' the entries below should be customized
23 # appropriately.
24
25 ############
26 #
27 # If you don't know enough about packet filtering, we suggest that you
28 # take time to read this book:
29 #
30 #       Building Internet Firewalls
31 #       Brent Chapman and Elizabeth Zwicky
32 #
33 #       O'Reilly & Associates, Inc
34 #       ISBN 1-56592-124-0
35 #       http://www.ora.com/
36 #
37 # For a more advanced treatment of Internet Security read:
38 #
39 #       Firewalls & Internet Security
40 #       Repelling the wily hacker
41 #       William R. Cheswick, Steven M. Bellowin
42 #
43 #       Addison-Wesley
44 #       ISBN 0-201-6337-4
45 #       http://www.awl.com/
46 #
47
48 if [ -n "${1}" ]; then
49         firewall_type="${1}"
50 fi
51
52 ############
53 # Set quiet mode if requested
54 #
55 case ${firewall_quiet} in
56 [Yy][Ee][Ss])
57         fwcmd="/sbin/ipfw -q"
58         ;;
59 *)
60         fwcmd="/sbin/ipfw"
61         ;;
62 esac
63
64 ############
65 # Flush out the list before we begin.
66 #
67 ${fwcmd} -f flush
68
69 ############
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)).
74 #
75 case ${natd_enable} in
76 [Yy][Ee][Ss])
77         if [ -n "${natd_interface}" ]; then
78               ${fwcmd} add 50 divert natd all from any to any via ${natd_interface}
79         fi
80         ;;
81 esac
82
83 ############
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''.
88 #
89 # ${fwcmd} add 65000 pass all from any to any
90
91 ############
92 # Only in rare cases do you want to change these rules
93 #
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
98
99
100 # Prototype setups.
101 #
102 case ${firewall_type} in
103 [Oo][Pp][Ee][Nn])
104         ${fwcmd} add 65000 pass all from any to any
105         ;;
106
107 [Cc][Ll][Ii][Ee][Nn][Tt])
108         ############
109         # This is a prototype setup that will protect your system somewhat
110         # against people from outside your own network.
111         ############
112
113         # set these to your network and netmask and ip
114         net="192.0.2.0"
115         mask="255.255.255.0"
116         ip="192.0.2.1"
117
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}
121
122         # Allow TCP through if setup succeeded
123         ${fwcmd} add pass tcp from any to any established
124
125         # Allow IP fragments to pass through
126         ${fwcmd} add pass all from any to any frag
127
128         # Allow setup of incoming email
129         ${fwcmd} add pass tcp from any to ${ip} 25 setup
130
131         # Allow setup of outgoing TCP connections only
132         ${fwcmd} add pass tcp from ${ip} to any setup
133
134         # Disallow setup of all other TCP connections
135         ${fwcmd} add deny tcp from any to any setup
136
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
140
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
144
145         # Everything else is denied by default, unless the
146         # IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
147         # config file.
148         ;;
149
150 [Ss][Ii][Mm][Pp][Ll][Ee])
151         ############
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.
155         ############
156
157         # set these to your outside interface network and netmask and ip
158         oif="ed0"
159         onet="192.0.2.0"
160         omask="255.255.255.240"
161         oip="192.0.2.1"
162
163         # set these to your inside interface network and netmask and ip
164         iif="ed1"
165         inet="192.0.2.16"
166         imask="255.255.255.240"
167         iip="192.0.2.17"
168
169         # Stop spoofing
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}
172
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}
180
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}
192
193         # Allow TCP through if setup succeeded
194         ${fwcmd} add pass tcp from any to any established
195
196         # Allow IP fragments to pass through
197         ${fwcmd} add pass all from any to any frag
198
199         # Allow setup of incoming email
200         ${fwcmd} add pass tcp from any to ${oip} 25 setup
201
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
206
207         # Allow access to our WWW
208         ${fwcmd} add pass tcp from any to ${oip} 80 setup
209
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
212
213         # Allow setup of any other TCP connection
214         ${fwcmd} add pass tcp from any to any setup
215
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
219
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
223
224         # Everything else is denied by default, unless the
225         # IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel
226         # config file.
227         ;;
228
229 [Uu][Nn][Kk][Nn][Oo][Ww][Nn])
230         ;;
231 *)
232         if [ -r "${firewall_type}" ]; then
233                 ${fwcmd} ${firewall_flags} ${firewall_type}
234         fi
235         ;;
236 esac