Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a server functioning as my nat that hosts some services. When I locally connect via UDP to this server it my client uses the public ip but the server answers with its local ip.

So the question is: How can I force all traffic that is directed to the public ip to be routed through the NAT too?

Or is there some even simpler method to achieve the conversation taking place on the public ip (without letting the traffic "leak" out into the public)

share|improve this question
up vote 2 down vote accepted

You have to add a MASQUERADE rule for this traffic on the nat box. This makes it so that traffic to any of the DNAT services will appear to come from the nat box. That way when the DNAT service replies, the traffic goes back to the nat box so it can be properly sent back to the client (with the correct source IP address).

For example, if your private network were and the nat box has this network on eth1:

iptables -t nat -A POSTROUTING -o eth1 -s -d -j MASQUERADE

(You could use SNAT instead of MASQUERADE, either works)

share|improve this answer
Thank you for this. For now I used SNAT. – Nobody Apr 8 '12 at 11:18

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.