I'm a developer and I'm having trouble setting up some hosting, and I hope you guys can help me out.

I've got a domain I'm setting up for a friend. URLs work fine when I use the short form, like

http://domainname.com

That is, the pages render properly and I get HTTP/200 responses. When I try

http://www.domainname.com

I get a HTTP/502 error. Pinging it gives me "Ping request could not find host www.domainname.com. Please check the name and try again."

I'm stumped, because I don't know enough terminology to formulate a good keyword search. Can anyone give me some info on what I might need to do, to set up some kind of alias so that the standard www. form will work? I don't know whether to talk to my registrar or my hosting company, what to ask them for, or where to look in the various control panels.

Any help at all -- even just naming the different pieces -- would be helpful. I don't know my TLDs from my domain aliases from my CNAMEs.

4 Answers
4

There's really no difference in these two names other than the fact that one has a subdomain prepended to it and the other doesn't. You can set up resource records to take advantage of an almost unlimited amount of subdomains once you own a domain name.

There are at least 30 different types of resource records. For now you can probably get by with focusing on two:

aname ("a" record - primary address record)

cname (Alias of one name to another)

www is by far the most common subdomain but there are many others. Take a look at the following examples:

gmail.google.com

my.yahoo.com

What you need to understand is that google.com and yahoo.com are domain names.Anything before that is referred to as a host name or a subdomain. As long as you take the necessary steps to set up your DNS resolution to resolve these subdomains to either their own IP address (use A Name) or as an alias (use a Cname) and you set up your webserver to understand such requests you'll be set.

In your case you should use a cname to point www.domainname.com to domainname.com. A cname is more appropriate as an answer only if you intend to point both to the same IP. That way if you need to change your IP in the future, you'll only need to adjust one record.

As for getting your webserver to understand both requests there are lots of examples for both Apache and IIS on serverfault. Do a search and you'll find everything you need. Look for virtual hosts.

Edit: Here's a cross reference about cnames. They have their place too. Use the tool that best suites your circumstances.

Patrick R is spot on with his answer. Also you want to keep in mind that every record has a TTL (Time To Live), so by using CName references you can guarantee that if you ever change your servers location via IP Address that all of your CNames will change at once. If you had to update multiple AName records you may have some confusing results when they are switching at different times.
–
ShaneFeb 9 '10 at 14:00

No, the CNAME is a terrible idea since it would alias every type, not just the A, so he will get also the SOA record, the NS, etc.
–
bortzmeyerFeb 10 '10 at 12:29

@bortzmeyer - how would this idea be terrible for Steve's situation above? where does he imply that he needs to avoid the SOA record, the NS, and the items you mysteriously refer to as etc?
–
Patrick RFeb 11 '10 at 12:47

Nothing mysterious in etc: the CNAME would get all the records of domainname.com in www.domainname.com. The first breakage would probably come from the NS records because www.domainname.com would then look like a delegation.
–
bortzmeyerFeb 12 '10 at 11:07

And that's exactly why I said he would be better off with a cname in this situation.
–
Patrick RFeb 12 '10 at 12:56

Steve would be better off using a cname since it appears as though he would like both urls above to resolve to the same location.
–
Patrick RFeb 9 '10 at 1:36

No, the CNAME is a terrible idea since it would alias every type, not just the A, so he will get also the SOA record, the NS, etc.
–
bortzmeyerFeb 10 '10 at 12:28

@bortzmeyer - you posted this exact comment twice. sounds like you feel pretty strongly about this. You're not wrong but in this situation you're also not correct since that has no bearing on what this person is attempting to do.
–
Patrick RFeb 11 '10 at 20:12

1

I think what bortzmeyer is saying is if you create a 'www' cname to domainname.com not only will you pull back the A record, you will multiple record types (NS, SOA, A and maybe MX). Creating a seperate A record for 'www' and using the same IP address would be a better solution.
–
commandbreakFeb 12 '10 at 2:25

@nick - what would take more resources, a client's dns query making a request of a cname or an admin who needed to update a single IP address multiple times because multiple hosts (aliases) pointed to that single address via anames?
–
Patrick RFeb 9 '10 at 2:19

if your running a big site, then the extra few minutes is worth the reduction in dns query overhead.
–
Nick KavadiasFeb 9 '10 at 2:34

I run several large sites and never noticed that cnames were a significant overhead. I'll take a closer look. What would be a good use for cname records? Should I consider using them in a different way?
–
Patrick RFeb 9 '10 at 2:51

personal preference maybe? I never use them for public sites. If 90% of your traffic is hitting a www. addresses, then you want that to be an a-record not a cname.
–
Nick KavadiasFeb 9 '10 at 2:56

personal preference? That I'll go with but you did mention query overhead. Is that not then the case?
–
Patrick RFeb 9 '10 at 3:51