许多常见的防火墙规则包括许多阻止特定入站流量的行。以 ipfw 为例:
# Fragments
$cmd 00420 deny all from any to any frag in via $pif
# ACK packets that did not match the dynamic rule table
$cmd 00430 deny tcp from any to any established in via $pif
Run Code Online (Sandbox Code Playgroud)
然而,最后,通常会阻止任何不符合任何规则的内容:
# Deny any other inbound traffic, with logging
$cmd 00998 deny log all from any to any in via $pif
# Deny any other traffic, with logging
$cmd 00999 deny log all from any to any
Run Code Online (Sandbox Code Playgroud)
如果我们无论如何都要阻止所有其他流量,如上所示,包含第一组规则将如何带来任何好处?
我不能说话ipfw,但iptables它很有意义,因为第一场决定性比赛获胜,并且通常在顶部的明确拒绝和底部的全面拒绝之间存在宽松规则(除非您正在构建一个非常,非常安静的设备!)。
因此,例如,如果您明确要排除所有火星人,则需要像这样的行
iptables -A INPUT -s 10.0.0.0/8 -j DROP
iptables -A INPUT -s 172.16.0.0/12 -j DROP
iptables -A INPUT -s 192.168.0.0/16 -j DROP
Run Code Online (Sandbox Code Playgroud)
前线喜欢
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -j DROP
Run Code Online (Sandbox Code Playgroud)
因为否则 ssh 的 ACCEPT 行将允许火星人在他们看到毯子拒绝之前。
感谢 Michael Hampton 确立了同样的逻辑适用于ipfw规则集。