rc.firewall revision 64028
1############ 2# Setup system for firewall service. 3# $FreeBSD: head/etc/rc.firewall 64028 2000-07-30 19:28:05Z obrien $ 4 5# Suck in the configuration variables. 6if [ -r /etc/defaults/rc.conf ]; then 7 . /etc/defaults/rc.conf 8 source_rc_confs 9elif [ -r /etc/rc.conf ]; then 10 . /etc/rc.conf 11fi 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 48if [ -n "${1}" ]; then 49 firewall_type="${1}" 50fi 51 52############ 53# Set quiet mode if requested 54# 55case ${firewall_quiet} in 56[Yy][Ee][Ss]) 57 fwcmd="/sbin/ipfw -q" 58 ;; 59*) 60 fwcmd="/sbin/ipfw" 61 ;; 62esac 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# 75case ${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 ;; 81esac 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# 102case ${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-03.txt (1 May 2000) nets (includes RESERVED-1, 182 # DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E) 183 # on the outside interface 184 ${fwcmd} add deny all from 0.0.0.0/8 to any via ${oif} 185 ${fwcmd} add deny all from any to 0.0.0.0/8 via ${oif} 186 ${fwcmd} add deny all from 169.254.0.0/16 to any via ${oif} 187 ${fwcmd} add deny all from any to 169.254.0.0/16 via ${oif} 188 ${fwcmd} add deny all from 192.0.2.0/24 to any via ${oif} 189 ${fwcmd} add deny all from any to 192.0.2.0/24 via ${oif} 190 ${fwcmd} add deny all from 224.0.0.0/4 to any via ${oif} 191 ${fwcmd} add deny all from any to 224.0.0.0/4 via ${oif} 192 ${fwcmd} add deny all from 240.0.0.0/4 to any via ${oif} 193 ${fwcmd} add deny all from any to 240.0.0.0/4 via ${oif} 194 195 # Allow TCP through if setup succeeded 196 ${fwcmd} add pass tcp from any to any established 197 198 # Allow IP fragments to pass through 199 ${fwcmd} add pass all from any to any frag 200 201 # Allow setup of incoming email 202 ${fwcmd} add pass tcp from any to ${oip} 25 setup 203 204 # Allow access to our DNS 205 ${fwcmd} add pass tcp from any to ${oip} 53 setup 206 ${fwcmd} add pass udp from any to ${oip} 53 207 ${fwcmd} add pass udp from ${oip} 53 to any 208 209 # Allow access to our WWW 210 ${fwcmd} add pass tcp from any to ${oip} 80 setup 211 212 # Reject&Log all setup of incoming connections from the outside 213 ${fwcmd} add deny log tcp from any to any in via ${oif} setup 214 215 # Allow setup of any other TCP connection 216 ${fwcmd} add pass tcp from any to any setup 217 218 # Allow DNS queries out in the world 219 ${fwcmd} add pass udp from any 53 to ${oip} 220 ${fwcmd} add pass udp from ${oip} to any 53 221 222 # Allow NTP queries out in the world 223 ${fwcmd} add pass udp from any 123 to ${oip} 224 ${fwcmd} add pass udp from ${oip} to any 123 225 226 # Everything else is denied by default, unless the 227 # IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel 228 # config file. 229 ;; 230 231[Uu][Nn][Kk][Nn][Oo][Ww][Nn]) 232 ;; 233*) 234 if [ -r "${firewall_type}" ]; then 235 ${fwcmd} ${firewall_flags} ${firewall_type} 236 fi 237 ;; 238esac 239