免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 772 | 回复: 2
打印 上一主题 下一主题

iptables一直有个问题没怎么搞得太清楚。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-08-21 23:03 |只看该作者 |倒序浏览
--syn:


[!] --syn
              Only  match TCP packets with the SYN bit set and the ACK,RST and
              FIN bits cleared.  Such packets are used to request TCP  connec-
              tion initiation; for example, blocking such packets coming in an
              interface will prevent incoming TCP  connections,  but  outgoing
              TCP  connections will be unaffected.  It is equivalent to --tcp-
              flags  SYN,RST,ACK,FIN  SYN.   If  the  "!"  flag  precedes  the
              "--syn", the sense of the option is inverted.

请问一下,具体哪些场合会将[!]--syn加入到匹配条件中去呢?

论坛徽章:
0
2 [报告]
发表于 2006-08-21 23:19 |只看该作者
原帖由 baif 于 2006-8-21 23:03 发表
--syn:
请问一下,具体哪些场合会将[!]--syn加入到匹配条件中去呢?


其实你提到的 manpage 的英文描述已经很清楚了,若是还不清楚建议去阅读一下 tcp/ip 网路协定内,位于传输层的 tcp and udp 这两个协定沟通流程就可以瞭解。当然,syn flag 一般是说 tcp,不是 udp。

  1. iptables -A INPUT -p tcp -s 192.168.1.1 -j DROP
复制代码


这是说禁止 192.168.1.1 不可以连结到你的主机,但是由于 tcp/ip 是双向沟通的,这样写其实也表示你也连不到该主机。你连线到对方主机,该主机封包要回应时刚好就会被该规则阻挡。所以一般搭配方式:

  1. iptables -A INPUT -p tcp --syn -s 192.168.1.1 -j DROP
复制代码


这是说当 tcp 封包旗标带有 SYN 项目,但是不包含  ACK,RST 旗标时,该封包就是主动连线的项目,所以这时候才禁止连结。

另外 --syn 这个已经很少用了,目前都会用 -m state --state NEW 方式来进行比对判断。

  1. iptables -A INPUT -m state --state NEW -s 192.168.1.1 -j DROP
复制代码


==

论坛徽章:
0
3 [报告]
发表于 2006-08-22 13:52 |只看该作者
嗯。 多谢kenduest。 其实大概的知道,就是写的规则比较少,所以没有太清楚具体的事情。谢谢。
--state state
              Where  state  is a comma separated list of the connection states
              to match.  Possible states are INVALID meaning that  the  packet
              could  not  be identified for some reason which includes running
              out of memory and ICMP errors  which  don’t  correspond  to  any
              known connection, ESTABLISHED meaning that the packet is associ-
              ated with a connection which has seen  packets  in  both  direc-
              tions, NEW meaning that the packet has started a new connection,
              or otherwise associated with a connection  which  has  not  seen
              packets  in both directions, and RELATED meaning that the packet
              is starting a new connection, but is associated with an existing
              connection, such as an FTP data transfer, or an ICMP error.

还是用-m state算了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP