Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Let's say these:

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 I want to host 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.

share|improve this question
up vote 2 down vote accepted

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( on port 22:

First allow masquerading:


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
share|improve this answer
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 '12 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. – Lucas Kauffman Apr 30 '12 at 7:16

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

share|improve this answer
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 '12 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 '12 at 19:29

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.