|
利用FreeBSD组建安全的网关(2)
options ICMP_BANDLIM //ICMP_BANDLIM根据带宽限制产生icmp错误。一般情况下我们需要这个选项,它有助于你的系统免受D.O.S.攻击。
把以上参数加入以后保存kernel_IPFW文件。
make depend
cd ../../compile/kernel_IPFW
make
make install
(注意!!!!!请不要使用远程方式来设置服务器!为什么?等下你就能知道了。)
以上完成以后,你就可以重新启动系统使用新的内核了。
使用新内核以后,如果该系统本来是连在网络上的,那么这时他的网络部分已经完全丧失,这表示系统新的内核已经起作用了,防火墙也起作用了,但由于FreeBSD的防火墙默认情况下是不允许任何机器访问,所以该机器的任何网络功能都暂时丧失。不过不要着急,接着往下看,你就会觉得非常有意思了。
既然该服务器担当是的网关,那么让网关启动起来是必须的。我们现在再:
cd /etc
用编译器编译rc.conf
加入如下参数:
gateway_enable="YES" //启动网关
##########IP-firewall#################
firewall_enable="YES" //激活firewall防火墙
firewall_script="/etc/rc.firewall" //firewall防火墙的默认脚本
firewall_type="/etc/ipfw.conf" //firewall自定义脚本
firewall_quiet="NO" //起用脚本时,是否显示规则信息。现在为“NO”假如你的防火墙脚本已经定型,那么就可以把这里设置成“YES”了。
firewall_logging_enable="YES" //启用firewall的log记录。
##########NATD#######################
natd_interface="xl0" //NATD服务启用在哪块网卡。
natd_enable="YES" //激活NATD服务
natd_flags="-config /etc/natd.conf" //NATD服务参数设置文件。
设置完成后我们再编译/etc/syslog.conf文件。
加入以下行:
!ipfw
*.* /var/log/ipfw.log
好了rc.conf文件设置完毕,然后就是其他文件了。
新建/etc/ipfw.conf 文件,在文件里写入以下内容:
add 00400 divert natd ip from any to any via xl0 //natd服务启动设置
add 00001 deny log ip from any to any ipopt rr
add 00002 deny log ip from any to any ipopt ts
add 00003 deny log ip from any to any ipopt ssrr
add 00004 deny log ip from any to any ipopt lsrr
add 00005 deny tcp from any to any in tcpflags syn,fin //这5行是过滤各种扫描包
|