linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘建议留言网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > article > linux网络与应用 > 网络安全 >
栏目导栏
资料搜索
热门文章
·Linux系统下使用aMsn(MSN)详解
·使用Snort规则.doc
·构建一个RADIUS服务器
·Netscreen防火墙简单配置实例
·IPTABLES配置方法
·SELinux 入门
·常用log4j配置
·如何利用嗅探器TcpDump分析网络
·ssh工具scp使用示例
·LINUX iptable应用手册(一)
·linux安全设置手册
·防火牆與ShoreWall使用方法
·snort 模块详讲
·LRP架构Linux路由器/防火墙
·Linux下防火墙设置
最新文章
·认识Linux操作系统下三大便利开
·Linux操作系统如何限制SSH密码
·Linux Iptables 内核2.6.18添加
·实用技巧:让Linux系统有效防御
·SELinux拒绝vsftpd上传文件到用
·解决SUSE Linux下SSH无法使用密
·关于Linux操作系统防火墙的进程
·OpenSSH实现Windows和Linux文件
·Linux防火墙示例 用简单规则集
·如何防范Linux操作系统下缓冲区
·Linux系统开防火墙时自动开启相
·Linux操作系统下防范黑客的一些
·Linux操作系统防火墙进程查看的
·Linux主机服务器被入侵后需要采
·通过监控Linux的运行进程来保证
Google
 
Linux系统下IPtables防火墙简易设置方法
[ 作者:  加入时间:2007-10-17 10:21:53  来自:Linux联盟收集整理 ]
 

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联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·UNIX和Linux中信号的个数  (2007-10-30 13:47:09)
 ·Linux 构建绿色校园网中的应用  (2007-10-30 12:57:09)
 ·Linux操作系统终端代理的设置方法介绍  (2007-10-30 12:31:18)
 ·Linux操作系统内存使用经验谈  (2007-10-30 12:29:55)
 ·Linux/Unix操作系统处于内网的桌面控制  (2007-10-30 12:28:59)
 ·摸清Linux日志处理的来龙去脉  (2007-10-30 12:28:18)
 ·Linux进入系统时自动设置环境变量的方法  (2007-10-30 12:27:35)
 ·linux下用GPG命令加密文件的方法  (2007-10-30 12:25:53)
 ·linux如何查询软件安装在什么目录  (2007-10-30 12:20:57)
 ·Linux 系统用户账号管理的基本操作命令  (2007-10-30 12:20:23)