问题原文
原帖链接 · hgl · CC BY-SA 4.0
The man page of iptables says that if a rule does match, then the next rule is specified by the value of the target.
So if I have two rules like this:
iptables -t mangle -I FORWARD -s 192.168.1.10 -j DROP
iptables -t mangle -I FORWARD -s 192.168.1.10 -j MARK --set-mark
I expect that since MARK rule is matched first and specifies the final target, the DROP rule is never consulted. But in realty, it is and the packets are dropped.
However, if the rules are
iptables -t mangle -I FORWARD -s 192.168.1.10 -j DROP
iptables -t mangle -I FORWARD -s 192.168.1.10 -j ACCEPT
Then the DROP rule is never consulted because the ACCEPT rule short-circuited it.
Is it the case that only the special targets like ACCEPT, DROP prevent iptables from keep looking for the next rule? But I don't see it mentioned anywhere in the man page, did I miss something?
已采纳解答
原帖链接 · Tero Kilkanen · CC BY-SA 4.0
There are two kinds of targets in IPTables chains: Terminating and Non-terminating targets.
ACCEPT, REJECT, DROP are terminating targets. They terminate processing of the packet in the current Netfilter hook.
MARK, LOG and many others are non-terminating targets. They create some action based on the packet, and then proceed to the next rule.
In your example, -j MARK is the first rule in the chain. It marks the packet, and then moves to next rule, which drops the packet.
If you want to mark and accept the packet, then you need something like:
iptables -t mangle -A FORWARD -s 192.168.1.10 -j MARK --set-mark 0x1
iptables -t mangle -A FORWARD -s 192.168.1.10 -m mark ! --mark 0x1 -j DROP
Also, it is not a recommended practice to DROP packets in the mangle table.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
