ขั้นแรกก็ทำการเช็คก่อนว่า เครื่องได้ติดตั้ง ipfw ไว้แล้วหรือยัง โดย
#ipfw list
ถ้ายังไม่ได้ติดตั้งจะฟ้องว่า
ipfw: getsockopt(IP_FW_GET): Protocol not available
ถ้าเป็นแบบนี้ก็เริ่มกันเลย
ก่อนอื่นก็
# cd /usr/src/sys/i386/conf
# cp GENERIC FIREWALL
จากนั้นก็ทำการแก้ไขไฟล์
#vi /usr/src/sys/i386/conf/FIREWALL
แก้ไขบรรทัดต่อไปนี้
ident GENERIC
แก้เป็น
ident FIREWALL
แล้วเลื่อนลงไปด้านล่างสุด เพิ่มข้อความเหล่านี้ลงไป
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
save ซะ ต่อด้วยการ compile kernel
# cd /usr/src
# make buildkernel KERNCONF=FIREWALL
แล้วรอ…
จากนั้นก็ทำการ Install kernel
# make installkernel KERNCONF=FIREWALL
เสร็จแล้ว reboot เครื่องซะ
# init 6
พอเครื่อง boot เสร็จเข้าไปแก้ไขให้เรียก ipfw
# vi /etc/rc.conf
โดยเพิ่มบรรทัดเหล่านี้ลงไป
firewall_enable=”YES”
firewall_script=”/usr/local/etc/ipfw.rules”
จากนั้นก็สร้างไฟล์ rulse script ขึ้นมาโดย
# 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
เสร็จแล้วก็ เซฟซะ
ทีนี้ก็ start ipfw ซะโดยสั่งว่า
# sh /usr/local/etc/ipfw.rules
แล้วก็เช็คว่าทำงานหรือยังโดยสั่งว่า
# ipfw list
จบครับ ก๊อปเค้ามาแล้วเรียบเรียงใหม่ จาก http://www.cyberciti.biz/faq/howto-setup-freebsd-ipfw-firewall/
Related posts:







Twitter
Facebook
GooglePlus