2

Is it possible to have 2 domain names pointed to two different VMs running under Ubuntu Server? My dilema is that I only have 1 public facing IP address.

Here is a graphic of what I am trying to achieve:

                /---FQDN1--->VM1
External IP ----
                \---FQDN2--->VM2

I realize that there may be some pitfalls with this, such as having applications bind to different ports to avoid conflicts.

After reading online this may be possible with iptables, bind, and/or squid proxy.

5
  • Q: Is it possible to have 2 domain names pointed to two different VMs running under Ubuntu Server? A: Yes.
    – joeqwerty
    Jun 15, 2014 at 3:12
  • joeqwert, how would I set this up?
    – Ion B.
    Jun 15, 2014 at 3:18
  • Start by adding some detail to your question. What are the details of the VM OS (Ubuntu Server x?). What services are running on the VM's? What services do you want to forward to the VM's?
    – joeqwerty
    Jun 15, 2014 at 3:22
  • My host OS is Ubuntu Server 14.04 x64. Both VMs also use Ubuntu Server 14.04 x64. One VM is running Apache + MySQL. VM2 is also running Apache, a game server, and a media server.
    – Ion B.
    Jun 15, 2014 at 3:24
  • What are the exact ports your applications use in the servers? Jun 15, 2014 at 10:33

2 Answers 2

1

First of all it is impossible to forward ports at the IP or transport layer to different internal machines based on the domain which the client is accessing. Because of that, what you want to do has to be done at a higher level of the network stack. But you may already have read this, since you are asking about proxies.

Moving one layer up the network stack, you find a wide range of different protocols. Some are easy to proxy based on hostname, some are impossible. I only know four protocols, which can be proxied in this way. Ranging from easiest to hardest, they are:

  • HTTP
  • HTTPS
  • DNS
  • SMTP

A standard HTTP proxy can handle the HTTP protocol for you. It works with any client sending a host header. This header is optional in HTTP/1.0 and mandatory in HTTP/1.1. By now HTTP/1.1 is more than a decade old, and you can expect pretty much all clients to support it by now.

HTTPS is a bit more tricky. It will only work with clients supporting SNI. I think you'll find a majority supporting it, but you may find a significant minority of clients still not supporting SNI. You can forward all clients without SNI support to one particular server, such that at least one of the domains can work for clients without SNI.

My recommendation is to assign a public IPv6 address to each server. That way clients with IPv6 support don't get the drawbacks of proxying, and you can use the IPv6 connectivity from the proxy to the actual server. This also means that the proxy can actually use DNS lookups to find the address of the server, which may simplify things.

I have implemented such a proxy with http and https support, so I know it is doable. But I think for your setup an off-the-shelf proxy is likely a better choice. I think squid can do it. On the other hand, I don't think iptables and bind will help you much.

2
  • Thanks, I just needed some clarification! I do currently have IPv6 through Hurricane Electric's broker service.
    – Ion B.
    Jun 15, 2014 at 19:15
  • I really like your idea to use dual-stack like this. Jun 15, 2014 at 21:09
0

The easiest way is using a reverse proxy which proxies your requests to the VM's. (I just assume we're speaking HTTP here)

2
  • No, not just HTTP. Otherwise I would have just used Apache's reverse proxying module. Is there anything for general TCP/UDP proxying, regardless of protocol?
    – Ion B.
    Jun 15, 2014 at 7:04
  • @IonB. No, there is no way to do it which will work for all TCP/UDP protocols. The proxy has to extract the hostname from the higher layer protocol. So it will be protocol dependent, and it will only work with some higher layer protocols. If you need anything better than that, it is time to move to IPv6, where you can get all the IP addresses you need.
    – kasperd
    Jun 15, 2014 at 10:00

Not the answer you're looking for? Browse other questions tagged .