来自 2 个子网的 Iptables 欺骗

Kri*_*iss 3 iptables

我有来自 2 个子网的数据包进入我的防火墙 eth1:

10.111.12.0/24 和 10.10.100.0/24

我这样设置 iptables 规则:

 iptables -A INPUT -i eth1 ! -s 10.111.12.0/24 -j DROP
 iptables -A INPUT -i eth1 ! -s 10.10.100.0/24 -j DROP
Run Code Online (Sandbox Code Playgroud)

但是 - 第一个规则不允许检查第二个规则,因为 10.10.100.0/24 不是 10.111.12.0/24 并且它与第一个规则匹配。如何修复它?

Zor*_*che 5

链在这里将是一个有用的方法。链的作用有点像子例程或函数。RETURN 只是意味着对该数据包的控制将返回到之前的链,并且规则将继续被评估。

# create a new chain
iptables -t filter -N in_validnet

# all incoming packets on eth1 are evaluated by the chain
iptables -t filter -A INPUT -i eth1 -j in_validnet

# packets from these networks are returned for further evaluation
iptables -A in_validnet -s 10.111.12.0/24 -j RETURN
iptables -A in_validnet -s 10.10.100.0/24 -j RETURN

# everything else gets dropped
iptables -A in_validnet -j DROP
Run Code Online (Sandbox Code Playgroud)