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

nftables support string matching support

· 52CE 我爱测

Iptables can match packets by string. Example for dns: iptables -A INPUT -i eth0 -p udp --dport 53 -m string --hex-string "|09|proxypipe|03|net" --algo bm -j DROP How to perform such matching in nftables?

问题原文

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

Iptables can match packets by string.

Example for dns:

iptables -A INPUT -i eth0 -p udp --dport 53 -m string --hex-string "|09|proxypipe|03|net" --algo bm -j DROP

How to perform such matching in nftables?

已采纳解答

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

With nftables, you can use Raw Payload Expression syntax (documented here) to match a packet based on the contents of a chunk of bits.

So, a rule to block queries for proxypipe.net would look like this:

meta l4proto udp udp dport 53 @th,160,120 0x0970726f787970697065036e657400 counter drop comment "block queries for proxypipe.net"

The above would grab 120 bits worth of data, starting from bit 160 of the transport header (@th), and compare them to the hex equivalent of |09|proxypipe|03|net

Note that unlike the iptables version, the above would only match proxypipe.net at a fixed position in the packet. This means that it wouldn't block foobar.proxypipe.net or any other subomains.

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

资料来源与适用范围

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

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

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