Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 have a range of ip addresses ( that I want to redirect all outgoing http traffic to an internal webserver. So if someone in that range tried to access any site, the html from my webserver would be returned instead. However, I only want to affect that ip range. What iptables rules do I need on my router to make this happen?

share|improve this question
up vote 3 down vote accepted

You can use the iprange module to match a range of addresses. You want to DNAT the packets to your webserver.

iptables --table nat --append PREROUTING --match iprange --src-range --protocol tcp --dport 80 --jump DNAT --to-destination
share|improve this answer
Thanks for the response. It worked for me with one modification; "" should be "". Other wise it blocked a much broader range of ips. – Daniel Jul 30 '12 at 14:28

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.