iptables -p 使用 tcp/udp 以外的协议

par*_*ing 2 linux iptables linux-kernel iproute network-interface

根据我的理解,iptables 在传输层(第 4 层)上工作,发生的任何数据包过滤都基于第 4 层的 ip 协议,如 tcp 和 udp。因此,如果我们在iptables -p选项中输入 esp、gre 和 l2tp 等协议,这是否有意义?我们可以使用 iptables 过滤基于第 2/3 层协议的数据包吗?如果不是,那么iptables是如何基于icmp协议过滤数据包的呢?

iptables 新手,我仍在学习。谢谢!

111*_*--- 6

iptables 支持在数据链路、网络和传输层进行过滤。

-p(协议)选项并不特别限定于4个协议。该手册页提到ICMP和ESP明确。我知道也支持 gre(作为“gre”或协议“47”)。指定的协议可以通过名称或其在 中指定的整数传递给此选项/etc/protocols。我不确定 iptables 是否支持此列表中的所有协议。

如果指定了 -p 或 --protocol 并且当且仅当遇到未知选项时,iptables 将尝试加载与协议同名的匹配模块,以尝试使该选项可用。

此“匹配模块”语法是扩展的数据包匹配模块,将使用-m --match选项指定。

您可以在此处找到支持的扩展列表:iptables-extensions。可用的 netfilter 内核模块列表位于/lib/modules/$(uname -r)/kernel/net/netfilter