Linux使用firewalld转发数据

以Debian为例

sudo apt install firewalld
systemctl enable firewalld
systemctl start firewalld
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf
sysctl -p
firewall-cmd --permanent --add-masquerade

添加转发内容

22是要转发目标服务器的端口,80是当前服务器的端口
firewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toaddr=127.0.0.1:toport=22
firewall-cmd --permanent --add-forward-port=port=80:proto=udp:toaddr=127.0.0.1:toport=22
firewall-cmd --reload