nftables 如何将 eth0 接口的流量通过 192.168.100.1:1080 转发?-灵析社区

001

我在 192.168.100.1:1080 上有一个代理,可以转发流量,我知道使用: iptables -t nat -A PREROUTING -i eth0 -j DNAT --to 192.168.100.1:1080 iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 可以将 eth0 的流量转发到 192.168.100.1:1080,但是我使用 nftables 却无法实现,测试了 iptables-translate 等工具也不行。 我期望的结果是,将 eth0 的所有流量通过 192.168.100.1:1080 代理转发。 请问我如何通过 nftables 实现上述需求? 注:192.168.100.1 不会走 eth0,假设要是走 eth0,需要排除 192.168.100.1 的转发。

阅读量:232

点赞量:14

问AI
nft add table inet nat nft add chain inet nat prerouting { type nat hook prerouting priority 0 \; } nft add chain inet nat postrouting { type nat hook postrouting priority 100 \; } nft add set inet nat exclude_ips { type ipv4_addr; flags interval; } nft add element inet nat exclude_ips { 192.168.100.1 } nft add rule inet nat prerouting iif "eth0" tcp daddr != @exclude_ips dnat 192.168.100.1:1080 nft add rule inet nat postrouting oif "eth0" masquerade