Linux – Routing requests from external hostnames to internal IP addresses in Ubuntu

hostnamelinuxnat;routerrouting

I want to host several websites using the same IP address. My ISP gives me one static IP address, however I have three different webservers (all running different sites) hooked up behind a cheap switch that all are ultimately behind this one IP address (I one is apache, and two are windows boxes, so I can't really consolidate them). I can do port forwarding with this switch based on port and incoming IP address, but not hostname. This isn't a long term solution since the only way to differentiate which webserver I'm trying to get to is via port. And that's ugly.

I also have a linux box with two network cards that I'm hoping to use as a more robust firewall/router. My question is – what is the best way to turn my linux box (running Xubuntu) in to a router that will be able to route based on host names and not just IP addresses? I want to leave Xubuntu on the box though, so no dedicated router linux distros please.

I looked at Shorewall, but I couldn't find a way to get it to route packets based on host name instead of IP address. Is IPTables the way to go? If so, could someone point me to a tutorial or something on how to do this? I googled and I was shocked that this is not a more commong scenario!

Best Answer

It is not possible to route based on hostname. The whole concept of DNS is something which exists on a higher level than basic network traffic does.

(For more info, read about the OSI model in general and the TCP/IP model in particular.)

On the other hand, the HTTP protocol does know about hostnames. Hence you should be able to setup a reverse proxy on the external address, forwarding requests to different internal addresses, based on incoming hostname. One option is to use Apache and mod_proxy.

Related Topic