36

I have one server which I'm hosting a handful of sites on.

Currently, each site has it's domain hosted by an independent provider and each has an A record pointing to the server's IP address.

But if I want to change the server in the future, I will have to go back an update each IP address in each DNS record.

Is it possible to use a CNAME record on each domain to point to another domain that I control directly?

This is so I can update the IP address in 1 place myself and not have to get all these other DNS providers to update their records separately?

24

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.

  • normally it's the recursive server that will perform that additional lookup, not the stub resolver in the client. – Alnitak Aug 31 '18 at 9:33
25

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.

  • 2
    "example.net must also have an SOA record". Some people cheat: look at lrnskls.com. – bortzmeyer Sep 16 '09 at 8:00
  • it's a nasty hack, and they'll have a huge problem should they ever want to DNSSEC sign it. – Alnitak Sep 16 '09 at 10:07
  • 5
    +1 this is a good point and one of the bigger flaws (and reason why none of my sites can be used www-less as those domains also needs an MX record, prohibiting this). – Oskar Duveborn Sep 16 '09 at 12:08
3

Yes it is possible.

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

0

I will have to go back an update each IP address in each DNS record.

Well, CNAMEs are indeed a possible solution (see Alnitak's reply for a limit of the CNAMEs) but there is another one: instead of managing your zone files by hand, create a ten-lines program (Perl / Python / Ruby / cpp / m4 / whatever) which will generate the zone files from a master (a text file, a XML file, a DBMS, whatever)

That way, your IP address can be in only one place. When it changes, just re-run the program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.