Networking

NFTABLE 問題:IPv6 的行為與具有鏡像配置的 IPv4 不同

  • March 10, 2022

我的伺服器上有 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;
       }
}

輸出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

注意我在埠 22 上的 ssh 沒有這個問題。我nftables v0.9.8 (E.D.S.)在 Debian 11 上執行。

我幾乎花了一天時間尋找解決方案。歡迎任何幫助!謝謝

ICMPv6 是基於 IPv6 的協議,使用多播和單播實現鏈路層解析。放棄 ICMPv6 意味著不再有可用的解決方案:節點無法在同一 LAN 中找到其他節點。這包括上游 IPv6 路由器,如果 ICMPv6 被丟棄,它將無法使用 IPv6 與 Linux 系統通信。

相比之下,IPv4 依賴於不同的協議:ARP(使用廣播和單播),它不是基於 IPv4 的。因此,由於 ARP 不受影響,因此可以丟棄所有 ICMP 並且不會遇到 LAN 連接問題(但是在丟棄所有 ICMP 時,尤其是在使用隧道時,仍然可能會遇到PMTU 黑洞和其他類似問題)。

因此,首先啟用所有 ICMPv6,然後再次驗證 IPv6 是否再次正常工作,如果您不想啟用所有 ICMPv6,請檢查在鄰居發現協議中選擇性接受的內容(對於非路由節點我會說至少類型 134、135、136 和 137):

nft add rule inet filter INPUT 'icmpv6 type { 134, 135, 136, 137 } accept'

引用自:https://serverfault.com/questions/1078828