0

I have a synthetic record set up pointing example.com to www.example.com and this works. I also have a CNAME pointing a.example.com to a website that hosts my images, and this works.

I want www.example.com to redirect to a.example.com, while I build a website to deploy on www.example.com.

I used CNAME from www.example.com to a.example.com and this did not work. Everything I read says that CNAME is the correct tool for this, so what is going on?

update: To clarify, I am setting these records on Namecheap (but this should apply to all other Domain managers like Google Domains), not Windows Server or Apache or NGINX.

Ryan
  • 109

3 Answers3

2

So you can check my comments for a little bit of insight on how to troubleshoot your issue. But I suppose a definitive answer to how DNS records work and how to achieve the redirection you are looking for would be more appropriate. RFCs probably are the proper way to site sources, but I like to explain with my own examples. So I will provide screen shots from my Windows 2016 Active Directory server that runs DNS locally on the server as well. Now if you use something like bind on Linux/Windows then the concepts should hold true, but obviously a different approach to configuration.

So your DNS server is going to have a Forward Lookup zone configured for your domain. Mine for this instance is digiecho.xyz as you can see in the screenshot below:

DNS Forward Zone Example

In the lookup zone you can see that I have an assortment of A records that point to IP addresses. These are the most common types of records created in my experience. So you should have one A record where your www.domain.com points to some IP. For my example I'm going to use my A record for VC01.

A CNAME or Canonical Name allows you to alias one name to another. I'm going to create a CNAME record vcenter.digiecho.xyz and point it to my A record VC01 (see screen shot below for record creation example, and info on CNAMEs):

https://support.dnsimple.com/articles/cname-record/

CNAME Record Creation

You then can use DNS tools like dig or nslookup to troubleshoot what is going on. Since this is all on my internal network I just used nslookup from another server on my virtual host to show some relevant outputs to help you in your troubleshooting:

nslookup Example

As you can see it not only tells me the true canonical domain the alias points to. However it should report back the server that is reporting back the record. So if you have like a master-slave configuration in your DNS environment you will want to make sure the zone transfers have occurred from the master to all the slaves to ensure that they all have the correct. If you are using Linux just man dig for the command parameters. But really those basic DNS checks and troubleshooting should be sufficient to solve a CNAME issue.

2
name                optional_TTL   CLASS   RR      canonical name
www.example.net.    3600           IN      CNAME   a.example.com. 

Simplified a DNS CNAME record does nothing more than pointing a DNS record to the canonical name of another host by using that hosts DNS name rather than by creating an A entering that hosts IP-address.

After that DNS change you will usually need to reconfigure a.example.com and make the services running there aware of the fact they can be accessed by an additional hostname www.example.net. rather than only via a.example.com.

If you don't do that, things may work out, for instance a web server running plain http and only one website will display that website regardless of the hostname used to access the web server, but for a web server running multiple virtual hosts on HTTPS you will need to both request a new TLS certificate with the www.example.net. domain name AND you need to either create a new virtual host entry, or add www.example.net. to a specific existing virtual host.

HBruijn
  • 84,206
  • 24
  • 145
  • 224
2

A CNAME record should not point to another CNAME record.

Find out where your a.example.com CNAME actually points to, and then set your www.example.com CNAME to also point directly to that.

Patrick Mevzek
  • 10,581
  • 7
  • 35
  • 45
telcoM
  • 4,876