首页 > linux问题 > 正文

简单通用的 iptables 脚本
2012-05-09 12:00:06   来源:   评论:0 点击:

 iptables 脚本介绍
   
    这是一个非常简单的 iptables 脚本,你只需要把要开放的端口写入 "$MPort" 变量中就行了,记住最多不能超过16个端口哦。这个脚本虽然简单,但能实现我们的基本要求,而且有时候简单的脚本作用更大,因为繁杂而臃肿不但难于理解,还会拖慢机器处理速度,呵呵。
   
    相关解释
   
    modprobe nf_conntrack_ftp ports=21
   
    modprobe nf_nat_ftp
   
    开放FTP端口,需要载入这两个模块。如果你修改了FTP默认连接端口,也需要修改此处:"modprobe nf_conntrack_ftp ports=21"
   
    iptables -A INPUT -s 127.0.0.1/32 -j ACCEPT
   
    本地回路,这个必需的。
   
    iptables -A INPUT -p tcp -m state –state related,established -j ACCEPT
   
    匹配已有连接和与已有连接相关的,FTP需要这个。
   
    iptables -A INPUT -p icmp –icmp-type 8 -m limit –limit 1/s –limit-burst 3 -j ACCEPT
   
    限制 ping 检查速度。
   
    iptables 脚本iptables.sh
   
    01 #!/bin/bash
   
    02 #author:        InBi
   
    03 #date:          2011-08-16
   
    04 #website:
   
    05 ##################################################
   
    06 MPort="80,21,2200,8080"
   
    07 ##################################################
   
    08 modprobe nf_conntrack_ftp ports=21
   
    09 modprobe nf_nat_ftp
   
    10 iptables -t filter -Z;iptables -t filter -F;iptables -t filter -X
   
    11 iptables -P INPUT DROP;iptables -P OUTPUT ACCEPT;iptables -P FORWARD DROP
   
    12
   
    13 iptables -A INPUT -p tcp -m state --state related,established -j ACCEPT
   
    14 iptables -A INPUT -p tcp ! --syn -m state --state new -j DROP
   
    15 iptables -A INPUT -s 127.0.0.1/32 -j ACCEPT
   
    16 iptables -A INPUT -p udp --sport 53 -j ACCEPT
   
    17 iptables -A INPUT -p tcp -m multiport --dports $MPort -j ACCEPT
   
    18 iptables -A INPUT -p icmp --icmp-type 8 -m limit --limit 1/s --limit-burst 3 -j ACCEPT
   
    把以上内容保存至iptables.sh(文件名自取),然后加上执行权限,加入开机启动就OK了。

相关热词搜索:简单 通用 iptables

上一篇:Linux操作系统下防范黑客的一些实用技巧
下一篇:最后一页

分享到: 收藏
评论排行