从一个范围到另一个范围的 iptables 目标 NAT

Mil*_* R. 3 networking linux iptables linux-networking

我试图使目标 NAT 从一个范围 (192.168.2.0/24) 到另一个范围 (192.168.1.0/24) 中的相应 IP 地址。

我已经设法通过 ip 执行此 ip

iptables -t nat -A PREROUTING -i ppp0 -d 192.168.2.1 -p all -j DNAT --to-destination 192.168.1.1
iptables -t nat -A PREROUTING -i ppp0 -d 192.168.2.2 -p all -j DNAT --to-destination 192.168.1.2
iptables -t nat -A PREROUTING -i ppp0 -d 192.168.2.3 -p all -j DNAT --to-destination 192.168.1.3
etc..
Run Code Online (Sandbox Code Playgroud)

有什么方法可以在单行中指定源和目标范围?

谢谢!

Icu*_*Icu 5

你应该试试这个:

iptables -t nat -A PREROUTING -i ppp0 -d 192.168.2.0/24 -j NETMAP --to 192.168.1.0/24
Run Code Online (Sandbox Code Playgroud)


以下参考资料可能对您有所帮助:

iptables 大规模 1:1 NAT

http://www.netfilter.org/documentation/HOWTO/netfilter-extensions-HOWTO-4.html