#!/bin/sh - # set these to your outside interface network and netmask and ip oif="tun0" # onet="x.x.x.x" # omask="255.255.255.0" # oip="x.x.x.x" # set these to your inside interface network and netmask and ip iif="fxp0" inet="10.0.0.0" imask="255.255.255.0" iip="10.0.0.1" # inetd mailserver inetdmail="211.13.206.142" # Setup system for firewall service. # # Suck in the configuration variables. if [ -z "${source_rc_confs_defined}" ]; then if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi fi setup_loopback () { ############ # Only in rare cases do you want to change these rules # ${fwcmd} add 100 pass all from any to any via lo0 ${fwcmd} add 200 deny all from any to 127.0.0.0/8 ${fwcmd} add 300 deny ip from 127.0.0.0/8 to any } if [ -n "${1}" ]; then firewall_type="${1}" fi ############ # Set quiet mode if requested # case ${firewall_quiet} in [Yy][Ee][Ss]) fwcmd="/sbin/ipfw -q" ;; *) fwcmd="/sbin/ipfw" ;; esac ############ # Flush out the list before we begin. # ${fwcmd} -f flush ############ # This is a prototype setup for a simple firewall. Configure this # machine as a named server and ntp server, and point all the machines # on the inside at this machine for those services. ############ setup_loopback # Stop spoofing # ${fwcmd} add deny all from ${inet}:${imask} to any in via ${oif} # ${fwcmd} add deny all from ${onet}:${omask} to any in via ${iif} # Stop RFC1918 nets on the outside interface ${fwcmd} add deny all from any to 10.0.0.0/8 via ${oif} ${fwcmd} add deny all from any to 172.16.0.0/12 via ${oif} ${fwcmd} add deny all from any to 192.168.0.0/16 via ${oif} # Stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1, # DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E) # on the outside interface ${fwcmd} add deny all from any to 0.0.0.0/8 via ${oif} ${fwcmd} add deny all from any to 169.254.0.0/16 via ${oif} ${fwcmd} add deny all from any to 192.0.2.0/24 via ${oif} ${fwcmd} add deny all from any to 224.0.0.0/4 via ${oif} ${fwcmd} add deny all from any to 240.0.0.0/4 via ${oif} # NetBIOS ${fwcmd} add deny log udp from any to any 137-139,135,445 via tun0 ${fwcmd} add deny log udp from any 137-139,135,445 to any via tun0 ${fwcmd} add deny log tcp from any to any 137-139,135,445 via tun0 ${fwcmd} add deny log tcp from any 137-139,135,445 to any via tun0 # Network Address Translation. This rule is placed here deliberately # so that it does not interfere with the surrounding address-checking # rules. If for example one of your internal LAN machines had its IP # address set to 192.0.2.1 then an incoming packet for it after being # translated by natd(8) would match the `deny' rule above. Similarly # an outgoing packet originated from it before being translated would # match the `deny' rule below. case ${natd_enable} in [Yy][Ee][Ss]) if [ -n "${natd_interface}" ]; then ${fwcmd} add divert natd all from any to any via ${natd_interface} fi ;; esac # Stop RFC1918 nets on the outside interface ${fwcmd} add deny all from 10.0.0.0/8 to any via ${oif} ${fwcmd} add deny all from 172.16.0.0/12 to any via ${oif} ${fwcmd} add deny all from 192.168.0.0/16 to any via ${oif} # Stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1, # DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E) # on the outside interface ${fwcmd} add deny all from 0.0.0.0/8 to any via ${oif} ${fwcmd} add deny all from 169.254.0.0/16 to any via ${oif} ${fwcmd} add deny all from 192.0.2.0/24 to any via ${oif} ${fwcmd} add deny all from 224.0.0.0/4 to any via ${oif} ${fwcmd} add deny all from 240.0.0.0/4 to any via ${oif} # Reject SMTP from local network except toriyu.dd.que.ne.jp and inetdmail ${fwcmd} add allow tcp from ${iip} to any 25 setup ${fwcmd} add allow tcp from any to ${inetdmail} 25 setup ${fwcmd} add allow tcp from ${inet}:${imask} to ${iip} 25 setup ${fwcmd} add deny log tcp from ${inet}:${imask} to any 25 setup # Allow TCP through if setup succeeded ${fwcmd} add pass tcp from any to any established # Allow IP fragments to pass through ${fwcmd} add pass all from any to any frag # Allow setup of incoming email # ${fwcmd} add pass tcp from any to ${oip} 25 setup # Allow setup of incoming POP3 # ${fwcmd} add pass tcp from any to ${oip} 110 setup # CHECK STATE ${fwcmd} add check-state ${fwcmd} add allow tcp from any to any keep-state out via ${oif} ${fwcmd} add allow udp from any to any keep-state out via ${oif} ${fwcmd} add allow tcp from ${inet}:$imask to any keep-state ${fwcmd} add allow udp from ${inet}:$imask to any keep-state # ftp # ${fwcmd} add allow tcp from any 20 to ${inet}:${imask} 1024-65535 setup in via ${oif} # Reject&Log all setup of incoming connections from the outside ${fwcmd} add 30000 deny log tcp from any to any in via ${oif} setup # Allow setup of any other TCP connection ${fwcmd} add pass tcp from any to any via ${oif} setup # allow ICMP ${fwcmd} add allow icmp from any to any in via ${oif} icmptype 0,3,4,11,12 ${fwcmd} add allow icmp from any to any out via ${oif} icmptype 0,3,4,8,11,12 ${fwcmd} add allow icmp from any to any via ${iif} icmptype 0,3,4,8,11,12 # ${fwcmd} add deny icmp from any to any via ${oif} # ${fwcmd} add 65000 deny log tcp from any to any # ${fwcmd} add 65100 deny log udp from any to any # Everything else is denied by default, unless the # IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel # config file.