centos中iptables_Centos中IPTABLES 端口映射的例子

更新时间:2020-11-02    来源:php安装    手机版     字体:

【www.bbyears.com--php安装】

我们现在有2台服务器1台服务器有内外网IP, 另一台服务器只有内网IP, 想要访问内网的服务器就需要将内网的端口映射到外网上.

server 1:

外网IP 10.0.0.1
内网IP 20.0.0.1
server 2:

内网IP 20.0.0.2

我们现在需要将 server2的内网端口22映射到server1的外网端口30022上

首先我们清空现有的链表

$ iptables -F
$ iptables -X
$ iptables -Z

然后我们做端口映射

$ iptables -t nat PREROUTING -d 10.0.0.1 -p tcp --dport 30022 -j DNAT --to 20.0.0.2:22
$ iptables -t nat POSTROUTING -d 20.0.0.2 -p tcp --dport 22 -j SNAT --to 20.0.0.1
$ iptables save


现在我们可以通过 10.0.0.1 的 30022 端口来远程访问server2了

本文来源:http://www.bbyears.com/jiaocheng/108423.html

猜你感兴趣

热门标签

更多>>

本类排行