I'm looking for a way how to nat 2 or more inner IPs (in my case xen doms) to one outer IP.
I tried to use

iptables -t nat -A PREROUTING -d -j DNAT --to --to
iptables -t nat -A POSTROUTING -s -j SNAT --to
iptables -t nat -A POSTROUTING -s -j SNAT --to

And got an error:

iptables v1.4.14: DNAT: Multiple --to-destination not supported
Try `iptables -h' or 'iptables --help' for more information.

I found this in the manpage:

Later Kernels (>= 2.6.11-rc1) don't have the ability to NAT to multiple ranges anymore.

So my question is: Why is it not possible anymore and is there a workaround? Maybe I should use an other method I don't know yet?

The idea is to use the system like a router, so I have one address but multiple users behind. The problem is I don't know which connection reffers to a user (for example But I know, they all have different ports open for incomming traffic.
So my solution (for DNAT) would be to nat all incoming connections to all users and filter all unused ports, so the connection goes to one single user. For outgoing traffic I would use

iptables -A FORWARD -i eth0 -d -m state --state ESTABLISHED,RELATED -j ACCEPT

  • 1
    I don't understand what you're trying to do. NAT isn't for load balancing, why would you possibly DNAT one public IP to multiple internal ones? Your SNAT rules would work fine for outgoing traffic, but I don't get how incoming traffic would be handled in the scenario your envision.
    – gparent
    Jul 27, 2013 at 16:17

2 Answers 2


You can't do 1-to-1 NAT with only 1 outside IP address when you're working with 2 internal hosts. The reason is because the firewall will never have a true destination for outside source connections, unless one of the internal hosts is down. In this case, you would require 2 iptables rules to provide round-robin functionality:

$ipt -t nat -A PREROUTING -s $srcip -d $wanip -j DNAT --to
$ipt -t nat -A PREROUTING -s $srcip -d $wanip -j DNAT --to

Also, your "DNAT: Multiple --to-destination not supported" error comes from the capability of specifying more than 1 DNAT destination being removed from the version you're running (v1.4.14). This functionality was removed in favor of the round-robin functionality.

If you want to allow multiple hosts a connection to the internet, you must use the POSTROUTING chain of the NAT table as follows:

$ipt -t nat -A POSTROUTING -o $wanif -s $lan_network -j MASQUERADE

MASQUERADE is used with dynamic IP configurations. For static IP, use SNAT in place of MASQUERADE:

$ipt -t nat -A POSTROUTING -o $wanif -s $lan_network -j SNAT --to $wanip

This will not, however, make the open ports on your internal hosts available to the outside world. DNAT is used for outside->inside and SNAT is used for inside->outside for basic scenarios like yours.

  • It has been quite a while now and even though this answer came too late for me, it was basically this idea that led me find the solution I looked for.I will therefore mark this as answer. Thanks.
    – Kaemmelot
    Oct 22, 2016 at 23:33

You could try to play with TEE target, that available via xtables-addons - http://xtables-addons.sourceforge.net/modules.php

To copy (duplicate) all traffic from and to a local ECHO server to a second box (nonfinal target)

# iptables -A PREROUTING -t mangle -p tcp --dport 7 -j TEE --gateway --tee
# iptables -A POSTROUTING -t mangle -p tcp --sport 7 -j TEE --gateway --tee

Also you can try http://code.google.com/p/port-mirroring/

  • I tried this, but it does not seem to work properly. I tried iptables -t mangle -A PREROUTING -i eth0 -d -j TEE --gateway Any idea what is wrong?
    – Kaemmelot
    Jul 29, 2013 at 20:45
  • I have to add is working fine (used DNAT for it), but works only for outgoing traffic.
    – Kaemmelot
    Jul 29, 2013 at 21:00

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.