我在 Podman 容器中运行 WireGuard。我有一个像这样的 Hub and Spoke 配置
Client A <--> Hub <--> Client B
|
|
Internet
这是目前 Hub 上的 WireGuard 配置
[Interface]
PrivateKey = ...
Address = 10.8.0.1/24, fdcc:ad94:bacf:61a4::cafe:1/112
ListenPort = 51820
MTU = 1420
PostUp = iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE; iptables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT; iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; ip6tables -t nat -A POSTROUTING -s fdcc:ad94:bacf:61a4::cafe:0/112 -o eth0 -j MASQUERADE; ip6tables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT; ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -A FORWARD -o wg0 -j ACCEPT;
PostDown = iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE; iptables -D INPUT -p udp -m udp --dport 51820 -j ACCEPT; iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; ip6tables -t nat -D POSTROUTING -s fdcc:ad94:bacf:61a4::cafe:0/112 -o eth0 -j MASQUERADE; ip6tables -D INPUT -p udp -m udp --dport 51820 -j ACCEPT; ip6tables -D FORWARD -i wg0 -j ACCEPT; ip6tables -D FORWARD -o wg0 -j ACCEPT;
# Client A
[Peer]
PublicKey = hcU3LDJmlsInRSDFErt+Kp2CZBRzSggvmfOkSKcGx1A=
PresharedKey = ...
AllowedIPs = 10.8.0.2/32, fdcc:ad94:bacf:61a4::cafe:2/128
但是因为 Hub 在 OCI 上运行的是 AlmaLinux 9.5,所以我不得不将 iptables 设置为使用 iptables-legacy。
现在我正尝试迁移到 nftables
这是新的配置
[Interface]
...
PostUp = nft add table inet wg_table; nft add chain inet wg_table postrouting { type nat hook postrouting priority 100 \; }; nft add rule inet wg_table postrouting ip saddr 10.8.0.0/24 oifname eth0 masquerade; nft add rule inet wg_table postrouting ip6 saddr fdcc:ad94:bacf:61a4::cafe:0/112 oifname eth0 masquerade; nft add chain inet wg_table input { type filter hook input priority 0 \; policy accept \; }; nft add rule inet wg_table input udp dport 51820 accept; nft add chain inet wg_table forward { type filter hook forward priority 0 \; policy accept \; }; nft add rule inet wg_table forward iifname "wg0" accept; nft add rule inet wg_table forward oifname "wg0" accept;
PostDown = nft delete table inet wg_table
...
我尝试暂时保持接近原始 iptables 规则。
但是用我的手机却不行,我无法用新规则连接到互联网。即使使用 iptables-nft 也不起作用