通过中间服务器访问其他服务器的端口(iptables)

通过 88.88.20.15 的 3300 端口访问 80.80.99.3 的 3306 端口,在 88.88.20.15 上设置:

sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 3300 -j DNAT --to-destination 80.80.99.3:3306
iptables -t nat -A POSTROUTING -p tcp -d 80.80.99.3 --dport 3306 -j SNAT --to-source 88.88.20.15

在88.88.20.15 上设置设置完成之后,就可以在其他能ping通(88.88.20.15 )的服务器访问80.80.99.3 的 3306 端口。

 

比如:88.88.20.16访问80.80.99.3:3306是无法访问的。但是现在可以通过88.88.20.16访问88.88.20.15的3300来访问。

mysql -uroot -p111111 -h88.88.20.15 -P3300 就可以访问80.80.99.3的mysql了。

 

 

通过以下命令可以查看情况。

iptables -t nat -nL

  

posted @ 2020-04-02 17:43  singsong~  阅读(580)  评论(0编辑  收藏  举报