Linux 版 (精华区)

发信人: lanken (os), 信区: Linux
标  题: 为Apache HTTP 1.3.3 Server设定一个简单防火墙策略 
发信站: 哈工大紫丁香 (Tue Feb  8 20:21:21 2005), 转信

为Apache HTTP 1.3.3 Server设定一个简单防火墙策略 

发布日期: 2005-02-01 00:07

赵珂
http://zhaoke.net


目录:
一. 设定防火墙策略
二. 设定脚本权限和运行脚本
三. 确认是否实施防火墙策略
四. 创建服务文件
五. 设定服务文件执行权限并添加到系统自动启动服务列表中
六. 更多


现在已经在Red Hat 9系统上成功的安装了Apache HTTP Server 1.3.3, 
接下来对防火墙进行一个简单设定, 允许HTTP和HTTPS访问Web服务器.

一. 设定防火墙策略
如果你没有设定HTTP访问80端口和HTTPS访问443端口, 你需要做如下
的设置. 添加下面的内容到防火墙控制脚本/usr/local/etc/firewall的
端口访问部分:

#Allow incoming HTTP requests (to Web Server)
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

如果你没有运行SSL服务器, 可以简单的通过在第三行前添加注释符号(#).


二. 设定脚本权限和运行脚本
#chmod +x firewall
#/usr/local/etc/firewall


三. 确认是否实施防火墙策略
运行iptables -L确认HTTP和HTTPS端口是否已经打开. 下面是正确的
iptables输出信息(最后两行):

ACCEPT icmp -- anywhere anyhere state ESTABLISHED
ACCEPT tcp -- anywhere anywhere state ESTABLISHED
ACCEPT udp -- anywhere anywhere state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:smtp
ACCEPT tcp -- anywhere anywhere tcp dpt:pop3

ACCEPT tcp -- anywhere anywhere tcp dpt:imap
ACCEPT tcp -- anywhere anywhere tcp dpt:domain
ACCEPT udp -- anywhere anywhere udp dpt:domain
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:https


四. 创建服务文件
#vi /etc/init.d/firewall

---拷贝下面区域内容然后张贴到firewall中--

#!/bin/sh
#
# This script is responsible for loading the custom
# IPTables Firewall settings.
#
# chkconfig: 345 96 96
#
# processname: /usr/local/etc/firewall
#
# description: Controls the custom built firewall rules
#
# Source function library:
. /etc/init.d/functions
RETVAL=0
start () {
echo "Loading Firewall Rules: "
/usr/local/etc/firewall > /dev/null
touch /var/lock/subsys/firewall
RETVAL=$?
[ $RETVAL -eq 0 ] && success || failure
echo -n "Status:"
echo
return $RETVAL
}
flush () {
echo -n "Turning Firewall Off"
iptables -F
rm -rf /var/lock/subsys/firewall
RETVAL=$?
[ $RETVAL -eq 0 ] && success || failure
echo
return $RETVAL
}
status () {
echo "Current Firewall Configuration:"
RETVAL=$?
iptables -L
return $RETVAL
}
panic () {
echo "Enabling Panic Mode. Only SSH access allowed!!"
echo -n "You must run '$0 start' to allow other ports "
echo " through the firewall again."
echo -n "Panic Mode Status:"
/sbin/iptables -F
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -j DROP
[ $RETVAL -eq 0 ] && success || failure
echo
return $RETVAL
}
case "$1" in
start)
start
;;
restart)
start
;;
flush)
flush
;;
stop)
flush
;;
status)
status
;;
list)
status
;;
panic)
panic
;;
*)
echo "Usage:$0 {start|stop|restart|flush|status|list|panic}"
exit 1
esac
exit $RETVAL

------------------结束----------------------


五. 设定服务文件执行权限并添加到系统自动启动服务列表中
#chmod 700 /etc/init.d/firewall
#chkconfig --add firewall
service firewall restart


六. 更多

关于作者: 赵珂, 操作系统研究和安全工程师. 
zhaoke.net是作者的个人网站. 欢迎技术交流以及链接交换.

原文出处: http://zhaoke.net/articles/general/2005-02-01.shtml

版权声明: 引用或转载, 请注明作者与出处. 并请保留本文的连接. 

如有问题或错误请提交到: http://zhaoke.net/cn/contact.shtml


--
Ke Zhao, http://zhaoke.net


※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 61.48.104.118]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.291毫秒