Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 操作系统 > Linux > iptables简单的脚本
【标  题】:iptables简单的脚本
【关键字】:iptables
【来  源】:http://blog.chinaunix.net/article.php?articleId=40696&blogId=8201

iptables简单的脚本

Your Ad Here     自由台外网得测试机器,可以测试使用,就写了一个简单得脚本,看了iptables只南,自己就试试!

eth0为内网,eth1为外网
echo 1 > /proc/sys/net/ipv4/ip_forward
可以使其局域网上网的简单命令
1.iptables -t nat -A POSTROUTING -j MASQUERADE
2.iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -j SNAT --to-source 218.17.*.*
或者 iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -j SNAT --to-source 218.17.*.*
3.iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o eth1 -j SNAT --to-source 218.17.*.*
或者 iptables -t nat -A POSTROUTING -o eth1 -s 192.168.2.0/24 -j SNAT --to-source 218.17.*.*
4.iptables -t nat -A POSTROUTING -o eth1 -s 192.168.2.0/24 -j MASQUERADE

例如:简单的脚本
1.编写脚本vi /usr/local/sbin/iptables.sh
#! /bin/bash
# Project by lch, 2005-09-02

#Initialize modules
modprobe ip_nat_ftp
modprobe ip_conntrack_ftp
echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -F
/sbin/iptables -t nat -F
/sbin/iptables -X
/sbin/iptables -t nat -X

# Deny ACK attack
/sbin/iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
/sbin/iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP

#共享上网(内网转发)
/sbin/iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o eth1 -j SNAT --to-source 218.17.*.*
##############INPUT链#######################
#内网192.168.2网段访问本机器ssh,telent,samba,8001端口,9090端口
/sbin/iptables -P INPUT DROP
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m multiport --dports 8001,9090 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -s 192.168.2.0/24 --dport 23 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -s 192.168.2.0/24 --dport 139 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -s 192.168.2.0/24 --dport 22 -j ACCEPT

##############FORWARD链######################
#允许内网192.168.2网段192.168.2网段8001,9090,ftp,telent,ssh,收发邮件,http,QQ,MSN通过
/sbin/iptables -P FORWARD DROP
iptables -A FORWARD -p tcp -s 192.168.2.0/24 -m multiport --dports 21,22,23,25,80,110,443,1863,8000,8001,9090 -j ACCEPT
iptables -A FORWARD -p udp -s 192.168.2.0/24 --dport 8000 -j ACCEPT
/sbin/iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

#禁止icmp通信(ping不通)
/sbin/iptables -A INPUT -p icmp -j DROP

2.加入/etc/rc.local中,使其系统每次启动机器都执行iptables
/usr/local/sbin/iptables.sh
3.给iptables.sh只能root用户读写执行
chmod 700 /usr/local/sbin/iptables.sh
Ok..

Microsoft Internet Explorer COM Objects Instantiat:【上一篇】
Troubleshooting的小总结,:【下一篇】
【相关文章】
  • 另一篇编译iptables模块的文章
  • IPTABLES 配置方法介绍
  • 短小精悍的IPTABLES配置练习
  • [转]Iptables 指南 1.1.19
  • 探讨 Linux 2.4 内核中的iptables 的各种新增功能和使用方法
  • iptables 入门
  • iptables下开放ftp连接
  • [Linux]用iptables统计流量
  • 关于iptables中ip_conntrack_max和hash表的关系及调整
  • 这个iptables用起来很不错
  • 【随机文章】
  • 无限子类,无限菜单的算法
  • Linux硬件通—声卡
  • 有关WEB开发的公告
  • Delphi面向对象的编程方法(二)
  • vsftp config
  • 如何同时启动6个X控制台
  • 本周ASP.NET英文技术文章推荐[11/19 - 11/25]
  • unrar3.5
  • 立体画梦工厂专业版2.04 算法分析
  • VC防止窗口及其控件(如CListCtrl)闪烁的简单方法(一组有用的宏)
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.