I have two network adapters that use the same ip range, but are different networks.

I tried this but it didn't work:

iptables -t nat -A OUTPUT -p all -d -j DNAT --to-destination -o eth0
iptables -t nat -A OUTPUT -p all -d -j DNAT --to-destination -o eth1


eth0 has the ip of on a network with the range 192.168.0.*

eth1 has the ip of on a separate network with the range 192.168.0.*

1.2.3.* = 192.168.0.* through eth1

3.2.1.* = 192.168.0.* through eth0

Is this something I can do with iptables?


Your question is not clear, but assuming you want to route your traffic to one NIC and to another than you need to update you routing table using route command.

Example :

route add -net netmask dev eth1
route add -net netmask dev eth0
|improve this answer|||||
  • This won't do what the OP seems to want. He wants a way to use NAT so that he can reach two different machines, both themselves numbered, with different IP addresses as seen from his machine. – David Schwartz Nov 5 '11 at 18:59
  • "both themselves numbered" where does it say that? – Andrey Nov 5 '11 at 19:02
  • That was just an example. I picked 50 arbitrarily to try to explain what I mean. He has two networks that both use the same IP address range, and he wants to remap those addresses into distinct IP ranges as seen from his machine. That's why he's using NAT. – David Schwartz Nov 5 '11 at 19:05
  • What I understand is that he has two physical LANs that are connected to his machine via two separate NICs. Each LAN has IP addressing. If this correct? – Andrey Nov 5 '11 at 19:05
  • Yes. So that means that could mean two different machines. He wants to be able to access both of them, one as and the other as -- that's why he's using DNAT. – David Schwartz Nov 5 '11 at 19:09

You would either have to write code specifically to do this or add 512 individual NAT rules. The DNAT module treats multiple IPs as a round-robin, not a mapping.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.