-
网络环境
公网服务器:
内网IP:ens33: 192.168.33.1
外网IP:ens38:192.168.3.138
内网机器:
内网IP:192.168.33.20
-
通过外网IP+端口(8082)实现到内网机器的22端口(ssh服务)的的访问
iptables -t nat -A POSTROUTING -d 192.168.33.20 -p tcp --dport 22 -j SNAT --to-source 192.168.3.138
iptables -t nat -D POSTROUTING -d 192.168.33.20 -p tcp --dport 22 -j SNAT --to-source 192.168.33.1
-
尝试连接
在公网上一台机器:IP:192.168.3.134
ssh 192.168.3.138 -p 8082
成功连接 -
端口转发
来自8888的都转到22
iptables -t nat -A PREROUTING -p tcp -d 192.168.3.138 --dport 8888 -j DNAT --to-destination 192.168.3.138:22
同样可以通过
ssh 192.168.3.138 -p 8888
连接上ssh
iptables实现端口转发
最新推荐文章于 2023-12-21 16:22:34 发布