大网数据广告活动
服务器运维问答

Iptables TTL and limit bytes

· 52CE 我爱测

I want to prohibit the reception and transmission of all packets whose size exceeds 512 bytes, and the TTL field is more than 30 Do I understand correctly that for TTL it will look like this: iptables -t mangle -A input -j TTL --…

问题原文

原帖链接 · Bronix · CC BY-SA 4.0

I want to prohibit the reception and transmission of all packets whose size exceeds 512 bytes, and the TTL field is more than 30

Do I understand correctly that for TTL it will look like this:

iptables -t mangle -A input -j TTL --ttl-set 30 ?

But I still need to specify in this rule that the packet does not exceed 512 bytes, how can I do that?

已采纳解答

原帖链接 · HBruijn · CC BY-SA 4.0

Do I understand correctly that for TTL it will look like this:

iptables -t mangle -A input -j TTL --ttl-set 30 ?

No. The -j TTL target is used to modify the IPv4 TTL header field.

You don't want to do that, you want to match on the TTL value (and packet size of 512 ) and then use the -j REJECT target to prohibit it.

You need to use matching modules for that:

iptables can use extended packet matching modules. These are loaded in two ways: implicitly, when -p or --protocol is specified, or with the -m or --match options, followed by the matching module name; after these, various extra command line options become available, depending on the specific module.
Source: man iptables

Simply activate the ttl matching module:

ttl

This module matches the time to live field in the IP header.
--ttl-eq ttl Matches the given TTL value.
--ttl-gt ttl Matches if TTL is greater than the given TTL value.
--ttl-lt ttl Matches if TTL is less than the given TTL value.
Source: man iptables

and the length matching module:

length

This module matches the length of a packet against a specific value or range of values. --length [!] length[:length]
Source: man iptables

So combine that and you get for example a rule along the lines of:

iptables -A INPUT --match length 513:65535  --match ttl --ttl-gt 30 -j REJECT  

or

 iptables -A INPUT --match length ! 1:512  --match ttl --ttl-gt 30 -j REJECT 

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-08-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。