bsd ipfw配置方法

ipfw的配置命令:
ipfw [-N] 命令 [编号] 动作 [log(日志)] 协议 地址 [其它选项] 例如:
# ipfw add allow tcp from any to 10.10.10.1 80 #允许外界访问我的web服务
# ipfw add allow tcp from any to 10.10.10.1 21 #允许外面访问我的ftp服务
# ipfw add allow tcp from any to 10.10.10.1 22 #允许外界访问我的ssh服务 如果使用规则包的形式,那么查看下面内容。

系统启动后,我们还要配置rc.conf文件来运行我们的防火墙:
# ee /etc/rc.conf 加入如下内容:
gateway_enable="YES" # 启动网关
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记录。

设置完成后我们再编辑/etc/syslog.conf文件:
# ee /etc/syslog.conf 加入以下行:
!ipfw *.* /var/log/ipfw.log
现在到了最重要的编辑规则包了:
# ee /etc/ipfw.conf 我们添加一下规则:(注意 10.10.10.1是我们服务器的IP)

######### TCP ##########
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行是过滤各种扫描包
add 10001 allow tcp from any to 10.10.10.1 80 in # 向整个Internet开放http服务。
add 10002 allow tcp from any to 10.10.10.1 21 in # 向整个Internet开放ftp服务。
add 10000 allow tcp from 1.2.3.4 to 10.10.10.1 22 in # 向Internet的xx.xx.xx.xx这个IP开放SSH服务。也就是只信任这个IP的SSH登陆。

# 如果你登陆服务器的IP不固定,那么就要设为:
add 10000 allow tcp from any to 10.10.10.1 22 in
add 19997 check-state add 19998 allow tcp from any to any out keep-state setup
add 19999 allow tcp from any to any out #这三个组合起来是允许内部网络访问出去,如果想服务器自己不和Internet进行tcp连接出去,可以把19997和19998去掉。(不影响Internet对服务器的访问)

########## UDP ##########
add 20001 allow udp from any 53 to 10.10.10.1 # 允许其他DNS服务器的信息进入该服务器,因为自己要进行DNS解析嘛~
add 29999 allow udp from any to any out # 允许自己的UDP包往外发送。

########## ICMP #########
add 30000 allow icmp from any to any icmptypes 3
add 30001 allow icmp from any to any icmptypes 4
add 30002 allow icmp from any to any icmptypes 8 out
add 30003 allow icmp from any to any icmptypes 0 in
add 30004 allow icmp from any to any icmptypes 11 in #允许自己ping别人的服务器。也允许内部网络用router命令进行路由跟踪。
 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值