A服务器编辑 /etc/sysctl.conf 文件添加
net.ipv4.ip_forward = 1运行应用配置
sysctl -p安装iptables
apt install iptables设置A要转发规则 172.17.63.48为B服务器
iptables -t nat -A PREROUTING -p tcp --dport 40000:60000 -j DNAT --to-destination 172.17.63.48
iptables -t nat -A PREROUTING -p udp --dport 40000:60000 -j DNAT --to-destination 172.17.63.48
iptables -t nat -A POSTROUTING -d 172.17.63.48 -p tcp --dport 40000:60000 -j MASQUERADE
iptables -t nat -A POSTROUTING -d 172.17.63.48 -p udp --dport 40000:60000 -j MASQUERADE
保存规则
apt install iptables-persistent
netfilter-persistent save在B服务器上运行
iptables -A INPUT -p tcp --dport 40000:60000 -j ACCEPT
iptables -A INPUT -p udp --dport 40000:60000 -j ACCEPT即可