Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5707929
  • 博文数量: 675
  • 博客积分: 20301
  • 博客等级: 上将
  • 技术积分: 7671
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-31 16:15
文章分类

全部博文(675)

文章存档

2012年(1)

2011年(20)

2010年(14)

2009年(63)

2008年(118)

2007年(141)

2006年(318)

分类: LINUX

2006-09-04 21:55:09

==========================================================

由于时间久远,这里找不到原帖了,无法标明出处了,这里对原作者表示歉意。

==========================================================

经常看到一些网络中流传的 iptables 脚本在开头的位置大多是如下内容

#!/bin/sh

#

modprobe ipt_MASQUERADE

modprobe ip_conntrack_ftp

modprobe ip_nat_ftp

iptables -F

iptables -t nat -F

iptables -X

iptables -t nat -X

iptables -P INPUT DROP

摘自

有的是这样的

# 2.0 载入模组

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

摘自

网上流传的东西未必就都是正确的,针对上面一些误区,我来做一下详细说明

1、modprobe ip_tables

当 iptables 对 filter、nat、mangle 任意一个表进行操作的时候,会自动加载 ip_tables 模块

另外,iptable_filter、iptable_nat、iptable_mangle 模块也会自动加载,情形例如

# lsmod

Module Size Used by Not tainted

iptable_mangle 2136 0 (autoclean) (unused)

iptable_filter 1708 0 (autoclean) (unused)

ip_tables 12832 2 [iptable_mangle iptable_filter]

8139too 13704 1

mii 2544 0 [8139too]

reiserfs 183376 2 (autoclean)

raid1 13068 1 (autoclean)

md 44480 2 [raid1]

因此,脚本里不用写 modprobe ip_tables

2、modprobe ip_conntrack

ip_conntrack 是状态检测机制,state 模块要用到

当 iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 时,ip_conntrack 自动加载,例如

# lsmod

Module Size Used by Not tainted

ipt_state 536 1 (autoclean)

ip_conntrack 25096 0 (autoclean) [ipt_state]

iptable_filter 1708 1 (autoclean)

ip_tables 12832 2 [ipt_state iptable_filter]

8139too 13704 1

mii 2544 0 [8139too]

reiserfs 183376 2 (autoclean)

raid1 13068 1 (autoclean)

md 44480 2 [raid1]

另外,modprobe ip_conntrack_ftp 时也会自动加载 ip_conntrack

3、modprobe ip_conntrack_ftp

ip_conntrack_ftp 是本机做 FTP 时用的

ip_nat_ftp 是通过本机的 FTP 需要用到的(若你的系统不需要路由转发,没必要用这个)

当 modprobe ip_nat_ftp 时,系统自动会加载 ip_conntrack_ftp 模块,例如

# lsmod

Module Size Used by Not tainted

ip_nat_ftp 2736 0 (unused)

iptable_nat 18040 4 [ip_nat_ftp]

ip_tables 12544 12 [iptable_filter iptable_nat]

ip_conntrack_ftp 3856 1

ip_conntrack 20268 3 [ip_nat_ftp iptable_nat ip_conntrack_ftp]

8139too 13704 1

mii 2544 0 [8139too]

reiserfs 183376 2 (autoclean)

raid1 13068 1 (autoclean)

md 44480 2 [raid1]

因此,当需要用到 ip_nat_ftp 时,脚本里不用写 modprbe ip_conntrack 和 modprobe ip_conntrack_ftp

4、iptables -P OUTPUT DROP

除非你明白 filter 中 OUTPUT 链的作用,除非你想限制 Linux 本机上网

否则,不要 iptables -P OUTPUT DROP!

5、先设置规则,还是先设置默认策略

不少脚本都是这样写的

iptables -F xxx

iptables -X

iptables -P INPUT DROP

modprobe ip_nat_ftp

之后才是具体规则

iptables -P INPUT DROP 是什么意思?

设置默认规则为 DROP,也就是说如果数据包没有被链中规则匹配,则默认按默认规则处理

试想,假如你在远程调试一个脚本,当前 filter 表的 INPUT 链默认规则是 DROP,iptables -F 后意味着什么?

因此,我建议大家

先设置默认规则为 ACCEPT

然后添加具体链的规则

最后设置默认规则为 DROP

若用基于 RedHat(CentOS) 的发行版,可以用 service iptables stop 来卸载内核中与 iptables 和 netfilter 有关的东西

阅读(1286) | 评论(6) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-08-13 10:48:32

这位老兄有点不够意思,这个文章是CU的版主白金写的,转贴也该注明出处。

chinaunix网友2009-08-13 10:48:32

这位老兄有点不够意思,这个文章是CU的版主白金写的,转贴也该注明出处。