iptables -j 与 -g 参数

iptables -j vs. -g parameters

从我的发行版的手册页中,我对下面的粗体部分特别感兴趣。

-j, --jump target

This specifies the target of the rule; i.e., what to do if the packet matches it. The target can be a user-defined chain (other than the one this rule is in), one of the special builtin targets which decide the fate of the packet immediately, or an extension (see EXTENSIONS below). If this option is omitted in a rule (and -g is not used), then matching the rule will have no effect on the packet's fate, but the counters on the rule will be incremented.

-g, --goto链

This specifies that the processing should continue in a user specified chain. Unlike the --jump option return will not continue processing in this chain but instead in the chain that called us via --jump.

恐怕我误解了 -g 的实际作用。

-g 现在与 -j 有何不同?

当当前链中的匹配规则指定了目标RETURN,或者到达当前链的末尾时,继续处理跳转到当前链的前一条链,从仍未处理的下一条规则,即实际指定当前链作为其目标并触发跳转到当前链的规则下方的规则。

然而,如果跳转到当前链是通过 -g(而不是通过 -j)完成的,处理将不会在之前的链中继续,而是在之前的链中继续,假设那里的跳跃是用 -j 完成的。如果情况也不是这样(即即使使用了 -g),那么之前的链也会被考虑在内,依此类推。换句话说,实际上用 -j 而不是用 -g 指定下一个链的最近链将被接下来处理。

如果没有找到这样的链(即所有链直到并包括指定的内置链-g),或者到达内置链的末尾或内置规则in chain with target RETURN 匹配,内置链策略指定的目标决定数据包的命运。