NFTABLE 问题:IPv6 的行为与具有镜像配置的 IPv4 不同

Ric*_*ain 4 networking firewall iptables ipv6 nftables

我的服务器上的 IPv6 存在问题。我将 nginx 配置为侦听 IPv4 和 IPv6 的端口 443。它效果很好:我的网站可以通过启用了 TLS 的 Internet 访问。

当我激活 nftables 时,事情变得复杂:当我从 IPv4 访问我的网站时,它可以工作,但当我从 IPv6 连接访问它时,超时:(

输出sudo nft list ruleset

table inet filter {
        chain INPUT {
                type filter hook input priority filter; policy drop;
                meta nftrace set 1
                ct state established,related accept comment "allow established connections"
                iif "lo" accept comment "allow all from localhost"
                iif != "lo" ip daddr 127.0.0.0/8 counter packets 0 bytes 0 drop comment "drop connections to loopback not coming from loopback"
                iif != "lo" ip6 daddr ::1 counter packets 0 bytes 0 drop comment "drop connections to loopback not coming from loopback"
                iifname "tunnel0" accept comment "allow all from VPN"
                udp dport 12345 accept comment "allow VPN on port 12345"
                tcp dport { 22, 80, 443 } accept comment "allow HTTP, HTTPS and SSH on classic ports"
        }

        chain OUTPUT {
                type filter hook output priority filter; policy accept;
        }

        chain FORWARD {
                type filter hook forward priority filter; policy drop;
        }
}
Run Code Online (Sandbox Code Playgroud)

输出sudo nft monitor trace | grep 443

trace id 76d7cb1a inet filter INPUT packet: iif "eth0" ether saddr AA:AA:AA:AA:AA:AA ether daddr BB:BB:BB:BB:BB:BB ip6 saddr 2a01:cb09:804b:cd61:CCCC:CCCC:CCCC:CCCC ip6 daddr 2001:CCCC:CCCC:CCCC::CCCC ip6 dscp cs0 ip6 ecn not-ect ip6 hoplimit 45 ip6 flowlabel 0 ip6 nexthdr tcp ip6 length 40 tcp sport 53184 tcp dport 443 tcp flags == syn tcp window 22240
Run Code Online (Sandbox Code Playgroud)

请注意,我在端口 22 上使用 ssh 时没有出现此问题。我nftables v0.9.8 (E.D.S.)在 Debian 11 上运行。

我几乎花了一天时间寻找解决方案。欢迎任何帮助!感谢

A.B*_*A.B 5

ICMPv6是基于IPv6的协议,通过组播和单播实现链路层解析。丢弃 ICMPv6 意味着不再有可用的解决方案:节点无法找到同一 LAN 中的其他节点。这包括上游 IPv6 路由器,如果 ICMPv6 被丢弃,则上游 IPv6 路由器将无法使用 IPv6 与 Linux 系统进行通信。

相比之下,IPv4 依赖于不同的协议:ARP(使用广播和单播),该协议不基于 IPv4。因此,我们可以丢弃所有 ICMP,并且不会遇到 LAN 连接问题,因为 ARP 不受影响(但在丢弃所有 ICMP 时,仍然可能会遇到PMTU 黑洞和其他类似问题,尤其是在使用隧道时)。

因此,首先启用所有 ICMPv6,然后,一旦您验证 IPv6 再次工作,如果您不想启用所有 ICMPv6,请检查在邻居发现协议中选择性接受的内容(对于非路由节点)我想说至少类型 134、135、136 和 137):

nft add rule inet filter INPUT 'icmpv6 type { 134, 135, 136, 137 } accept'
Run Code Online (Sandbox Code Playgroud)