Thanks to quanta, I can now use iptables to port forward SSH through to servers behind the firewall using a single IP and multiple ports - original question here.

However, if I use this technique to port forward http traffic to an Apache server outside the firewall's LAN, the IP that gets stamped in Apache's log is the firewall's, not the IP of the PC that made the original request.

Is there any was to change this, or is there another field I need in the Apache log to capture this information?


You need a Layer 4 device (such as squid, apache in proxy mode, or a dedicated load balancer such as an F5 or Netscaler) if you want information about the original host making the request. If you do a straight NAT translation, then all requests will appear (correctly) to be from the host with the public IP address that is connecting to the server.

A Layer 4 device or server can add either a Via:, X-Forwarded-For:, or other arbitrary header to the HTTP request to the server. The server can then (if it desires) use that information about the original client. Netscaler(Citrix) publishes an Apache plugin which allows you to rewrite the apache request with the value of said arbitrary HTTP header, for example.

See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more information about the Via: header and what actual information is attached.

  • Thanks for the speedy response. So if I want my analytics box to get accurate logs, I either need to give it a public IP (thus avoiding the port forwarding issue) or sit it behind Varnish along with the main website servers (which'll handle X-Forwarded-For). Makes sense. Thanks again. – jetboy Nov 1 '11 at 22:50

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.