#!/bin/sh
IPF="ipfw -q add"
#network interface
oif="em1"
ipfw -q -f flush
ipfw table all flush
myip="123.123.123.123"
#loopback, localhost stuff
$IPF 10 allow ip from any to any via lo0
$IPF 11 deny ip from any to 127.0.0.0/8
$IPF 12 deny ip from 127.0.0.0/8 to any
$IPF 13 deny tcp from any to any frag
#deny bogus poackets by tcpflags
#xmas tree
$IPF 30 deny tcp from any to any in tcpflags fin,psh,urg recv $oif
$IPF 31 deny tcp from any to any in tcpflags !fin,!syn,!rst,!psh,!ack,!urg recv $oif
$IPF 32 deny tcp from any to any in tcpflags syn,fin recv $oif
$IPF 33 deny tcp from any to any in tcpflags fin,rst recv $oif
$IPF 34 deny ip from any to any in ipoptions ssrr,lsrr,rr,ts recv $oif
#block bad ips by tables
#########################
ipfw table 1 flush
cat /usr/local/etc/block_ip.txt | while read ip; do
ipfw table 1 add $ip 1
done
ipfw -q add 100 deny ip from "table(1)" to any via $oif
#allow ftp
$IPF 42 allow tcp from $myip to me 21
$IPF 49 deny tcp from any to any 21
#allow ssh
$IPF 51 allow tcp from $myip to me 22
$IPF 59 deny tcp from any to any 22
#allow mysql
$IPF 61 allow tcp from me to me 3306
$IPF 62 allow tcp from $myip to me 3306
$IPF 69 deny tcp from any to any 3306
#$IPF 207 allow tcp from any to any 25 in
#$IPF 208 allow tcp from any to any 25 out
$IPF 89 deny tcp from any to any 25
$IPF 209 allow udp from any to any 53 in
$IPF 210 allow tcp from any to any 53 in
$IPF 211 allow udp from any to any 53 out
$IPF 212 allow tcp from any to any 53 out
$IPF 213 allow tcp from any to any 80 in
$IPF 214 allow tcp from any to any 80 out
#$IPF 215 allow tcp from any to any 10000 in
#$IPF 216 allow tcp from any to any 10000 out
#$IPF 219 allow tcp from any to any 11211 in
#$IPF 220 allow tcp from any to any 11211 out
#$IPF 300 divert natd all from any to any via $oif
#all connections from my network allowed
$IPF 500 check-state
$IPF 501 allow all from any to any keep-state
$IPF 502 deny tcp from any to any established in via $oif
$IPF 503 deny all from any to any frag in via $oif
#ack scan
$IPF 1000 deny tcp from any to any in tcpflags ack,rst recv $oif
# deny and log everything
$IPF 3000 deny log all from any to any