iptables新的连接与–syn

有什么区别:

iptables ... -m state --state NEW 

 iptables ... --syn 

第一个应该selectNEW连接,但是AFAIK新的连接是通过发送TCP syn标志来完成的。 另一个意思就是 – 带有syn标志的数据包。

你可以给任何实际的例子,当上述命令返回不同的结果?

--syn标志对检查TCPstream量很有用,但NEW状态可用于UDPICMP等其他协议(包括TCP )。 我可以说, NEW--syn TCP选项更普遍。

从iptables手册中,您可以阅读:

 NEW meaning that the packet has started a new connection, or otherwise associated with a connection which has not seen packets in both directions 

例如,DNS请求将与NEW状态匹配,但不会与具有--syn选项的规则相匹配。 简而言之,它是一个UDP数据报。

此外,可以使用--syn选项检查具有错误标志组合的TCP数据包,以删除它们。

另外,你可以同时使用这两个选项来检查没有--syn作为第一个数据包的NEW TCP数据stream,并且丢弃它们,例如:

 $ sudo iptables -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j LOG --log-prefix "New not syn:" 

在这里,我们将这些types的数据包添加到一个名为bad_tcp_packets的用户定义链中, bad_tcp_packets将其丢弃/logging等。