Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

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 192.168.0.0/24 and the nat box has this network on eth1:

iptables -t nat -A POSTROUTING -o eth1 -s 192.168.0.0/24 -d 192.168.0.0/24 -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
add comment

Your Answer

 
discard

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.