EDU511 国际专业IT教育服务门户
设为首页   加入收藏    联系我们
寻找IT教育内容合作伙伴
招聘教育网络编辑和运营门户高手
中讯IT教育2008年改版上线
寻找地方站运营伙伴QQ:59955917
中讯IT 技术成就未来
   你现在的位置:首页 >> 新闻系统 >> 操作系统 >> FreeBSD >> FreeBSD高级教程 >> 正文

如何设定防火墙IP Firewall

 
 
日期:08-05-14 07:52:39 点击: 来源:中讯IT职业教育
 
IP Firewall 可以有效的增进系统的安全,但是除非你对 IP Firewall 有 
相当的了解,否则你可能把你的机器弄的无法上网路。 

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

你必须在 kernel config file 中加入 options IPFIREWALL 及 options 
IPFIREWALL_VERBOSE,再重新编译 kernel。 

在你开始以前,请先 man ipfw。 

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

echo "IP Firewall Rules ...." 
# true to enable, false to disable 
 
if true; then 
        # basic information 
        net="140.113.139.0" 
        mask="255.255.255.0" 
        mask_b="255.255.0.0" 
        myip="140.113.139.1" 
 
        # flush all rules 
        # FreeBSD-2.2 1996/Sep 以後的版本,请使用 ipfw -f flush (见後 PS) 
        /sbin/ipfw flush 
 
        # Allow all connections at last 
        # IPFW default rule : "65535 deny all from any to any" 
        /sbin/ipfw add 65000 pass all from any to any 
 
        # Allow all connections (the latest match 65000) 本行最後才 match ! 
        /sbin/ipfw add 65000 pass all from any to any 
 
        # Allow all localhost connections (first match) 本行最先 match ! 
        /sbin/ipfw add 1000 pass all from 127.0.0.1 to 127.0.0.1 
        /sbin/ipfw add 1010 pass all from ${myip} to a 
 
        # Friendly sites (fully access rights) 
        # 这些 host 最好用 IP,或是要纪录在 /etc/hosts 中 
        /sbin/ipfw add 1100 pass all from Friend1 to any 
        /sbin/ipfw add 1120 pass all from Server to any 
        /sbin/ipfw add 1130 pass all from FreeBSD.csie.nctu.edu.tw to any 
 
        # deny everything (asshole host) 
        /sbin/ipfw add 2000 deny all from 123.123.123.123:${mask} to any 
 
        # deny remote syslogging to get ride of security problem 
        /sbin/ipfw add 3000 deny udp from any to any 514 
 
        # deny users out of campus from doing "rusers", "rwall" 
        /sbin/ipfw add 4000 pass udp from ${net}:${mask_b} to any 1034,1035 
        /sbin/ipfw add 4010 deny udp from any to any 1034,1035 
 
        # deny most hosts from tcpspray me 
        /sbin/ipfw add 5000 deny tcp from any to any 9 
        /sbin/ipfw add 5010 deny udp from any to any 9 
fi 
 
3. 执行 sh /etc/rc.firewall,然後测试各种网路连线看看 

後记: 
IPFW 一启动後,内定是『拒绝所有连线』!!! 
(IPFW 内定 rule : 65535 deny all from any to any) 
这点要特别注意,因此如果你下了 ipfw flush 指令,你立刻跟网路隔绝, 
连 localhost 也无法连接。 
因此通常我们会在最後一个 rule (如 65534) 允许所有连线,然後把 deny 
的 rules 都放在前面。 

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

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

登录模块加载中...
热点操作系统技术
友情链接
重庆之窗 | 博学教育网 | 重庆IT教育 | 我爱论文网 | 涪陵课件园 | 中国教育导航 | 洪波物理教育 | 第一教育网 | 考试培训 | 职业培训
地址:重庆渝中区大坪正街88号 Copyright © edu511.com All rights reserved.
本站建设得到北京泰胜得风险投资机构、重庆网通信息港、平全教育服务中心与的大力支持            重庆视网科技发展有限公司版权所有 邮编:400041
电话:023-61630611 15902314551            ICP备案号:渝ICP备08002346号 QQ:59955917       邮箱:sysium_yuh@126.com yuhong@edu511.com