Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to redirect traffic from one IP reached on a specific port to a website. For example I have two external ips, lets say and set on one network card as - eth0 and -eth0:1 mywebsite.com allows access only from and I want to set my rules like if I hit to open mywebsite.com trough

Thanks in advance!

share|improve this question

1 Answer 1

Something like this?

iptables -t nat -A PREROUTING -p tcp -i eth0 --dst --dport 8080 -j REDIRECT --to-ports 80

Though I'm not sure if that's what you really want.

I think what you actually want would be to set up a rewrite on the web server running on to 301 redirect to, which is a question that will depend on what kind of software you're running on

Also, if you want traffic only on, why bother exposing at all?

Please clarify the problem, rather than asking for details on how to implement your (possibly suboptimal) solution.

share|improve this answer
Thanks for the answer cjc. Basically what I want is: mywebsite.com is accessible only from and I want to be able to connect to specific port to that or other IP on the same server and see the website. Kind of proxy but I want to avoid squid and just use IPtables –  Anthony Apr 7 '12 at 14:21
You don't need Squid. You can run a reverse proxy using most web server software, which will do what you want, and is the more "standard" solution. Google for "reverse proxy" with whatever software you're using, and then block access on that other IP. –  cjc Apr 7 '12 at 15:20

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.