Using CNAME to point to another domain to save IP addresses

Solution 1:

Per Farseeker's answer, yes, this is (sort of) what CNAME records are for.

However whilst you can use this to point www.example.net to www.example.com, you can't use it to point example.net on its own (i.e. without the www prefix) to something else.

This is because example.net must also have an SOA record and NS records, and it's not legal in DNS to have a CNAME present at the same part of the tree as any other records (DNSSEC keys excepted).

The "sort of" qualifier above, is because strictly speaking the CNAME record introduces the "left hand side" as an alias for the target of the CNAME record, where that target is actually the "canonical name".

Hence if you see e.g.:

www.example.net IN CNAME www.example.com.

It is not saying that www.example.net should be "redirected" to www.example.com, it's saying that the www.example.net is another name for www.example.com.

Solution 2:

That's exactly the point of a CNAME. A CNAME does not need to point to a DNS in the same zone, it can point to any DNS name registered with any nameserver.

What it means for your clients is an additional DNS lookup on the NS for the other host, but that's a tiny price to pay for the majority of websites on the internet.


Solution 3:

Yes it is possible.

That's how I do my experimental web servers that also have dynamic IPs (though seldom changed).