-1

I have a www.example.com with X.X.Y.Y ip i want to forward traffic from port 80 to the domain(www.example.com), I used the following iptable:

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination X.X.Y.Y:80

but i dont get good result because X.X.Y.Y content is not equal to the domain(www.example.com)
For ex: if you go to 198.252.206.16(the ip of serverfault) with your browser you will see that result and content of the address(ip address) is not equl www.serverfault.com.
I want to use domain in the above iptables rule, for ex:--to-destination www.example.com(its just an example and i know its not working), how can i do this?
Is there any alternative way to do that without using iptables?
Thank you

Carig
  • 1
  • 1
  • 2

3 Answers3

2

I think what you need is an HTTP proxy to do the rewriting of the request headers. IPTables doesn't parse the HTTP header and replace the domains in them.

You should look at something like Nginx, or Squid for doing that, just something that understands and rewrites the HTTP request headers into the domain that you want.

IPTables does not know any higher protocols than TCP or UDP.

replay
  • 3,180
  • 13
  • 16
  • very nice answer, so i have an alternative and i can use Http proxy like Squid proxy instead of iptables, that's right? – Carig Sep 03 '13 at 09:27
  • Yes. For rewriting the content of the HTTP headers you will have to use a proxy that is able to parse HTTP. IPTables cannot do that – replay Sep 03 '13 at 09:28
2

You cannot do it with iptables even if you use the -d option as the domain names are loaded during iptables startup. The right way to do what you want to do is to use a proxy server like Squid.

deppfx
  • 429
  • 3
  • 13
0

on your webserver do something like this:

 NameVirtualHost *:80
 <VirtualHost *:80>
   # The DNS1 site is hosted locally
   ServerName DNS1
   DocumentRoot /var/www./...
 </VirtualHost>

 <VirtualHost *:80>
   ServerName DNS2
   # Forward all requests to container:
   Proxypass / http://<container-ip>
   ProxypassReverse / http://<container-ip>
 </VirtualHost>
Mike Q
  • 163
  • 1
  • 4