Strange but it stopped working since I upgraded to FreeBSD 9.0.........
I'm about to setup a new box with FreeBSD 9 and I'm wondering if you did anything to get this to work?
Strange but it stopped working since I upgraded to FreeBSD 9.0.........
mmx, I decided to go with FreeBSD 8.3 because 9.0 is still beta for directadmin and I need to have a stable system.
I did implement your guide and it's working like a charm. Thumbs up!
#!/bin/sh
set -e
/sbin/sysctl net.inet.ip.forwarding=0 >/dev/null
/sbin/ipfw -q list >/dev/null 2>&1 || /sbin/kldload ipfw
(/sbin/ipf -D) >/dev/null 2>&1 || true
(/sbin/kldunload ipl) >/dev/null 2>&1 || true
(/sbin/pfctl -d) >/dev/null 2>&1 || true
(/sbin/kldunload pf) >/dev/null 2>&1 || true
/sbin/ipfw -q /dev/stdin << EOF
flush
add allow ip from any to any via lo0
add check-state
add reset tcp from any to any established
add allow tcp from any to any 80 setup in keep-state
add allow tcp from any to any 20 in setup keep-state
add allow udp from any to any 20 in setup keep-state
add allow tcp from any to any 21 in setup keep-state
add allow udp from any to any 21 in setup keep-state
add allow tcp from any to any 25 in setup keep-state
add allow udp from any to any 53 in keep-state
add allow tcp from any to any 53 in keep-state
add allow tcp from any to any 443 in setup keep-state
add allow tcp from any to any 110 in setup keep-state
add allow tcp from any to any 143 in setup keep-state
add allow tcp from any to any 587 in setup keep-state
add allow tcp from any to any 465 in setup keep-state
add allow tcp from any to any 2222 in setup keep-state
add allow tcp from any to me 3306 in setup keep-state
add allow tcp from any to any 49152-65535 in setup keep-state
#blacklists - HERE I BLOCK BAD IP's
add deny tcp from xxx.xxx.xxx.xxx to me
#whitelists - HERE I WHITELIST IP's with SSH access allowed
add allow tcp from yyy.yyy.yyy.0:255.255.255.0 to me 22 setup in keep-state
#after whitelists
add allow icmp from any to me icmptypes 8 in keep-state
add deny tcp from any to me setup in
add deny ip from any to me in
add allow tcp from me to any setup out keep-state
add allow ip from me to any out keep-state
add deny tcp from any to any setup
add deny ip from any to any
enable firewall
EOF
/sbin/sysctl net.inet.ip.forwarding=1 >/dev/null
/sbin/sysctl net.inet.ip.fw.dyn_ack_lifetime=3600 >/dev/null
/etc: ipfw table 10 list
12.40.5.162/32 0
24.106.41.206/32 0
24.173.170.242/32 0
37.0.121.152/32 0
37.59.180.250/32 0
37.220.1.62/32 0
38.100.55.66/32 0
... // and many more!
Do you mean the "#blacklists" part? It definitely blocks the IP's - it stops the bruteforces..
ipfw show
/: ipfw show
00100 944289 180560852 allow ip from any to any via lo0
00200 0 0 check-state
00300 362096 17362185 reset tcp from any to any established
00400 23176100 14339787330 allow tcp from any to any dst-port 80 setup in keep-state
00500 0 0 allow tcp from any to any dst-port 20 in setup keep-state
00600 0 0 allow udp from any to any dst-port 20 in setup keep-state
00700 126998 7915283 allow tcp from any to any dst-port 21 in setup keep-state
00800 0 0 allow udp from any to any dst-port 21 in setup keep-state
00900 1546306 1029837660 allow tcp from any to any dst-port 25 in setup keep-state
01000 316135 34866264 allow udp from any to any dst-port 53 in keep-state
01100 43 1956 allow tcp from any to any dst-port 53 in keep-state
01200 10850 3484004 allow tcp from any to any dst-port 443 in setup keep-state
01300 2280887 1908975288 allow tcp from any to any dst-port 110 in setup keep-state
01400 505216 334063810 allow tcp from any to any dst-port 143 in setup keep-state
01500 86277 56218084 allow tcp from any to any dst-port 587 in setup keep-state
01600 109 16896 allow tcp from any to any dst-port 465 in setup keep-state
01700 7618 3779048 allow tcp from any to any dst-port 2222 in setup keep-state
01800 17317 911899 allow tcp from any to me dst-port 3306 in setup keep-state
01900 233728 150655723 allow tcp from any to any dst-port 49152-65535 in setup keep-state
02000 0 0 deny tcp from 61.235.113.205 to me
02100 185292 22501732 allow tcp from 212.36.25.0/24 to me dst-port 22 setup in keep-state
02200 0 0 allow tcp from 82.137.72.0/24 to me dst-port 22 setup in keep-state
02300 0 0 allow tcp from 85.130.22.0/24 to me dst-port 22 setup in keep-state
02400 0 0 allow tcp from 85.130.5.70 to me dst-port 22 setup in keep-state
02500 0 0 allow tcp from 85.130.15.30 to me dst-port 22 setup in keep-state
02600 0 0 allow tcp from 91.193.156.234 to me dst-port 22 setup in keep-state
02700 0 0 allow tcp from 217.174.50.96 to me dst-port 22 setup in keep-state
02800 0 0 allow tcp from 217.174.49.188 to me dst-port 22 setup in keep-state
02900 0 0 allow tcp from 194.0.235.0/24 to me dst-port 22 setup in keep-state
03000 0 0 allow tcp from 81.161.240.0/24 to me dst-port 22 setup in keep-state
03100 0 0 allow tcp from 81.161.245.0/24 to me dst-port 22 setup in keep-state
03200 4494 263266 allow icmp from any to me icmptypes 8 in keep-state
03300 10307 453564 deny tcp from any to me setup in
03400 7239 1595286 deny ip from any to me in
03500 1651276 754499630 allow tcp from me to any setup out keep-state
03600 93311 17946689 allow ip from me to any out keep-state
03700 1392 60532 deny tcp from any to any setup
03800 218 46446 deny ip from any to any
65535 0 0 deny ip from any to any
add deny tcp from xxx.xxx.xxx.xxx to me
/etc: ipfw table 10 list
12.40.5.162/32 0
24.106.41.206/32 0
24.173.170.242/32 0
37.0.121.152/32 0
37.59.180.250/32 0
37.220.1.62/32 0
38.100.55.66/32 0
... // and many more!
When a packet enters the firewall it is compared against the first rule in the ruleset and progresses one rule at a time moving from top to bottom of the set in ascending rule number sequence order. When the packet matches the selection parameters of a rule, the rules' action field value is executed and the search of the ruleset terminates for that packet. This is referred to as “the first match wins” search method. If the packet does not match any of the rules, it gets caught by the mandatory IPFW default rule, number 65535 which denies all packets and discards them without any reply back to the originating destination.
add allow tcp from any to any 20 in setup keep-state
add allow udp from any to any 20 in setup keep-state
add allow tcp from any to any 21 in setup keep-state
add allow udp from any to any 21 in setup keep-state
add allow tcp from any to any 25 in setup keep-state
add allow tcp from any to any 110 in setup keep-state
add allow tcp from any to any 143 in setup keep-state
add allow tcp from any to any 587 in setup keep-state
add allow tcp from any to any 465 in setup keep-state
add allow tcp from any to any 2222 in setup keep-state
ipfw -d list | wc -l
4676
netstat -anf inet | grep FIN_WAIT | wc -l
8541
Apr/01/2013 01:07:02 proto TCP (ACK), xx.xx.xx.xx->yy.yy.yyy.yy:50572, len 52
Apr/01/2013 01:07:02 proto TCP (ACK), xx.xx.xx.xx->yy.yy.yyy.yy:50567, len 52
Apr/01/2013 01:07:02 proto TCP (ACK), xx.xx.xx.xx->yy.yy.yyy.yy:50602, len 40
Apr/01/2013 01:07:02 proto TCP (ACK), xx.xx.xx.xx->yy.yy.yyy.yy:50597, len 40
Apr/01/2013 01:07:02 proto TCP (ACK), xx.xx.xx.xx->yy.yy.yyy.yy:50602, len 52
sysctl net.inet.tcp.fast_finwait2_recycle=1
>ipfw -d list | wc -l
133
>netstat -anf inet | grep FIN_WAIT | wc -l
28