Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
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 '13 at 16:17
add comment

1 Answer

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/

share|improve this answer
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 '13 at 20:45
I have to add is working fine (used DNAT for it), but works only for outgoing traffic. –  Kaemmelot Jul 29 '13 at 21:00
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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