一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Centos中IPTABLES 端口映射的例子

时间:2016-08-21 编辑:简简单单 来源:一聚教程网

我们现在有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了

热门栏目