My purpose is to NAT (translate) all IP addresses that reach eth0 on all ports and protocols this way: 192.168.55.x -> 192.168.42.x (I have ip forwarding enabled and 192.168.42.0/24 subnetwork is on eth1). I can do this for one host per pair of lines like this, for example with x=20:
iptables -t nat -A PREROUTING -i eth0 -d 192.168.55.20 -j DNAT --to 192.168.42.20
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.42.20 -j SNAT --to 192.168.55.20
But I cannot find a way to translate all 253 possible hosts. I tried this:
iptables -t nat -A PREROUTING -i eth0 -d 192.168.55.0/24 -j DNAT --to 192.168.42.0-192.168.42.255
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.42.20/24 -j SNAT --to 192.168.55.0-192-168.55.255
This results in a random host translation. Useful for load balancing. But how to get a plain one-to-one translation?
Thank you.