庞大资源库的计算机教程网站!
设为首页
加入收藏
总编信箱
投稿或申请专栏请先 [登 陆]
首页 操作系统 程序设计 图形图像 媒体动画 机械电子 WEB开发 数 据 库 办公系列 路由技术 网络原理 网络应用
认证考试 安全技术
首页>操作系统>FreeBSD>应用技术>正文
资料搜索
Google搜索
Google
返回上级列表

推荐文章

快速保存网页中所有图片的方法
Windows中让光驱巧妙“隐身”技
防范非法用户入侵Win 2000/XP系
两款比较典型的ASP木马防范方法
有关表格边框的css语法整理
Windows XP中可以被禁用的服务
SQL Server导出导入数据方法
Javascript所有对象的属性的获
网页(HTML)中的特殊字符
与篮球共舞,尽显模式本色
QQ病毒的手工清除方法
Photoshop为极品美女打造性感睫
天衣无缝:IIS与PHP水火也相容
SQL Server存储过程编写和优化

FreeBSD ipfw 防火墙基础指南

 作者:本站收集   日期:2005-3-13
字号选择〖 〗/ 双击滚屏 单击停止   
一、内核配置
/usr/src/sys/i386/conf/HQ_SuperServer

[code:1:66aaf20915]options IPFIREWALL
options IPFIREWALL_DEFAULT_TO_ACCEPT
options IPDIVERT # IPDIVERT enables the divert IP sockets, used by ''ipfw divert''
options IPFIREWALL_VERBOSE
options IPFIREWALL_VERBOSE_LIMIT=30

#options IPFILTER #ipfilter support
#options IPFILTER_LOG #ipfilter logging

# traffic shaper, bandwidth manager and delay emulator
options DUMMYNET # enables the "dummynet" bandwidth limiter. You need IPFIREWALL as well.
# Statically Link in accept filters for a web server on this box
options ACCEPT_FILTER_DATA
options ACCEPT_FILTER_HTTP
options ICMP_BANDLIM # D.O.S. protection
options IPSTEALTH #To hide firewall from traceroute
options TCP_DROP_SYNFIN #To hide from nmap OS fingerprint, remove if create web server[/code:1:66aaf20915]

 

二、rc.conf配置
/etc/rc.conf

[code:1:66aaf20915]firewall_enable="YES"
firewall_logging="YES"
firewall_script="/etc/rc.firewall"
firewall_quiet="NO" #change to YES once happy with rules
firewall_logging_enable="YES"

#extra firewalling options
log_in_vain="YES"
#This option prevents something known as OS fingerprinting, must have TCP_DROP_SYNFIN compiled into kernel to use
tcp_drop_synfin="NO" #change to NO if create webserver
tcp_restrict_rst="YES"
icmp_drop_redirect="YES"[/code:1:66aaf20915]

三、ipfw使用

[code:1:66aaf20915]ipfw add allow tcp from to in recv [/code:1:66aaf20915]

添加和除去规则例子:
[code:1:66aaf20915]$ sudo ipfw add deny tcp from 61.49.203.115 to 61.49.203.114 22 in recv fxp0
$ sudo ipfw -t list
$ sudo ipfw delete 00100[/code:1:66aaf20915]

禁止icmp
[code:1:66aaf20915]$ sudo ipfw add deny icmp from any to any in recv fxp0[/code:1:66aaf20915]

显示rules
[code:1:66aaf20915]$ sudo ipfw show[/code:1:66aaf20915]

按照序号显示规则
[code:1:66aaf20915]$ sudo ipfw -t list[/code:1:66aaf20915]

列出信息包的数目,和与它们相对应的规则匹配
[code:1:66aaf20915]$ sudo ipfw -a list[/code:1:66aaf20915]

四、/etc/ipfw.rules规则文件
[code:1:66aaf20915]allow 00010 udp from any to me 67 in via $iif
allow 00020 udp from me 68 to any out via $iif[/code:1:66aaf20915]

五、/etc/rc.firewall脚本

[code:1:66aaf20915]# mv /etc/rc.firewall /etc/rc.firewall.orig
# touch /etc/rc.firewall
# chmod u=+rx,og=-rwx /etc/ipfw.rules[/code:1:66aaf20915]

/etc/rc.firewall

[code:1:66aaf20915]#!/bin/sh

# This will flush the existing rules - sudo ipfw -f flush
# You can execute this script without dropping existing connections/states

fwcmd="/sbin/ipfw -q"
extif="fxp0"
myip="10.1.8.114"
mybcast="10.1.8.119"
mynetwork="10.1.8.112/29"
dns_server="10.1.8.1"

# Reset all rules in case script run multiple times
${fwcmd} -f flush

${fwcmd} add 200 check-state

# Block RFC 1918 networks - the , syntax only works in ipfw2
${fwcmd} add 210 deny all from 0.0.0.0/7,1.0.0.0/8,2.0.0.0/8,5.0.0.0/8,10.0.0.0/8,23.0.0.0/8,\
27.0.0.0/8,31.0.0.0/8,67.0.0.0/8,68.0.0.0/6,72.0.0.0/5,80.0.0.0/4,96.0.0.0/3,127.0.0.0/8,\
128.0.0.0/16,128.66.0.0/16,169.254.0.0/16,172.16.0.0/12,191.255.0.0/16,192.0.0.0/16,\
192.168.0.0/16,197.0.0.0/8,201.0.0.0/8,204.152.64.0/23,224.0.0.0/3,240.0.0.0/8 to any

# Allow all via loopback to loopback
${fwcmd} add 220 allow all from any to any via lo0

# Allow from me to anywhere
${fwcmd} add 240 allow tcp from ${myip} to any setup keep-state
${fwcmd} add 260 allow udp from ${myip} to any keep-state
${fwcmd} add 280 allow icmp from ${myip} to any

# Allow local LAN to connect to us
${fwcmd} add 300 allow ip from ${mynetwork} to ${mynetwork}

# Allow INCOMING SSH,SMTP,HTTP from anywhere on the internet
${fwcmd} add 320 allow log tcp from any to ${myip} 22,25,80 in keep-state setup

# Disable icmp
${fwcmd} add 340 allow icmp from any to any icmptype 0,3,11

# Block all other traffic and log in
${fwcmd} add 360 deny log all from any to any

# End of /etc/rc.firewall[/code:1:66aaf20915]

 

六、 ipfw日志纪录配置

/etc/syslog.conf
[code:1:66aaf20915]!ipfw
*.* /var/log/ipfw.log[/code:1:66aaf20915]

[code:1:66aaf20915]$ sudo touch /var/log/ipfw.log
$ sudo killall -HUP syslogd[/code:1:66aaf20915]

上一篇:FreeBSD Shared object "libintl.so.4"或(libc.so.4) not found    下一篇:FreeBSD 如何使用ssmtp提交你的port  
[发送给好友]  [关闭窗口]  [返回顶部]   转载请注明来源:www.it00.com   
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
责任编辑: 原点 投稿作者: 本站收集
信息来源: 网络 录入时间: 2005-3-13
关于我们 - 广告服务 - 版权申明 - 网站地图 - 联系方式 - 总编信箱 - 会员投稿