Thứ năm, ngày 29 tháng mười hai năm 2011

Compile kernel IPFW (FreeBSD 8.2)

Kiểm tra xem ipfw có compilte vào kernel hay không
# ipfw list

Nếu xuất hiện thông báo như sau ipfw: getsockopt(IP_FW_GET): Protocol not available thì bạn cần làm những bước sau
- Sử dụng sysinstall để cài đặt src (chọn Configure chọn mục Distributions chọn src trong phần src chọn All)

- Sau khi đợi nó cài đặt xong, kiểm tra xem thư mục /usr/src xem có tập tin binary xuất hiện ở trong đường dẫn này hay không
master# grep IPFIREWALL /usr/src/sys/i386/conf (tùy thuộc vào kiến trúc mà bạn chọn loại thích hợp có thể là i386, amd64, ia64, powerpc, sparc64 hoặc pc98)

master# cd /usr/src/sys/i386/conf
master# cp GENERIC IPFWKERNEL

master# vi IPFWKERNEL
Thêm vào các dòng sau
options IPFIREWALL # required for IPFW
options IPFIREWALL_VERBOSE # optional; logging
options IPFIREWALL_VERBOSE_LIMIT=10 # optional; don't get too many log entries
options IPDIVERT # needed for natd


Bắt đầu thực thi
master# cd /usr/src
master# make buildkernel KERNCONF=IPFWKERNEL

Sau khi đợi nó compile xong , bạn
master # vi /etc/rc.conf

Thêm vào các dòng sau :
firewall_enable="YES"
firewall_script="/usr/local/etc/ipfw.rules"

Bgây iờ bắt đầu viết rule Firewall đầu tiên trên FreeBSD

# vi /usr/local/etc/ipfw.rules
IPF="ipfw -q add"
ipfw -q -f flush
#loopback
$IPF 10 allow all from any to any via lo0
$IPF 20 deny all from any to 127.0.0.0/8
$IPF 30 deny all from 127.0.0.0/8 to any
$IPF 40 deny tcp from any to any frag
# statefull
$IPF 50 check-state
$IPF 60 allow tcp from any to any established
$IPF 70 allow all from any to any out keep-state
$IPF 80 allow icmp from any to any
# open port ftp (20,21), ssh (22), mail (25)
# http (80), dns (53) etc
$IPF 110 allow tcp from any to any 21 in
$IPF 120 allow tcp from any to any 21 out
$IPF 130 allow tcp from any to any 22 in
$IPF 140 allow tcp from any to any 22 out
$IPF 150 allow tcp from any to any 25 in
$IPF 160 allow tcp from any to any 25 out
$IPF 170 allow udp from any to any 53 in
$IPF 175 allow tcp from any to any 53 in
$IPF 180 allow udp from any to any 53 out
$IPF 185 allow tcp from any to any 53 out
$IPF 200 allow tcp from any to any 80 in
$IPF 210 allow tcp from any to any 80 out
# deny and log everything
$IPF 500 deny log all from any to any
# sh /usr/local/etc/ipfw.rules

Để kiểm tra các rules chạy
# ipfw list

Tham khảo từ

0 nhận xét: