iptables 规则疑问

2017-06-03 21:39:15 +08:00
 syuraking
这两种写法,最终结果是否相同?
第一种:
-A INPUT -p udp --dport 10000:65000 -j ACCEPT

-A INPUT -p tcp --dport 16666:20000 -j ACCEPT


第二种:
-A INPUT -p udp -m udp --dport 10000:65000 -j ACCEPT

-A INPUT -p tcp -m tcp --dport 16666:20000 -j ACCEPT


在网上找了一堆资料,也没看明白是什么意思,求高人指点一下,两者有没有什么不同,执行的结果是不是一样的?
2061 次点击
所在节点    问与答
3 条回复
auser
2017-06-03 22:07:55 +08:00
网上找资料不如读文档。


iptables-extensions(8) iptables 1.6.0 iptables-extensions(8)

NAME
iptables-extensions — list of extensions in the standard iptables distribution

SYNOPSIS
ip6tables [-m name [module-options...]] [-j target-name [target-options...]

iptables [-m name [module-options...]] [-j target-name [target-options...]

MATCH EXTENSIONS
iptables can use extended packet matching modules with the -m or --match options, followed by the matching module name; after these, various extra command line options become available, depending on the specific module. You can specify multiple extended match modules in one line, and you can use the -h or --help options after the module has been specified to receive help specific to that module. The extended match modules are evaluated in the order they are specified in the rule.

--------------------------
If the -p or --protocol was specified and if and only if an unknown option is encountered, iptables will try load a match module of the same name as the protocol, to try making the option available.
--------------------------


tcp
These extensions can be used if `--protocol tcp' is specified. It provides the following options:

udp
These extensions can be used if `--protocol udp' is specified. It provides the following options:
ryd994
2017-06-04 01:24:40 +08:00
一样
-p udp 会自动加载 -m udp
如果你用 iptables-save 导出看就是一样的
syuraking
2017-06-04 08:08:47 +08:00
@ryd994
@auser

谢谢,大致明白了区别点在哪儿了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/365741

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX