岁月联盟 · 中国技术网 本站主页 | 安全认证 | 用户服务 | 技术论坛
新闻快报 | 新手学堂 | 黑客特区 | 程序语言 | 数 据 库 | 防 火 墙 | 路由交换 | 系统集成 | 服 务 器 | 存储备份 | 考试认证
Windows | Linux | Java | 协议分析 | 问题解答 | 进程大全 | 网页设计 | 多 媒 体 | 图库资料 | 软件下载 | 站内下载
  您现在的位置: 岁月联盟 >> Linux频道 >> 网络管理 >> Linux安全 >> Linux频道正文
Linux系统下IPtables防火墙简易设置方法
作者:未知 文章来源:本站整理 点击数: 更新时间:2007-12-18 17:34:39

  iptables.rule为firewall总规则;

  iptables.allow为充许进入的主机;

  iptables.deny为不许放的主机;

  iptables.allow代码如下:

  #!/bin/bash

  # This is an esay firewall.

  # the inside interface. if you don't have this one

  # and you must let this be black ex> INIF=""

  INIF="eth0"

  INNET="192.168.160.0/20"

  # 2.0 load the right module

  PATH=/sbin:/bin:/usr/sbin:/usr/bin

  export PATH EXTIF INIF INNET

  modprobe ip_tables > /dev/null 2>&1

  modprobe iptable_nat > /dev/null 2>&1

  modprobe ip_nat_ftp > /dev/null 2>&1

  modprobe ip_nat_irc > /dev/null 2>&1

  modprobe ip_conntrack > /dev/null 2>&1

  modprobe ip_conntrack_ftp > /dev/null 2>&1

  modprobe ip_conntrack_irc > /dev/null 2>&1

  # 3.0 clear iptables rule

  /sbin/iptables -F

  /sbin/iptables -X

  /sbin/iptables -Z

  /sbin/iptables -F -t nat

  /sbin/iptables -X -t nat

  /sbin/iptables -Z -t nat

  /sbin/iptables -P INPUT DROP

  /sbin/iptables -P OUTPUT ACCEPT

  /sbin/iptables -P FORWARD ACCEPT

  /sbin/iptables -t nat -P PREROUTING ACCEPT

  /sbin/iptables -t nat -P POSTROUTING ACCEPT

  /sbin/iptables -t nat -P OUTPUT ACCEPT

  # 4.0 start loading trusted and denied file.

  if [ -f /usr/local/virus/iptables/iptables.allow ]; then

  sh /usr/local/virus/iptables/iptables.allow

  fi

  if [ -f /usr/local/virus/iptables/iptables.deny ]; then

  sh /usr/local/virus/iptables/iptables.deny

  fi

  # 5.0 if the following file exist ,please executed

  if [ -f /usr/local/virus/httpd-err/iptables.http ];then

  sh /usr/local/virus/httpd-err/iptables.http

  fi

  # 6.0 allow icmp data packet and the establishd data

  /sbin/iptables -A INPUT -m state ——state ESTABLISHED,RELATED -j ACCEPT

  AICMP="0 3 3/4 4 11 12 14 16 18"

  for tyicmp in $AICMP

  do

  /sbin/iptables -A INPUT -i $EXTIF="eth0" -p icmp ——icmp-type $tyicmp -j ACCEPT

  done

[1] [2] 下一页  

  # 7.0 open the other service ports

  /sbin/iptables -A INPUT -p TCP -i $EXTIF="eth0" ——dport 25 -j ACCEPT # SMTP

  /sbin/iptables -A INPUT -p TCP -i $EXTIF="eth0" ——dport 53 -j ACCEPT # DNS

  /sbin/iptables -A INPUT -p TCP -i $EXTIF="eth0" ——dport 80 -j ACCEPT # WWW

  /sbin/iptables -A INPUT -p TCP -i $EXTIF="eth0" ——dport 110 -j ACCEPT # POP3

  /sbin/iptables -A INPUT -p TCP -i $EXTIF="eth0" ——dport 113 -j ACCEPT #AUTH

  /sbin/iptables -A INPUT -p TCP -i $EXTIF="eth0" ——dport 22222 -j ACCEPT #SSH

  /sbin/iptables -A INPUT -p UDP -i $EXTIF="eth0" ——dport 138 -j ACCEPT #138

  /sbin/iptables -A INPUT -p TCP -i $EXTIF="eth0" ——dport 139 -j ACCEPT #139

  /sbin/iptables -A INPUT -p UDP -i $EXTIF="eth0" ——dport 137 -j ACCEPT #137

  /sbin/iptables -A INPUT -p TCP -i $EXTIF="eth0" ——dport 445 -j ACCEPT #445

  iptables.allow代码如下

  #!/bin/bash

  # this program is used to allow some IP or hosts to a

[1] [2] 下一页


  • 上一个Linux频道:
  • 下一个Linux频道:
  •  
    热门文章
    推荐文章
    关于我们 | 发展历程 | 网站地图 | 广告服务 | 招贤纳士 | 战略合作 | 友情链接 | 著作声明 | 联系我们
    Copyright © 2002-2007 SYUE All rights reserved.
    E_mail:Admin@Syue.Com 皖ICP备05004589号
    未经授权禁止转载、摘编、复制或建立镜像.如有违反,追究法律责任.
    天龙八部私服 传世私服 传奇世界私服 传奇私服 bet365 天龙八部私服 热血江湖私服 英雄合击传奇私服 热血江湖私服 bet365 bet365