Linux – iptables destination NAT from one range to another

iptableslinuxlinux-networkingnetworking

I am trying to make destination NAT from one range (192.168.2.0/24) to corresponding ip addresses in another range (192.168.1.0/24).

I have managed to do this ip by 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..

Is any way that I can specify source & destination range in single line ?

Thanks!

Best Answer

You should try this:

iptables -t nat -A PREROUTING -i ppp0 -d 192.168.2.0/24 -j NETMAP --to 192.168.1.0/24


The following references may help you:

Iptables massive 1:1 NAT

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