如何设定防火墙IP Firewall

2005-03-28 10:35:42  作者
IPFirewall可以有效的增进系统的安全,但是除非你对IPFirewall有
相当的了解,否则你可能把你的机器弄的无法上网路。

警告!!绝对不要从远端连线设定IPFW,一定要从console!!
不然设定错误,你的连线可能会被中断!!

你必须在kernelconfigfile中加入optionsIPFIREWALL及options
IPFIREWALL_VERBOSE,再重新编译kernel。

在你开始以前,请先manipfw。

1.编辑/etc/sysconfig,把firewall=NO改成firewall=YES
2.修改/etc/rc.firewall
你可以参照里面的□例,假如看不懂的话,请manipfw
以下是一个简单的例子

echo"IPFirewallRules...."
#truetoenable,falsetodisable

iftrue;then
#basicinformation
net="140.113.139.0"
mask="255.255.255.0"
mask_b="255.255.0.0"
myip="140.113.139.1"

#flushallrules
#FreeBSD-2.21996/Sep以後的版本,请使用ipfw-fflush(见後PS)
/sbin/ipfwflush

#Allowallconnectionsatlast
#IPFWdefaultrule:"65535denyallfromanytoany"
/sbin/ipfwadd65000passallfromanytoany

#Allowallconnections(thelatestmatch65000)本行最後才match!
/sbin/ipfwadd65000passallfromanytoany

#Allowalllocalhostconnections(firstmatch)本行最先match!
/sbin/ipfwadd1000passallfrom127.0.0.1to127.0.0.1
/sbin/ipfwadd1010passallfrom${myip}toa

#Friendlysites(fullyaccessrights)
#这些host最好用IP,或是要纪录在/etc/hosts中
/sbin/ipfwadd1100passallfromFriend1toany
/sbin/ipfwadd1120passallfromServertoany
/sbin/ipfwadd1130passallfromFreeBSD.csie.nctu.edu.twtoany

#denyeverything(assholehost)
/sbin/ipfwadd2000denyallfrom123.123.123.123:${mask}toany

#denyremotesysloggingtogetrideofsecurityproblem
/sbin/ipfwadd3000denyudpfromanytoany514

#denyusersoutofcampusfromdoing"rusers","rwall"
/sbin/ipfwadd4000passudpfrom${net}:${mask_b}toany1034,1035
/sbin/ipfwadd4010denyudpfromanytoany1034,1035

#denymosthostsfromtcpsprayme
/sbin/ipfwadd5000denytcpfromanytoany9
/sbin/ipfwadd5010denyudpfromanytoany9
fi

3.执行sh/etc/rc.firewall,然後测试各种网路连线看看

後记
IPFW一启动後,内定是『拒绝所有连线』!!!
(IPFW内定rule:65535denyallfromanytoany)
这点要非凡注重,因此假如你下了ipfwflush指令,你马上跟网路隔绝,
连localhost也无法连接。
因此通常我们会在最後一个rule(如65534)答应所有连线,然後把deny
的rules都放在前面。

假如你在系统启动之後修改了/etc/rc.firewall,只要用
sh/etc/rc.firewall就可以载入新的rules。
假如你在远端控制,要注重新加的rule不要把自己给ban掉了啊。

PS.在1996/Sep以後的ipfw在执行ipfwflush时会询问使用者以求
确认(因为ipfwflush会导致连线中断),因此你在撰写/etc/
rc.firewall时请使用ipfw-fflush。
你可以打ipfw-h看看你的ipfw有没有支援-f的选项
相关文章