Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a query regarding setting up servers.

Suppose I have multiple websites to host.

foo.com
bar.com
hello.com

I may or may not to have specific servers for them. Suppose an arbitrary configuration is something like this (with the respective domain registrar)

foo.com  A  1.1.1.1
bar.com  A  1.1.1.2
hello.com A 1.1.1.1

What I would like is to give each website a universal domain to point to instead of an IP (since IP can change).

something like the following.

foo.com CNAME service.com
bar.com CNAME service.com
hello.com CNAME service.com

From what I have understood about DNS so far,

Queries

  1. I think I will need to setup a DNS server at service.com which returns the appropriate records.
    • Is this correct?
  2. If so what if domain is held with a domain registrar? such as dreamhost. How to handle it then?
    • Since they respond to DNS queries, how do I insert that layer of indirection?

Achieve transparent server migration from client's perspective

Ultimately what I would like to achieve is that if I were to one day host hello.com from a different server, I would only have to modify in 1 place at the server rather then tell the client to change their DNS config.

Additional Info:

I use rackspace, they also have something called reverse DNS. Is that useful?

I noticed for google Apps - we always point to ghs.google.com and they forward the request to appropriate IP. So it must be possible, but I just can't figure out how to achieve it.

share|improve this question

4 Answers 4

up vote 1 down vote accepted

You'd need a separate cname per site. Something like:

foot.com CNAME foo.com.service.com
bar.com CNAME bar.com.service.com
hello.com CNAME hello.com.service.com
share|improve this answer
    
So how does foo.com.service.com get resolved. The domain registrar will see service.com and say I know this and return an IP. This might not be the IP where foo.com is actually hosted. I want to control that, but not sure how to. (refer to query 2) –  Nasir Nov 4 '11 at 16:18
    
You set up an A record for foo.com.service.com in your DNS. If foo.com's IP needs to change, just change that A record. –  ceejayoz Nov 4 '11 at 16:22
1  
A note, though - you can't CNAME a root level domain. You can do it for www but the non-www will need to go to a server that kicks them to the www alias. –  ceejayoz Nov 4 '11 at 16:23
    
Cname per site may be used. But common CNAME with short TTL is perfectly OK too –  Lazy Badger Nov 4 '11 at 16:24
    
@LazyBadger A common CNAME won't work here. bar.com has a different IP address in the question. –  ceejayoz Nov 4 '11 at 16:43

You need an A record for each server. (Using standard documentation data.)

host1.example.com.   A   192.0.32.11
host2.example.com.   A   192.0.32.12

You can then use CNAME records to point the server to the appropriate server. I split the hosts as per your addresses.

www.foo.com.    CNAME  host1.example.com.
www.bar.com.    CNAME  host2.example.com.
www.hello.com.  CNAME  host1.example.com.

On your servers use virtualhost definitions in your web server to define the available websites. There is no siginificant penalty for defining unused virtual hosts, so you could set up sites on several servers but only provide DNS records for one.

If you want to handle domains like foo.com which require more than one DNS record. You need to use A records. There are a couple of ways to do this. Have an A record with the same address as the host that serves the domain.

foo.com         A   192.0.32.11
bar.com         A   192.0.32.12
hello.com       A   192.0.32.11

Another approach would be to use a server to redirect the domains to their www subdomains. This could be the same as one or more of the hosts above.

foo.com.        A   192.0.32.5
bar.com.        A   192.0.32.5
hello.com.      A   192.0.32.5

Seriously consider setting up MX records for the domains like foo.bar. Also consider SPF for both versions of the domain. If you mail server is mail.example.net these records should work (SPF records are optional an may not be accepted by old DNS servers.):

foo.bar.        MX   10 mail.example.net.
foo.bar.        TXT  'v=spf1 mx -all'
foo.bar.        SPF  'v=spf1 mx -all'
www.foo.bar.    TXT  'v=spf1 -all'
www.foo.bar.    SPF  'v=spf1 -all'

The above SPF records state that only the MX will send email for the domain foo.bar, and no mail should have the domain www.foo.bar. For domains that won't originate email remove the mx from the TXT and SPF records. See http://www.openspf.org or my article on SPF for more detail.

Remember that domain data is cached. When moving static sites, leave the site up on the old host until traffic stops arriving. Moving sites with dynamic content is more difficult.

share|improve this answer
    
You can't have a CNAME at the zone apex as it cannot be used in conjunction with another RR type. As the SOA RR exists at the apex, you can't use a CNAME. –  James O'Gorman Nov 4 '11 at 19:30
    
@James O'Gorman Yes SOA and NS records at a minium. I new there was a good arguement against no_www. This applies for any delegated domain. –  BillThor Nov 4 '11 at 21:57

Keep in mind that you won't be able to use CNAMEs for second level domains like "example.com" because they have to have SOA RRs.

share|improve this answer

To set up DNS for a domain you own
On Dreamhost, make sure the name servers are set to Dreamhost name servers (they should be by default). Then set up the DNS with them (there should be a control panel to set up DNS records for the domain).

Some infos
CNAMEs just point to hostnames; those hostnames must be configured with IP addresses (ie, must have an A record pointing them to an IP).

If you have a few hostnames that need to be mapped to the same IP, then it can be easier setting up one hostname (A) to point to that IP, and then all other hostnames CNAME to that hostname (A).

If you have a few hostnames that need to point to different IPs, CNAMEs won't be much use.

So let's say you have foo.com, bar.com, hello.com and service.com and you want to point them all to the same IP (taking note of @ceejayoz's comment about root domains and CNAMES). You'll need to set up one A record to point a hostname (say, service.com) to the IP, then set up CNAMEs for www.bar.com, www.foo.com and www.hello.com to point to service.com.

This will require you to have access to the DNS records for foo.com, bar.com, hello.com and service.com (so if you've registered all of these domains with Dreamhost, you need to configure them all to use Dreamhost name servers, then setup the DNS records for each of them.

Specific answer to your question
You've mentioned, though, that you want to be able to modify the IP address for one domain without effecting the other; in this situation, you'll need to set up a CNAME for each domain name. Or, you can use reverse proxy (although it adds additional complexity). With a reverse proxy you can have all the domains using the same IP, regardless of what server they're on (the reverse proxy will forward the request onto the right server depending on what domain is being asked for). This is probably what Google Apps are doing.

Reverse DNS will not help you for this, but is useful (especially for email delivery). I won't go into it now, but you should read up on it!

share|improve this answer

Your Answer

 
discard

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.