免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1198 | 回复: 0
打印 上一主题 下一主题

做Double NAT的一种可行方法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-08-11 23:11 |只看该作者 |倒序浏览
当两个子网通过NAT网关相连,而且子网与子网又有ip重叠的话,你该怎么办呢?Double NAT可以解决这个问题,但记住这个方法是Hacker-Style的——怪异却工作的方法。
  • 看如下的情形:
Network 1
        192.168.150.0 (Corporate)
       --------------/-------------------------
        Network 2
        192.168.150.0 (Untrusted Network)
怎么连接这两个子网呢?注意到,他们的网段是重叠的。
  • 首先,从两网段各抽出一台机器做NAT网关,情形如下:
Network 1
        192.168.150.0 (Corp)
                         |
        Network 2        |
        192.168.180.0 (Intermediate)
                                |
                NAT BOX 1       |
                eth0 192.168.180.180
                eth1 10.15.15.1
                            |
                NAT BOX 2   |
                eth0 10.15.15.2
                eth1 192.168.150.252
                                |
        Newtwork 3              |
        192.168.150.0 (Untrusted Network)
  • 现在开始配置。

在NAT BOX 1, 给eth0建立三个别名.
        ifconfig eth0:0 192.168.180.181 netmask 255.255.255.0
        ifconfig eth0:1 192.168.180.182 netmask 255.255.255.0
        ifconfig eth0:2 192.168.180.183 netmask 255.255.255.0
NAT BOX 2也是。
        ifconfig eth0:0 10.15.15.181 netmask 255.255.255.0
        ifconfig eth0:1 10.15.15.182 netmask 255.255.255.0
        ifconfig eth0:2 10.15.15.183 netmask 255.255.255.0
接下来给出iptables的,你一看应该就会明白了:
在NAT BOX 1給eth0做三个DNAT:
        iptables -t nat -A PREROUTING -d 192.168.180.181 -i eth0
                -j DNAT --to-destination 10.15.15.181
        iptables -t nat -A PREROUTING -d 192.168.181.182 -i eth0
                -j DNAT --to-destination 10.15.15.182
        iptables -t nat -A PREROUTING -d 192.168.181.183 -i eth0
                -j DNAT --to-destination 10.15.15.183
还有一个SNAT:
        iptables -A POSTROUTING -s 192.168.150.0/255.255.255.0
                -d 10.15.15.0/255.255.255.0 -j SNAT -o eth1
                --to-source 10.15.15.1
网段2也类似
        iptables -t nat -A PREROUTING -d 10.15.15.181 -i eth0
                -j DNAT --to-destination 192.168.150.10
        iptables -t nat -A PREROUTING -d 10.15.15.182 -i eth0
                -j DNAT --to-destination 192.168.150.11
        iptables -t nat -A PREROUTING -d 10.15.15.183 -i eth0
                -j DNAT --to-destination 192.168.150.12
        iptables -A POSTROUTING -s 10.15.15.0/24
                -d 192.168.150.0/24 -j SNAT -o eth1
                --to-source 192.168.150.252
好了,现在目的是达到了,但缺点很明显的——维护起来太麻烦了。呵呵,我说过的这是Haker-Style的解决办法。


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8057/showart_41137.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP