温馨提示×

debian nftables能进行端口转发吗

小樊
100
2024-12-31 19:04:28
栏目: 智能运维
Debian服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

是的,Debian上的nftables可以进行端口转发

sudo nft add table ip nat
sudo nft add rule ip nat prerouting { type nat hook prerouting priority -100; }
sudo nft add rule ip nat postrouting { type nat hook postrouting priority 100; }
sudo nft add rule ip nat prerouting iif eth0 tcp dport 80 dnat to 192.168.1.100:80
sudo nft add rule ip nat postrouting oif eth0 ip saddr 192.168.1.100 tcp dnat to 192.168.1.2:80

这里,我们首先创建了一个名为nat的表,然后添加了两个规则:一个用于预路由(prerouting),另一个用于后路由(postrouting)。接下来,我们为预路由规则添加了源接口eth0,将外部端口80的流量转发到内部IP地址192.168.1.100的端口80。最后,我们为后路由规则添加了目标接口eth0,将内部IP地址192.168.1.100的端口80的流量转发到外部IP地址192.168.1.2的端口80。

请注意,这些示例规则可能需要根据您的网络环境进行调整。您可能需要安装nftables软件包并确保内核支持nftables

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:debian nftables支持哪些功能

0