rc.firewall revision 52873
1############ 2# Setup system for firewall service. 3# $FreeBSD: head/etc/rc.firewall 52873 1999-11-04 10:13:59Z 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# If you're using 'options BRIDGE', uncomment the following line to pass ARP 96#${fwcmd} add 300 pass udp from 0.0.0.0 2054 to 0.0.0.0 97 98 99# Prototype setups. 100# 101case ${firewall_type} in 102[Oo][Pp][Ee][Nn]) 103 ${fwcmd} add 65000 pass all from any to any 104 ;; 105[Cc][Ll][Ii][Ee][Nn][Tt]) 106 107 ############ 108 # This is a prototype setup that will protect your system somewhat 109 # against people from outside your own network. 110 ############ 111 112 # set these to your network and netmask and ip 113 net="192.168.4.0" 114 mask="255.255.255.0" 115 ip="192.168.4.17" 116 117 # Allow any traffic to or from my own net. 118 ${fwcmd} add pass all from ${ip} to ${net}:${mask} 119 ${fwcmd} add pass all from ${net}:${mask} to ${ip} 120 121 # Allow TCP through if setup succeeded 122 ${fwcmd} add pass tcp from any to any established 123 124 # Allow IP fragments to pass through 125 ${fwcmd} add pass all from any to any frag 126 127 # Allow setup of incoming email 128 ${fwcmd} add pass tcp from any to ${ip} 25 setup 129 130 # Allow setup of outgoing TCP connections only 131 ${fwcmd} add pass tcp from ${ip} to any setup 132 133 # Disallow setup of all other TCP connections 134 ${fwcmd} add deny tcp from any to any setup 135 136 # Allow DNS queries out in the world 137 ${fwcmd} add pass udp from any 53 to ${ip} 138 ${fwcmd} add pass udp from ${ip} to any 53 139 140 # Allow NTP queries out in the world 141 ${fwcmd} add pass udp from any 123 to ${ip} 142 ${fwcmd} add pass udp from ${ip} to any 123 143 144 # Everything else is denied by default, unless the 145 # IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel 146 # config file. 147 ;; 148 149[Ss][Ii][Mm][Pp][Ll][Ee]) 150 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.168.4.0" 160 omask="255.255.255.0" 161 oip="192.168.4.17" 162 163 # set these to your inside interface network and netmask and ip 164 iif="ed1" 165 inet="192.168.3.0" 166 imask="255.255.255.0" 167 iip="192.168.3.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 192.168.0.0:255.255.0.0 to any via ${oif} 175 ${fwcmd} add deny all from any to 192.168.0.0:255.255.0.0 via ${oif} 176 ${fwcmd} add deny all from 172.16.0.0:255.240.0.0 to any via ${oif} 177 ${fwcmd} add deny all from any to 172.16.0.0:255.240.0.0 via ${oif} 178 ${fwcmd} add deny all from 10.0.0.0:255.0.0.0 to any via ${oif} 179 ${fwcmd} add deny all from any to 10.0.0.0:255.0.0.0 via ${oif} 180 181 # Allow TCP through if setup succeeded 182 ${fwcmd} add pass tcp from any to any established 183 184 # Allow IP fragments to pass through 185 ${fwcmd} add pass all from any to any frag 186 187 # Allow setup of incoming email 188 ${fwcmd} add pass tcp from any to ${oip} 25 setup 189 190 # Allow access to our DNS 191 ${fwcmd} add pass tcp from any to ${oip} 53 setup 192 ${fwcmd} add pass udp from any to ${oip} 53 193 ${fwcmd} add pass udp from ${oip} 53 to any 194 195 # Allow access to our WWW 196 ${fwcmd} add pass tcp from any to ${oip} 80 setup 197 198 # Reject&Log all setup of incoming connections from the outside 199 ${fwcmd} add deny log tcp from any to any in via ${oif} setup 200 201 # Allow setup of any other TCP connection 202 ${fwcmd} add pass tcp from any to any setup 203 204 # Allow DNS queries out in the world 205 ${fwcmd} add pass udp from any 53 to ${oip} 206 ${fwcmd} add pass udp from ${oip} to any 53 207 208 # Allow NTP queries out in the world 209 ${fwcmd} add pass udp from any 123 to ${oip} 210 ${fwcmd} add pass udp from ${oip} to any 123 211 212 # Everything else is denied by default, unless the 213 # IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel 214 # config file. 215 ;; 216 217[Uu][Nn][Kk][Nn][Oo][Ww][Nn]) 218 ;; 219*) 220 if [ -r "${firewall_type}" ]; then 221 ${fwcmd} ${firewall_type} 222 fi 223 ;; 224esac 225