Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 am doing NAT traffic forwarding using iptables ( => with the following commands:

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

It works fine except for one thing: If I check apache logs, doing firewall rules etc. on server, it looks like all traffic is comming from

Of course it makes a bit sense, since it is that is forwarding the traffic to, but I assumed NAT would pass the original IP "requestor" in the package?

Is there a way to make the traffic to have the "real" orignal IP?

Currently, it makes it very difficult to setup good firewall rules and other security stuff as ALL traffic seems to be comming from regardless what the original traffic is actually comming from.

share|improve this question
I did not understand your rules well. If you want to redirect the traffic destined to to be destined to, the first rule should be enough. In this case, you will see the original requester IP address. Using both rules, you are changing both the source and destination addresses!! – Khaled Jul 16 '13 at 10:43
Without the SNAT rule, traffic will never get back to the original client properly, so the DNAT by itself is insufficient. – John Jul 16 '13 at 12:03

Apache will never see the IP behind the NAT. The endpoint system,, doesn't know about anything outside of The only way to get the original requestor's IP is to embed some sort of javascript or client-side code that runs the equivalent of ipconfig or ifconfig on the client and hands that output off to the web server as part of a POST. This is generally frowned upon, however.

share|improve this answer
So you are basically saying that I cannot put any IP-based firewall rules on the server, as it will see ALL incomming traffic as – Daniele Testa Jul 16 '13 at 12:20
No, I'm saying you cannot put any NAT rules in place. It amounts to the same thing in practice, but the "firewall" rules blocking access to certain ports are different from "NAT" rules telling packets where to go. – John Jul 16 '13 at 12:24
After some digging around, this can not be true. Computers behind the NAT "router" should still see the requests comming in as from the original IP. – Daniele Testa Jul 16 '13 at 12:31
Ok, so how would "reserve proxy" iptable rules looks like that accomplishes this? I know NAT is usually used for outgoing traffic and I am trying to forward incomming traffic instead. Incomming traffic to should be forwarded to and the response comming from should, of course, be routed back to – Daniele Testa Jul 16 '13 at 12:34
What you want cannot be accomplished via iptables. A NAT router will always hide the external IP address. An outgoing NAT always hides internal addresses (e.g. a home network) and gives only the one public address you have from (as an example) AT&T to external web servers. That is how it works. Are there other, more complicated solutions that may give you what you want? I wouldn't be surprised. Are they worth the time to figure out? I don't think so. – John Jul 16 '13 at 12:37

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.