無法存取區域網路內的網站。 nftables 中的 NAT 髮夾

無法存取區域網路內的網站。 nftables 中的 NAT 髮夾

我正在嘗試讓 NAT 髮夾在我的路由器上工作。我無法存取 LAN 上的本地網站主機 (192.168.1.3)。我使用 nftables 進行以下設定:

enp1s0 = 廣域網 enp2s0 = 區域網

#!/sbin/nft -f
flush ruleset
table ip nat {
        chain prerouting {
                type nat hook prerouting priority -100; policy accept;
                iifname "enp1s0" tcp dport { 80, 443 } dnat to 192.168.1.3
                meta nftrace set 1
        }

        chain postrouting {
                type nat hook postrouting priority 100; policy accept;
                ip saddr 192.168.1.0/24 ip daddr 192.168.1.3 tcp dport { http, https } counter snat 192.168.1.1
                oifname "enp1s0" masquerade
                meta nftrace set 1
        }
}

我到底要怎麼樣才能讓髮夾發揮作用?我看過有人使用拆分 DNS,但我不太確定如何設定。

答案1

要在 nftables 中進行 NAT Hairpinning,您可以新增 DNAT 規則,該規則檢查套件的目標位址是否是您網路的外部 IP。您還需要在內部介面 (LAN) 上進行偽裝。

flush ruleset

define wan = enp1s0
define lan = enp2s0

define webserver = 192.168.1.3
define extip = 1.2.3.4

table ip nat {
        chain prerouting {
                type nat hook prerouting priority dstnat; policy accept;
                tcp dport { 80, 443 } ip daddr $extip dnat to $webserver
        }

        chain postrouting {
                type nat hook postrouting priority srcnat; policy accept;
                oif $wan masquerade
                oif $lan masquerade
        }
}

相關內容