2

I have a server on which I want to host several domains.

Let's say these:

example1.com
example2.com
example3.com

I only have one public IP (currently). I have configured all A-records to point to that public IP address. I can configure my apache to serve files for all domains without any problem and I can ssh to any of these domains and reach my server.

Now I have installed KVM and created a couple of guests. One guest has a private IP address 192.168.0.100. I want to host example2.com on that guest. Therefore I would need to somehow direct all traffic meant for that domain to the private IP address.

I want to be able to have an apache and sshd running on several guests and distribute traffic according to which domain the guest is configured for.

Is this possible at all with a private network? Or do I need public IP addresses for each domain?

I'd be grateful if someone could enlighten me I suspect I am overlooking something obvious.

2 Answers 2

2

It is possible to forward the traffic, you can forward traffic with iptables and use mod_proxy to proxy the incoming http requests to the right server.

You will not be able to ssh to port 22 by using a domain name and expecting it to go to the local guest. You will need to use separate ports to forward the traffic to the right ssh port.

For example if you have guest1 we will reserver port 10000 on our public IP to forward all packets to our guest1 private IP(192.168.1.2) on port 22:

First allow masquerading:

$IPTABLES -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Forward traffic coming in on port 10000 to your ssh port on guest1:

$IPTABLES -A PREROUTING -t nat -p tcp -i eth0 --dport 10000 -j DNAT --to 192.168.1.2:22
2
  • I was hoping for some solution with bind, but was suspecting that it would come to what you are proposing. I am still very much a beginner as server admin and networking is not my favorite aspect ;)
    – Yashima
    Apr 30, 2012 at 6:16
  • Well the problem is that the DNS protocol doesn't have a part where you can specify a port, so you can't use it for SSH. However you can use it for your domain names. Apache will see the hostname in the HTTP header and it will proxy it to the correct server. Apr 30, 2012 at 7:16
0

Another way to forward traffic to a number of servers (based on load) is LVS. ipvsadm is the command that sets it up...

2
  • I am already using kvm as virtualization tool. I was considering LVS but ended up using KVM because it us bundled with Ubuntu and I was hoping it would be easier to set up. (which turned out to be true for some aspects)
    – Yashima
    Apr 30, 2012 at 6:15
  • @Yashima Despite the name LVS is not about virtualization of machines. It is about virtualization of services which are addressed through IP and UDP/TCP ports. So all it does is forward/route traffic from one IP/port to a number of IP/ports using certain criteria.
    – Nils
    May 1, 2012 at 19:29

You must log in to answer this question.

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