我必须连接两个 LAN:LAN1:10.10.0.0/16 和 LAN2:192.168.0.0/16。我做不了简单的路由,因为192.168.0.0/16 net在LAN1是被禁止的,所以想着用Full con nat (1:1)把192.168.xy/16翻译成10.11.xy/16。每次翻译都是按照这个规则完成的:
iptables -t nat -A PREROUTING -d 10.11.0.0/16 -j DNAT --to-destination 192.168.0.0/16
iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -j SNAT --to-source 10.11.0.0/16
Run Code Online (Sandbox Code Playgroud)
但是我将不得不输入 254*254*2 的规则,我认为这会导致巨大的性能下降。那么,有没有办法用最少的规则来编写这种一对一的翻译?
Zor*_*che 15
我不确定它是否存在于所有内核中,但您可能正在寻找的是NETMAP目标。
NETMAP
This target allows you to statically map a whole network of
addresses onto another network of addresses. It can only be
used from rules in the nat table.
--to address[/mask]
Network address to map to. The resulting address will be
constructed in the following way: All 'one' bits in the
mask are filled in from the new 'address'. All bits that
are zero in the mask are filled in from the original
address.
Run Code Online (Sandbox Code Playgroud)
小智 9
就像第一个答案所说的,使用 -j NETMAP:
# iptables -t nat -A PREROUTING -d 10.11.0.0/16 -j NETMAP --to 192.168.0.0/16
# iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -j NETMAP --to 10.11.0.0/16
Run Code Online (Sandbox Code Playgroud)
在 POSTROUTING 行中添加 -d 10.10.0.0/16 可能也是个好主意。
您可以使用一个小的 shell 脚本来完成此操作
#!/bin/bash
for (( i=0 ; $i<256 ; i=$i+1 )) ; do
for (( j=0 ; $j<256 ; j=$j+1 )) ; do
iptables -t nat -A PREROUTING -d 10.11.$i.$j/16 -j DNAT --to-destination 192.168.$i.$j/16
iptables -t nat -A POSTROUTING -s 192.168.$i.$j/16 -j SNAT --to-source 10.11.$i.$j/16
done
done
Run Code Online (Sandbox Code Playgroud)
但我认为有一个错误。我认为应该是/32而不是/16。
归档时间: |
|
查看次数: |
11653 次 |
最近记录: |