做Double NAT的一种可行方法

当两个子网通过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的解决办法。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值