iptables对报文中TTL的操作

欢迎转载,转载请务必注明出处:http://blog.csdn.net/alading2009/article/details/46289083

1. 匹配TTL值

  • 匹配TTL 大于 n(如 2) 的报文
iptables -t mangle -A POSTROUTING -m ttl --ttl-gt 2 -j DROP
  • 匹配TTL 小于 n 的报文
iptables -t mangle -A POSTROUTING -m ttl --ttl-lt 2 -j DROP
  • 匹配TTL 等于 n 的报文
iptables -t mangle -A POSTROUTING -m ttl --ttl-eq 2 -j DROP

2. 修改TTL值

  • 将TTL值 设定 为 n (如 2)
iptables -t mangle -A PREROUTING -i eth0 -j TTL --ttl-set 2
  • 将TTL值 减小 n
iptables -t mangle -A PREROUTING -i eth0 -j TTL --ttl-dec 2
  • 将TTL值 增大 n(一般情况下不要去增大TTL值)
iptables -t mangle -A PREROUTING -i eth0 -j TTL --ttl-inc 2

3. 关于ip6tables上操作 hop limit 字段


在 ip6tables 上的操作类似于 iptables 上的操作,如:

  • 匹配HL值
ip6tables -t mangle -A PREROUTING -i eth1 -m hl --hl-eq 2 -j DROP
  • 修改HL值
ip6tables -t mangle -A PREROUTING -i eth1 -j HL --hl-dec 2


唯一的区别在于在IPv6的规范中,生存时间TTL(time to live)叫做HL(hop limit)。另外,在ip6tables 上使用HL字段时经常会莫名其妙地导致ipv6网络不通,不知是否ip6tables对这个字段的支持还存在问题。

原文地址:https://www.cnblogs.com/read-the-spring-and-autumn-annals-in-night/p/12041975.html