ipfw防火墙配置记录
来源:岁月联盟
时间:2010-02-09
ipfw是BSD系统中重要的防火墙和通信控制工具,在MacOSX中也很好用。先简单贴几个用法,有空再补上:
列出配置表
Java代码
- ipfw list
ipfw list
禁用ping,即ICMP协议
Java代码
- ipfw add 3333 deny icmp from any to any via en0
ipfw add 3333 deny icmp from any to any via en0
取消,则用
Java代码
- ipfw del 3333
ipfw del 3333
* 续
ipfw重启之后就失效了,为了使每次开机都有效,需要加入到启动服务器中,下面是MacOSX下的一个配置例子:
1. 将ipfw规则写入自定的配置文件,例如/etc/rc.firewall
Java代码
- #!/bin/sh
- IPFW='/sbin/ipfw -q'
- $IPFW -f flush
- $IPFW add 2000 allow ip from any to any via lo*
- $IPFW add 2010 deny log ip from 127.0.0.0/8 to any in
- $IPFW add 2020 deny log ip from any to 127.0.0.0/8 in
- $IPFW add 2030 deny log ip from 224.0.0.0/3 to any in
- $IPFW add 2040 deny log tcp from any to 224.0.0.0/3 in
- $IPFW add 2050 allow log tcp from any to any out
- $IPFW add 2060 allow log tcp from any to any established
- $IPFW add 2070 allow log tcp from any to any 22 in
- $IPFW add 2080 allow log tcp from any to any 80 in
- $IPFW add 2090 allow log tcp from any to any 427 in
- $IPFW add 12190 deny log tcp from any to any
#!/bin/shIPFW='/sbin/ipfw -q'$IPFW -f flush$IPFW add 2000 allow ip from any to any via lo*$IPFW add 2010 deny log ip from 127.0.0.0/8 to any in$IPFW add 2020 deny log ip from any to 127.0.0.0/8 in$IPFW add 2030 deny log ip from 224.0.0.0/3 to any in$IPFW add 2040 deny log tcp from any to 224.0.0.0/3 in$IPFW add 2050 allow log tcp from any to any out$IPFW add 2060 allow log tcp from any to any established$IPFW add 2070 allow log tcp from any to any 22 in$IPFW add 2080 allow log tcp from any to any 80 in$IPFW add 2090 allow log tcp from any to any 427 in$IPFW add 12190 deny log tcp from any to any
以上配置规则适合个人web服务器管理,并开启远程ssh登录管理端口。摘自:
http://www.macdevcenter.com/pub/a/mac/2005/03/15/firewall.html
2. 建立目录/Library/StartupItems/Firewall,并在Firewall中创建两个文件:Firewall和StartupParameters.plist。设置属性:
Java代码
- chmod ug+x Firewall StartupParameters.plist
chmod ug+x Firewall StartupParameters.plist
Firewall脚本内容如下:
Java代码
- . /etc/rc.common
- StartService ()
- {
- if [ "${FIREWALL:=-NO-}" = "-YES-" ]
- then
- ConsoleMessage "Starting Firewall"
- sh /etc/rc.firewall > /dev/null
- fi
- }
- StopService ()
- {
- ConsoleMessage "Stopping Firewall"
- /sbin/ipfw -f -q flush
- }
- RestartService ()
- {
- StopService
- StartService
- }
- RunService "${1:-start}" #默认参数为-start
. /etc/rc.commonStartService (){ if [ "${FIREWALL:=-NO-}" = "-YES-" ] then ConsoleMessage "Starting Firewall" sh /etc/rc.firewall > /dev/null fi}StopService (){ ConsoleMessage "Stopping Firewall" /sbin/ipfw -f -q flush}RestartService (){ StopService StartService}RunService "${1:-start}" #默认参数为-start
StartupParameters.plist配置内容如下:
Java代码
- {
- Description = "Firewall";
- Provides = ("Firewall");
- Requires = ("Network");
- OrderPreference = "None";
- Messages =
- {
- start = "Starting NAT/Firewall";
- stop = "Stopping NAT/Firewall";
- };
- }
{Description = "Firewall";Provides = ("Firewall");Requires = ("Network");OrderPreference = "None";Messages = { start = "Starting NAT/Firewall"; stop = "Stopping NAT/Firewall"; };}
3. 设置/etc/hostconfig,在最底下增加一行:
Java代码
- FIREWALL=-YES-
FIREWALL=-YES-
使/Library/StartupItems/Firewall/Firewall的启动脚本能执行启动ipfw服务。
4. 测试
Java代码
- /Library/StartupItems/Firewall/Firewall start
转自: http://willzh.javaeye.com/blog/252362
上一篇:ipfw配置
下一篇:FreeBSD对硬盘容量的要求