防火墙实用性模板

防火墙对于服务器的安全性相当重要,但是防火墙的设置需要小心,尤其是初学者,很容易弄错,一旦弄错,很容易连不上网络,要自己去机房重新配置防火墙。

如果不熟悉配置,一个是怕权限太严格,容易导致自己都不能访问,上面的程序也很可能不能正常访问网络,另一个是怕权限设置的太松,安全性不够,容易被侵入。所以初学者很需要一个简单的防火墙模板,经过简单修改,就能满足一般的安全要求,不用走多个弯路。于是我参考鸟哥的私房菜,经过修改,写出以下防火墙的模板,帮助初学者入门,巩固防火墙。脚本内容如下,保存脚本内容为iptables.sh,然后直接执行,还要加入/etc/rc.local下,随机启动执行防火墙配置(以上工作前提是防火墙服务有打开)。

IF=”eth0″

#清除规则
/sbin/iptables -F
/sbin/iptables -X
/sbin/iptables -Z

预定义策略

/sbin/iptables -A INPUT -s 127.0.0.1 -j ACCEPT  # 允许回环接口可以被访问
/sbin/iptables -P INPUT   DROP # 默认是拒绝访问
/sbin/iptables -P OUTPUT  ACCEPT  # 允许本机访问其他机器,无限制
/sbin/iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A INPUT -p icmp -j ACCEPT # 允许ping
#允许的本机服务
/sbin/iptables -A INPUT -p TCP -i $IF –dport 22 -j ACCEPT        # SSH
/sbin/iptables -A INPUT -p TCP -i $IF –dport  3306 -j ACCEPT        # mysql
/sbin/iptables -A INPUT -p TCP -i $IF –dport  80 -j ACCEPT        # web

黑名单

#/sbin/iptables -A INPUT -s 1.1.1.0/24 -j DROP
#/sbin/iptables -A INPUT -s 1.1.1.0 -j DROP

信任的网络和IP

/sbin/iptables -A INPUT -s 1.1.1.1/24 -j ACCEPT # 信任的网络

/sbin/iptables -A INPUT -s 1.1.1.1  -j ACCEPT # 信任的ip

使用者,只要根据自己的情况,修改信任的网络和IP,还有允许的本机服务,本脚本可以满足一般的安全要求。更多内容参考:http://vbird.dic.ksu.edu.tw/linux_server/0250simple_firewall/0250simple_firewall-centos4.php

发自 WordPress for Android

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.