赛迪网 > IT技术 Linux > 系统管理
  IT资讯搜索
 
IT产品搜索
[程序开发][网管世界][网络安全][数据库技术]
[操作系统][嘉宾聊天·在线访谈][活动集锦]
[精彩专题][Symantec专区][订阅IT技术周刊]
[开发论坛][网管论坛][安全论坛][数据库论坛]
[操作系统论坛][Sybase专区][IBM dW技术专区]
[病毒求助][病毒与漏洞播报][文档·源码下载]

Linux系统下IPtables防火墙简易设置方法

发布时间:2007.10.17 06:17     来源:赛迪网    作者:metallica

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

# 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 access your server

/sbin/iptables -A INPUT -i $EXTIF="eth0" -s 192.168.161.242 -j ACCEPT

/sbin/iptables -A INPUT -i $EXTIF="eth0" -s 192.168.160.178 -j ACCEPT

/sbin/iptables -A INPUT -i $EXTIF="eth0" -s 192.168.160.218 -j ACCEPT

iptables.deny代码如下

#! /bin/bash

# This script will deny some IPs that I don't want in IN

/sbin/iptables -A INPUT -i $EXTIF="eth0" -s 192.168.160.242 -j DROP

以上的三个文件都放在/usr/local/virus/iptables目录下,最在修改此文件/etc/rc.d/rc.local成如下代码。

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

# Starting firewall settings

/usr/local/virus/iptables/iptables.rule

以上就是linux下firewall简易设置啦。

(责任编辑:云子)


[ 发表评论 ] 字体[  ] [ 打印 ] [ 进入博客 ] [ 进入论坛 ]  [ 推荐给朋友 ]
  相关文章
· Linux系统攻略 Samba服务器的搭建与配置 (10-16) · 新手学堂:Linux操作系统中安装网卡驱动 (10-16)
· 新手学堂:进入Linux操作系统的单机模式 (10-16) · Linux和开源软件的主要优势体现在哪里? (10-16)
· Ubuntu开源新版将发布 能耗将低于7.04版 (10-16) · IBM在深圳落成linux大型计算机支持中心 (10-15)
· 如何监控和保护Linux操作系统的运行进程 (10-15) · Ubuntu Linux 7.04系统安装并使用Proftp (10-15)
· UNIX的分支 服务器上的FreeBSD操作系统 (10-15) · Linux操作系统下VMware的多网卡桥接转换 (10-15)
  客户需求反馈表
* 姓  名:
更多资料  了解方案  认识厂商
* 单位名称:
* 联系电话:
* 电子邮件:
  赛迪推荐  
  手机·资费 ·新品·导购·评测·手机资费·宽带
手机搜索  诺基亚 N73 MOTO Z6
  IT产品 ·笔记本·台式机·服务器·打印·投影
IT产品搜索 
  IT技术 ·开发·网管·安全·数据库·操作系统
  信息化 ·热点·专题·访谈·周刊·方案案例
· 移动信息化市场方兴未艾 企业呼唤标准出台
· 如何把握企业价值差异 避免CRM与SCM脱节
· 齐看四大厂商的SaaS动态 ERP案例分析
· 通方期货CRM解决方案 方正电子公文系统
  IT博客 ·曾剑秋·项立刚·Java学习·网管
  IT技术论坛 ·开发·网管·安全·数据库·系统