Moving many sites to new server – whats the quickest way to update their DNS records

dns-zonedomain-name-systemmigration

I'm planning on migrating a large-ish amount of websites (approx 100) to a new server and I'm in the migration planning process.

A typical DNS zone for each website has two A records pointing to the web server IP, one for example.com and one for the www subdomain.

When we're all setup and ready to launch the new server to production, changing 100×2 DNS records will be time-consuming so I'm searching a way to make this quicker. In a couple cases I read about creating a bash script that iterates the DNS records and performs a find-replace with the new IP.
In other topics I've read suggestions about adding A records with the new IP so that when the current server is no longer available, the DNS server will point the requests to the next record, that containing the new IP.

Apart from these, is there any scenario in which I could replace the A records with some other type of DNS entry ie a hostname so that, when the time comes, I can only change the IP of the hostname with the new one and have all websites point to the new server? I'm sure 'hostname' is not the right term, I hope you all get the idea though.

Best Answer

The term you're looking for is CNAME, and the answer to your question is both yes and no.

First, here's an example of how a CNAME works in a zone file.

example.se  IN SOA  ns1.example.se. hostmaster.example.se. (
            [....]
            )

server1    A       10.1.2.3
www        CNAME   server1

Now you just need to update the server1 record in order to move both server1 and www to the new IP address.

The CNAME doesn't have to point to an address within the same domain; it could also look like this:

example.se  IN SOA  ns1.example.se. hostmaster.example.se. (
            [....]
            )

www         CNAME   server1.example.org.

Now, when you update the A record for server1 in the zone example.org, the record for www.example.se will follow along without any further configuration.

The bad part, from your point of view, is that this does not work for the apex record - that means the "bare" domain. In other words, you can make www.example.com into a CNAME, but you can't do that with example.com. This is because when you use a CNAME record, you can't have any additional records for that entry - meaning that you can't have mail server records, or name server records... meaning that the domain will stop working.

The best-practice solution is to use some kind of configuration management software, such as puppet, chef or ansible, to generate the zone files from a template. If, for some reason, that is not possible for you, then I'd use a script to replace the IP addresses in all files.

You'll also want to reduce the TTL value for the domain in due time before the migration. (And don't forget to update the serial number of the zone file - I have, and it's very embarrassing...)

Related Topic