Apache : Name-based Vs IP Based Virtual Hosting

September 10, 2005
Often when, you attend interviews for network administration related jobs , the one question you may encounter while discussing about web servers is the difference between name-based and IP based virtual hosting. Here I will explain the difference between the two.

In IP-based virtual hosting, you are running more than one web site on the same server machine, but each web site has its own IP address. In order to do this, you have to first tell your operating system about the multiple IP addresses. See my post on configuring multiple IP addresses on a single NIC . You also need to put each IP in your DNS, so that it will resolve to the names that you want to give those addresses .

In Name-based virtual hosting, you host multiple websites on the same IP address. But for this to succeed, you have to put more than one DNS record for your IP address in the DNS database. This is done using CNAME tag in BIND. You can have as many CNAME(s) as you like pointing to a particular machine. Of course, you also have to uncomment the NameVirtualHost section in httpd.conf file and point it to the IP address of your machine.

#FILE: httpd.conf

This excellent article on Serverwatch.com explains in detail the configuration details of both types of virtual hosting in apache webserver.


  • I think there's 3rd possibility with mixing these.

    DNS for several domain names pointing to a same IP address

    And in Apache, make sure this address is listened and configure VirtualHost on that IP address and in the context, use ServerName and ServerAlias to make Apache differ between each other.