Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


July 1997

Multiple Virtual Domains with One IP Address


RSS
Subscribe to Windows IT Pro | See More Domains Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Setting up virtual domains in Windows NT is straightforward. In September 1996 ("How to Set Up Virtual Domains"), I described how to assign a unique IP address to each domain. However, in practice, you might want to set up domains that share an IP address, for several reasons. For example, because of a bug in the NT 3.x design, you can add only about 14 different IP addresses in that system unless you have installed Service Pack 5. In NT 4.0 Workstation, you can add about 10 IP addresses in the system; if you add more, you risk running into legal battles with Microsoft. Moreover, many Web servers-- in particular, those running on Windows 95 or on the Macintosh--do not support multiple IP addresses. In these circumstances, sharing an IP address for different domains is the best solution for setting up virtual domains. Let's explore how sharing an IP address works and look at two ways of setting up virtual domains with one IP address.

Our goal is to set up different domains, such as abc.com and xyz.com, so that when users browse http://www.abc.com or http://www.xyz.com, the system displays the respective home pages of companies ABC and XYZ, even though the companies have the same IP address (207.68.156.100). You can accomplish this feat with a simple script. The method works for more than two domains, too. I used Computer Software Manufaktur's Alibaba 2.0 Web server running NT Workstation to illustrate the techniques, but you can use the same method with Microsoft Internet Information Server (IIS) or any other contemporary Web server.

The Domain Name System Name Server
First, set up the Domain Name System (DNS) name server in your Network properly. To make two domains share an IP address, you can set up a canonical name (CNAME) for aliases. (A CNAME is the official name of the system host and is specified in the address (A) record for the host.) Create a CNAME record for each alias that shares the address. When a name server looks up a host name or domain name and finds a CNAME record, the server replaces the host or domain name with the CNAME and looks up the CNAME. If you use the Berkeley Internet Name Domain (BIND) software in your name server, you must add the following two entries to the primary named file:

www.abc.com. IN A 207.68.156.100
www.xyz.com. IN CNAME www.abc.com.

(BIND, usually included in UNIX-based operating systems, is the basis for the Windows NT 4.0 DNS. See Spyros Sakellariadis, "Configuring and Administering DNS," August 1996.) In the NT machine, add the network IP address 207.68.156.100. Now whether you ping www.abc.com or www.xyz.com, you obtain the same response: Reply from 207.68.156.100.

Set Up the Document Root
In your NT Web server, set up the document root directory, e:\, for the IP address 207.68.156.100. Create two subdirectories, e:\abc and e:\xyz, for the domains abc.com and xyz.com, respectively. The home pages of the two companies reside in those two subdirectories and subsequent subdirectories. For example, company ABC can set up a subdirectory e:\abc\images to hold all the images that it needs. At this point, create the default file index.htm (or the appropriate default entry file of your Web server) for a home page and put it in the document root directory. Now when users browse either http:\\www.abc.com or http:\\www.xyz.com, they will see the same home page.

To display different home pages for the two universal resource locators (URLs), you must redirect the requests to the appropriate directories and execute the correct files. A simple way to do this task is to add the appropriate index.htm file, or subdirectory, to the URL or to the link to the company on a related home page; when users request that URL or click on that link, they will go to the right subdirectory. The following sections explore two methods to make this process transparent to the user.

The CGI Method
First, let's first explore using Common Gateway Interface (CGI) scripts to redirect requests. You can automatically start a new URL by making use of the client-pull technique. In this technique, the browser either reloads the current page or loads a different page after a specified delay. In this way, Web document contents can change without action from the user. One way to redirect a URL is to edit the default start file index.htm (in e:\) so that it contains the statements:

<html>

<head>

<meta http-equiv="Refresh" content="0;url=/cgi-bin/referer.exe">

<title>testing</title>

</head>

</html>

where content="0 informs the server to start (i.e., refresh) the URL specified in the line after 0 seconds (i.e., immediately). The file referer.exe is an executable CGI script that has been compiled from the C-source code (referer.c) in Listing 1 to direct the user to the correct domain.

In Listing 1, the statement

getenv("HTTP_REFERER");

returns the link that leads to the execution of the CGI script. The function

strstr()

searches for the existence of a substring that returns NULL if the substring does not exist. Through these steps, the command Refresh will start the correct home page. For example

printf( "Refresh: 0; URL=http://www.xyz.com/xyz/index.htm\n\n" );

starts the URL link http://www.xyz.com/index.htm after 0 seconds--that is, immediately.

