Linux 隔离网段下端口转发

设备在隔离网段下,设置端口转发。使A设备可访问C设备的服务
Linux 隔离网段下端口转发_第1张图片

#!/bin/bash
#输出成绩脚本
echo -n "请输入外网服务器的IP地址:"
read score
sudo iptables -t nat -A PREROUTING -p tcp --dport 1883 -j DNAT --to-destination $score:1883
sudo iptables -t nat -A PREROUTING -p tcp --dport 7033 -j DNAT --to-destination $score:7033
sudo iptables -t nat -A PREROUTING -p tcp --dport 5500 -j DNAT --to-destination $score:5500
iptables -I FORWARD -i enp3s0 -j ACCEPT
iptables -I FORWARD -i enp2s0 -j ACCEPT
ufw allow 1883
ufw allow 7033
ufw allow 5500
iptables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o enp3s0 -j MASQUERADE
ufw status
sudo iptables -t nat -L -n
exit 0

你可能感兴趣的:(linux,服务器,网络)