正文
(每个info和help本是英文的,为方便阅读我把它翻译成中文,由于水平有限,如果有误请有经验者来信指正)netfilter/iptables模块功能中文介绍
powered by kindgeorge 2005.4.2 chinaunix.net
功能介绍 (每个info和help本是英文的,为方便阅读我把它翻译成中文,由于水平有限,如果有误请有经验者来信指正)
获取最新patch-o-matic-ng的地址:ftp://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/
[root@kindgeorge src] wget ftp://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/patch-o-matic-ng-20050331.tar.bz2
解压:
tar xjvf patch-o-matic-ng-20050331.tar.bz2 后,在/usr/src/下生成目录patch-o-matic-ng-20050331
进入该目录
[root@kindgeorge src]# cd patch-o-matic-ng-20050331
统计一下
[root@kindgeorge patch-o-matic-ng-20050331]# ls |wc -l
99
其中共94个目录,就是说有九十多个拓展功能.这里只对部分感兴趣,对这些进行介绍.
patch
-o-matic-ng-20050331目录下有readme
和readme.newpatches.不过都是英文的,大概是介绍怎么应用这些补丁和使用约定.里面每个拓展功能为一个目录,每个目录下面都有info
(信息) 和help(使用帮助)文件,info里面一般是这样的:
title: terse description of the patch 标题: 这个补丁的简单描述
author: author (name, e-mail address) 作者(名字,email地址)
status: testing|experimental|alpha|beta|stable 状况:试验的|根据实验的|测试一版|测试二版|稳定的
repository: submitted|pending|base|extra贮仓库:顺从的|未决的|基础的|额外的
requires:
repository-entry ==|>|<|>=|<=
kernel-version|iptables-version 要求:
贮仓库==|>|<|>=|<=内核版本|iptables版本
depends: [!]patch-name 依赖性:(否)补丁名字
recompile: kernel|netfilter|iptables 重新编译:内核|netfilter|iptables
successor: patch-name 继承者: 补丁名字
1. string(字符串匹配,可以用做内容过滤)
[root@kindgeorge patch-o-matic-ng-20050331]# cat string/info
title: iptables string match (标题: iptables 字符串匹配)
author: emmanuel roger (作者:名字,email地址)
status: working, not with kernel 2.4.9 (状况:正常工作, 但不能在内核2.4.9工作)
repository: extra (贮仓库: 额外的)
requires: linux < 2.6.0 (要求: linux < 2.6.0)
[root@kindgeorge patch-o-matic-ng-20050331]# cat string/help
this patch adds config_ip_nf_match_string which allows you to
match a string in a whole packet.
this patch does not work with kernel 2.4.9 !!!
翻译:这个补丁增加config_ip_nf_match_string,允许在一整个包里面匹配一个字符串.
译者:这个功能真是值得一用,实际上应该说是可以做内容过滤吧,令人兴奋啊.我测试过,连中文也支持,我是这样测试它的:
iptables -i forward -m string --string "腾讯" -j drop
iptables -i forward -s 192.168.3.159 -m string --string "qq.com" -j drop
iptables -i forward -d 192.168.3.0/24 -m string --string "宽频影院" -j drop
iptables -i forward -d 192.168.3.0/24 -m string --string "色情" -j drop
iptables -i forward -d 192.168.3.0/24 -p tcp --sport 80 -m string --string "广告" -j drop
至于怎么灵活运用就要看自己的需要了.
关于string其他安全应用这里有个转帖收录:
http://blog.chinaunix.net/article.php?articleid=16909&blogid=4543
2. comment (备注匹配,可以支持最多256个字符)
[root@kindgeorge patch-o-matic-ng-20050331]# cat comment/info
title: iptables comment match (标题: iptables 注释匹配)
author: brad fisher (作者(名字,email地址brad@info-link.net))
status: part of 2.6.x mainline(状况:2.6.x主流版本的一部分) [由于mainline我还在犹豫怎么翻译,高手请提示]
repository: submitted (贮仓库: 顺从的)
requires: linux == 2.4 (要求: linux == 2.4)
recompile: netfilter, iptables(重新编译:netfilter|iptables)
[root@kindgeorge patch-o-matic-ng-20050331]# cat comment/help this option adds config_ip_nf_match_comment, which supplies a comment
match module. this match allows you to add comments (up to 256 characters)
to any rule.
supported options:
--comment comment
翻译:这个选项增加config_ip_nf_match_comment,补充一个注释匹配模块.这个匹允许你增加一个备注都任何规则,这个备注最多支持256个字符,例如
example:(例子:)
-a input -s 192.168.0.0/16 -m comment --comment "a privatized ip block"
译者:我是这样测试使用这个comment
iptables -i forward -s 192.168.3.159 -p tcp --dport 80 -j drop -m comment --comment "the bad guy can not online"
iptables -i forward -s 192.168.3.159 -m string --string "qq.com" -j drop -m comment --comment "denny go to qq.com"
这样在iptables -l时,就看到每条规则后面出现备注的内容.可以提高可读和理解该条规则的作用.
这个comment 在2.6.x中已经被正式收录.
3. connlimit(同时连接个数限制匹配)
[root@kindgeorge patch-o-matic-ng-20050331]# cat connlimit/info
title: iptables connlimit match (标题: iptables同时连接个数限制匹配)
author: gerd knorr (作者:名字,email地址)
status: itworksforme[tm] (状态:我可以运作)
repository: base (贮仓库: 基础的)
[root@kindgeorge patch-o-matic-ng-20050331]# cat connlimit/help
this
adds an iptables match which allows you to restrict the number of
parallel tcp connections to a server per client ip address(or address
block).
翻译:这个增加一个iptables匹配允许你限制每个客户ip地址的并发tcp连接,即同时连接到一个服务器个数.
examples: 例子:
# allow 2 telnet connections per client host (允许每个客户机同时两个telnet连接)
iptables -p tcp --syn --dport 23 -m connlimit --connlimit-above 2 -j reject
# you can also match the other way around:(你也可以匹配其他的方法:)
iptables -p tcp --syn --dport 23 -m connlimit ! --connlimit-above 2 -j accept
# limit the nr of parallel http requests to 16 per class c sized (这下面例子限制80端口最多同时16个连接请求)
# network (24 bit netmask)
iptables -p tcp --syn --dport 80 -m connlimit --connlimit-above 16 --connlimit-mask 24 -j reject
模块 connlimit 作用:连接限制
--connlimit-above n 限制为多少个
--connlimit-mask n 这组主机的掩码,默认是connlimit-mask 32 ,即每ip.
这个主要可以限制内网用户的网络使用,对服务器而言则可以限制每个ip发起的连接数...比较实用
例如:只允许每个ip同时5个80端口转发,超过的丢弃:
iptables -i forward -p tcp --syn --dport 80 -m connlimit --connlimit-above 5 -j drop
例如:只允许每组c类ip同时10个80端口转发:
iptables -i forward -p tcp --syn --dport 80 -m connlimit --connlimit-above 10 --connlimit-mask 24 -j drop
例如:为了防止dos太多连接进来,那么可以允许最多15个初始连接,超过的丢弃.
/sbin/iptables -a input -s 192.186.1.0/24 -p tcp --syn -m connlimit --connlimit-above 15 -j drop
/sbin/iptables -a input -s 192.186.1.0/24 -p tcp -m state --state established,related -j accept
4. time(时间匹配)
[root@kindgeorge patch-o-matic-ng-20050331]# cat time/info title: iptables ``time match (标题: iptables时间匹配)
author: fabrice marie (作者:名字,email地址)
status: works within its limitations (状况:运作)
repository: base (贮仓库: 基础的)
[root@kindgeorge patch-o-matic-ng-20050331]# cat time/help
this option adds config_ip_nf_match_time, which supplies a time match module.
this
match allows you to filter based on the packet arrival
time/date(arrival time/date at the machine which the netfilter is
running on) or
departure time/date (for locally generated packets).
翻译:这个选项增加一个时间匹配模块,这个匹配允许你过滤基于包到达时间/日期(这个到达时间和日期是指这个netfilter运行的机器上的)或者发出时间/日期(本地产生的信息包)
supported options are: (支持选项有:)
[ --timestart value ] (开始时间 值)
match only if it is after `value (inclusive, format: hh:mm ; default 00:00).
(只是匹配在这个值之后)(包括格式hh:mm ; 默认 00:00)
[ --timestop value ] (结束时间 值)
match only if it is before `value (inclusive, format: hh:mm ; default 23:59).
(只是匹配在这个值之前的)(包括格式hh:mm ; 默认 23:59)
[ --days listofdays ] (--天 天列表)
match only if today is one of the given days. (format: mon,tue,wed,thu,fri,sat,sun ; default everyday)
(只是匹配已经给出的天,格式mon,tue,wed,thu,fri,sat,sun ;默认每天)
[ --datestart date ] (开始日期 日期)
match only if it is after `date (inclusive, format: yyyy[:mm[:dd[:hh[:mm[:ss]]]]] h,m,s start from 0 ; default to 1970)
(只是匹配这个开始日期值之后的(包括,格式: yyyy[:mm[:dd[:hh[:mm[:ss]]]]] h,m,s start from 0 ; 默认是1970):
[ --datestop date ]
match only if it is before `date (inclusive, format: yyyy[:mm[:dd[:hh[:mm[:ss]]]]] h,m,s start from 0 ; default to 2037)
(只是匹配这个开始日期值之前的(包括,格式: yyyy[:mm[:dd[:hh[:mm[:ss]]]]] h,m,s start from 0 ; 默认是2037):
example: (例子:)
-a input -m time --timestart 8:00 --timestop 18:00 --days mon,tue,wed,thu,fri
will match packets that have an arrival timestamp in the range 8:00->18:00 from monday to friday.
(上面将匹配从到达日期是星期一至星期五时间从8:00至18:00的包)
-a output -m time --timestart 8:00 --timestop 18:00 --days mon --date-stop 2010
will match the packets (locally generated) that have a departure timestamp in the range 8:00->18:00 on monday only, until 20
5. iprange (ip范围匹配)
[root@kindgeorge patch-o-matic-ng-20050331]# cat iprange/info
title: iptables iprange match (标题: iptables范围匹配)
author: jozsef kadlecsik (作者:名字,email地址)
status: works (状况:运作)
repository: base (贮仓库: 基础的)
[root@kindgeorge patch-o-matic-ng-20050331]# cat iprange/help
this patch makes possible to match source/destination ip addresses against inclusive ip address ranges.
翻译: 这个补丁令匹配源/目标 ip地址可以倚着给出的地址范围进行匹配
examples:(例子)
iptables -a forward -m iprange --src-range 192.168.1.5-192.168.1.124 -j accept
这个例子是允许源ip地址范围192.168.1.5-192.168.1.124的包通过
iptables -a forward -m iprange --dst-range 10.0.0.0-10.255.255.255 -j accept
这个例子是允许目标ip地址范围10.0.0.0-10.255.255.255的包通过
6. geoip(根据地理位置匹配)
[root@kindgeorge patch-o-matic-ng-20050331]# cat geoip/info
title: iptables geoip match (标题: iptables国家地区匹配)
author: samuel jean ; nicolas bouliane (作者:名字,email地址)
status: testing (状况:测试)
repository: extra (贮仓库: 额外的)
recompile: netfilter, iptables (重新编译: netfilter, iptables)
[root@kindgeorge patch-o-matic-ng-20050331]# cat geoip/help
this patch makes possible to match a packet by its source or destination country.
翻译:这个补丁令一个包能够根据源或目的国家(地区)匹配
geoip options: (选项:)
[!] --src-cc, --source-country country[,country,country,...]
match packet coming from (one of) the specified country(ies)
根据包的来源(或非来源)地区匹配
[!] --dst-cc, --destination-country country[,country,country,...]
match packet going to (one of) the specified country(ies)
根据包的去向(或非去向)地区匹配
note: the country is inputed by its iso3166 code.
注意:这个国家地区列表放在iso3166编码里
the
only extra files you need is a binary db (geoipdb.bin) & its index
file (geoipdb.idx).both files are generated from a countries &
subnets database with the csv2bin tool,available at
both files must also be moved in /var/geoip/ as the shared library is
statically looking for that pathname (ex.: /var/geoip/geoipdb.bin).
这
个你需要额外的二进位文件geoipdb.bin 和它的索引文件geoipdb.idx.这两个文件是国家地区网络数据库,是用csv2bin
工具生成的,可以在得到.这些文件必须放在/var/geoip/下,作为一个共享库查找路径名
字如/var/geoip/geoipdb.bin
7. nth(第n个包匹配)
[root@kindgeorge patch-o-matic-ng-20050331]# cat nth/info
title: iptables nth match (标题: iptables第n个匹配)
author: fabrice marie (作者:名字,email地址)
status: works (状况:运作)
repository: base (贮仓库: 基础的)
[root@kindgeorge patch-o-matic-ng-20050331]# cat nth/help
this
option adds an iptables `nth match, which allows you to match every nth
packet encountered. by default there are 16 different counters that
can be used.
翻译: 这个选项增加一个第n个匹配,允许你匹配每隔n个包,默认有16不同的计算方法可以使用
this match functions in one of two ways
1) match ever nth packet, and only the nth packet.
example:(例子)
iptables -t mangle -a prerouting -m nth --every 10 -j drop
this rule will drop every 10th packet.
这个规则将丢弃每隔10个包
2) unique rule for every packet. this is an easy and quick method to produce load-balancing for both inbound and outbound.
为每一个包应用一个独特的规则,这样是一个容易和快速的负载均衡方法
example: (例如)
iptables -t nat -a postrouting -o eth0 -m nth --counter 7 --every 3 --packet 0 -j snat --to-source 10.0.0.5
iptables -t nat -a postrouting -o eth0 -m nth --counter 7 --every 3 --packet 1 -j snat --to-source 10.0.0.6
iptables -t nat -a postrouting -o eth0 -m nth --counter 7 --every 3 --packet 2 -j snat --to-source 10.0.0.7
this example evenly splits connections between the three snat addresses.
上面例子由三个源ip地址平滑分割连接
by using the mangle table and iproute2, you can setup complex load-balanced routing. theres lot of other uses. be creative!
配合iptables 的mangle表和高级路由iproute2,你能设置一个复合的负载平衡路由.还有其他的用途,具有创造性的设置
suppported options are: (支持选项有:)
--every nth match every nth packet (匹配每n 个包)
[--counter] num use counter 0-15 (default:0) (用计算器(默认是0))
[--start] num initialize the counter at the number num instead of 0. must be between 0 and nth-1
(初始化一个计算器,用这个num值而不是0. 必需是在0和n减1之间的数
[--packet]
num match on num packet. must be between 0 and nth-1. if
--packet is used for a counter than there
must be nth number of --packet rules, covering all values between 0 and
nth-1 inclusively.
匹配num 包,必需是在0和n减1之间的数,如果该包被用一个计算器,必需是第nth数字包规则,并覆盖0至nth-1的所有值(这个翻译得不好,请指正)
8. ipp2p(点对点匹配)
[root@kindgeorge patch-o-matic-ng-20050331]# cat ipp2p/info
title: detects some p2p packets (标题: 侦查p2p包)
author: eicke friedrich (作者:名字,email地址)
status: stable (状况:稳定的)
repository: extra (贮仓库: 额外的)
recompile: netfilter, iptables (重新编译:netfilter|iptables)
[root@kindgeorge patch-o-matic-ng-20050331]# cat ipp2p/help
this option makes possible to match some p2p packets therefore helps controlling such traffic.
dropping all matches prohibits p2p networks.
combined with conntrack,connmark and a packet scheduler it can be used for accounting or shaping of p2p traffic.
这个选项能够匹配某些p2p包,帮助控制流量.丢弃所有匹配的p2p.结合连接跟踪,和一个包的调度器,它能被用作计算和整形一个p2流量
examples: (例如:)
iptables -a forward -m ipp2p --edk --kazaa --bit -j drop
iptables -a forward -p tcp -m ipp2p --ares -j drop
iptables -a forward -p udp -m ipp2p --kazaa -j drop
上例可以封杀很多bt等的p2p软件.
更多参数更详细的参考还有ipp2p/iptables/extensions/libipt_ipp2p.man或
9. quota(配额匹配)
[root@kindgeorge patch-o-matic-ng-20050331]# cat quota/info title: iptables quota match (标题: iptables配额匹配)
author: sam johnston (作者:名字,email地址)
status: worksforme (状况:运作的)
repository: base (贮仓库: 基础的)
[root@kindgeorge patch-o-matic-ng-20050331]# cat quota/help
this option adds config_ip_nf_match_quota, which implements network quotas by decrementing a byte counter with each packet.
这个选项增加一个模块匹配包实现网络包通过的配额
supported options are: (支持选项有:)
--quota
the quota in bytes. (用bytes为单位)
iptables -i forward -s 192.168.3.159 -p tcp --dport 80 -m quota --quota 500 -j drop
上例是这样的,在ip192.168.3.159的目标端口为80匹配的500个字节内,将被丢弃.直到匹配完这500字节后,才不会丢弃,就是说,才可以打开网页.
known bugs: this does not work on smp systems.
知道的bug:这个不能工作在smp系统上,(smp, symmetric multiprocessing 多处理技术)
10.其他的.
推荐用cat /模块目录名/info 和cat /模块目录名/help 查看相应的模块信息和帮助.
由于我对其他某些模块不太感兴趣,或和我现在系统2.4.20-8有冲突,没有再列出翻译.如果有谁翻译了,可以让我参考下.谢谢
如果有更新,请看blog:
相关资料:
安装编译 kindgeorge的:
http://blog.chinaunix.net/article.php?articleid=19797&blogid=4543
platinum 的 如何给iptables添加新的模块v2.2(含视频教程)
hongfengyue 的 iptables 添加模块 (for kernel 2.6)
官方: http://www.netfilter.org/documentation/howto/netfilter-extensions-howto.html
阅读(1938) | 评论(0) | 转发(0) |