This method is a simple way to redirect the user. You can easily modify the code to make the URL-lookup efficient when you have a large number of URLs. For example, you can put all the URLs in a table and use standard searching techniques, such as hashing or binary searching to perform a quick table lookup. Unfortunately, most browsers currently do not return the appropriate URL-referrer when you start the CGI by Refresh instead of by hand-clicking the URL link. Although I believe that Refresh will work in the future, to use the CGI method now, you must click at the prompt, and the file index.htm in e:\ will be

<html>

<a href="\cgi-bin\referer.exe">
Please click here</a>

</html>

Users browsing http://www.abc.com or http://www.xyz.com will see the prompt

Please click here

You must click on this message to start the correct page. Alternatively, you can use the tag

<meta HTTP_EQUIV>

in an HTML page to perform the page refresh.

If you want to automate the whole process to work under browsers in use today, you must use JavaScripts.

The JavaScript Method
JavaScript lets you embed JavaScript commands in an HTML page to call up the correct home page. When you use a compatible Web browser, such as Internet Explorer (IE) 3.0 or Netscape Navigator 2.0 or higher, the browser loads your JavaScript commands as part of the HTML document. You trigger the commands by clicking the buttons that Java displays on a related home page or the browser evaluates the commands as it downloads the script. Thus, the scripts can make Web pages execute dynamically. Listing 2 presents the complete JavaScript code that makes the URL-redirection transparent to the user. Place this code in the file index.htm (or the default entry file of your Web server) in the document root directory of the Web server.

When the Web browser downloads the HTML file index.htm, the browser evaluates the JavaScript code go(), which calls the function go(). The function go() calls up the correct URL link. In the function, the variable location.href contains the current URL (i.e., either http://www.abc.com/index.htm or http://www.xyz.com/index.htm) and is compared with variable x. I set x to be the string http://www.r, which has a string value between http://www.abc.com and http://www.xyz.com. Thus, if location.href is larger than x, the reference URL is http://www.xyz.com; otherwise, it is http://www.abc.com.

After determining the correct reference URL, you can redirect the browser to the correct home page by assigning the appropriate URL link to location.href. For example, the statement

location.href="http://www.abc.com/index1.htm"

automatically informs the browser to download the file index1.htm, which resides in the document root directory. This file (index1.htm) is the entry point for the home pages of the company abc.com. (Alternatively, you can put the company-specific index.htm file in subdirectory e:\abc with the statement location.href="http://www.abc.com/abc/index.htm".)

This script can make the single-address virtual domain setup user-transparent; that is, when you use a compatible browser to browse the URL http://www.abc.com based on this setup, the effect will be the same as browsing a URL whose setup is based on multiple IP addresses.

I admit that this method works only if the browser supports JavaScript. For obsolete browsers, you must rely on the manual CGI method. But either method lets you stretch a limited number of IP addresses.

End of Article



Reader Comments
In his July article, “Multiple Virtual Domains with One IP Address,” Tong Lai Yu suggested a method to redirect a client to one of several pages based on the virtual domain. This method bounced the client to a CGI script with a <meta> redirect and checked the HTTP_REFERER environmental variable. He qualified this suggestion with the fact that “most browsers currently do not return the appropriate URL-
referer when you start the CGI by Refresh…” You can solve this problem by using the SERVER_NAME environmental variable, which the National Center for Supercomputing Applications (NCSA) defines as “the server’s hostname, DNS alias, or IP address as it would appear in self-referencing URLs.”<br>
--Steven Richman

Steven Richman August 13, 1999


Hi,

Your technical articles are really good and gives a clear cut practical information about HOW EXACTLY THINGS WORKS
and HOW EXACTLY TO DO IT.

Thanks.
Rahul

Rahul November 25, 2002


great work.

Anonymous User March 03, 2005 (Article Rating: )


Hey, fantastic article. I have a suggestion to help with the obsolete vrowser problem. At the start of the default web page for the server, you could determine what browser is being used to access the domains, then based on a series of checks you could either perform a java based redirect or put up a helpful bit of text explaining that their browser does not support java, and to "click here" do be directed to the approporaite web page. Just a thought.

Having suggested this, I have no idea how to determin which browser is access the web page but I'm sure you've already addressed that somewhere else...

Anonymous User April 04, 2005 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
CES 2009: Ballmer Announces Windows 7, Windows Live, Live Search Milestones

During his first-ever Consumer Electronics Show (CES) 2009 keynote address last night in Las Vegas, Microsoft CEO Steve Ballmer announced the pending public availability of a feature-complete Windows 7, the final version of Windows Live Essentials, and ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

Where is Microsoft NetMeeting in Windows XP?

...


Related Articles How to Set Up Virtual Domains

Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Related Events Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Cloud Computing Forum: Integrating Software, Server and Storage as a Service into Your Enterprise IT Delivery Model

Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2009 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing