Moving your website to another server? Tune your DNS for minimum downtime.
I hate to move a website to another server, but in real life there are many situations were this will happen (maybe you need to upgrade your current server to a better one, maybe your current server is on a bad datacenter, or you just found a better financial deal, or maybe you only need to change the IPs on the same server, etc.). Besides some other problems that might appear (for example software incompatibilities, and the site not running the same way on the new server), the major problem you might face is the DNS caching problem. This means that based on what your current DNS configurations, for a period of time your site will be accessible on both servers. Now this might be ok, but in most situations it is not. For example you will have the emails delivered by some remote servers to either server, or some users browsing your site still on the old server (causing problems with e-commerce sites, or sites that depend on the various data that is saved while users browse the site). I have completed successfully with minimum downtime many such moves and I will show you how this can be done with a very simple DNS trick.
In order to do this in the best possible way we need to be aware and understand a little about how DNS caching works. When a remote DNS resolver will make a query to one authoritive DNS server (let’s say for the domain we are moving) then if the query is successful it will cache that response for a predefined time. This means that for that amount of time that particular server will use its cached information and no longer query the authoritive server for any additional requests. That timer is defined in the authoritive DNS server and as long as all the remote servers follow the standards, we can make this work. In order to be successful in this operation you NEED to have control over your authoritive DNS server.
The parameter that we are going to tweak is:
TTL value: This value used to determine the default (technically, minimum) TTL (time-to-live) for DNS entries, but now is used for negative caching.
Here is its definition from RFC 1921:
“The default TTL (time-to-live) for resource records — how long data will remain in other nameservers’ cache. ([RFC 1035] defines this to be the minimum value, but servers seem to always implement this as the default value) This is by far the most important timer. Set this as large as is comfortable given how often you update your nameserver. If you plan to make major changes, it’s a good idea to turn this value down temporarily beforehand. Then wait the previous minimum value, make your changes, verify their correctness, and turn this value back up. 1-5 days are typical values. Remember this value can be overridden on individual resource records.”
So as you can see this is not at all a big secret and the RFC even explains what you need to do in such situations… Now I will exemplify this on a small example where I will consider having an authoritive nameserver running BIND9 and the zone domain_to_move.com. In case you are running a different DNS server this should be similar just that the configurations will look different based on the particular DNS server you are using. Let’s say that we have a very simple zone file defined that looks like this (the IPs are private ones just for the exemplification):
; zone 'domain_to_move.com'
$TTL 86400
@ IN SOA ns1.domain_to_move.com. hostmaster.domain_to_move.com. (
2006052101 ; Serial
10800 ; Refresh 3 hours
3600 ; Retry 1 hour
604800 ; Expire 1 week
86400 ); Minimum 24 hours
@ NS ns1.domain_to_move.com.
@ NS ns2.domain_to_move.com.
@ A 192.168.0.10
@ MX 10 mail.domain_to_move.com.
; Nameservers
ns1 A 192.168.0.1
ns2 A 192.168.0.2
; Mail
mail A 192.168.0.10
; Web
www CNAME domain_to_move.com.
As you can see in the first line of the zone file ($TTL 86400) this defines the default TTL for all existing records to 86400 seconds (that means 24 hours). So the first thing that we need to do before starting the actual move is to lower this to a very small value. 60 seconds sounds good. This means that any remote server will not cache the records for more than 1 minute
; zone 'domain_to_move.com'
$TTL 60
@ IN SOA ns1.domain_to_move.com. hostmaster.domain_to_move.com. (
2006052102 ; Serial
...
Now we will need to reload the DNS server to activate the new configuration. After this we have to wait for the previous TTL amount of time (here 1 day) in order to be sure that no other remote DNS server has that information in cache. Once that time has passed we can safely proceed with the move and change the actual IPs to point to the new server. I have assumed in this example that the nameservers will remain unchanged, but if you are going to move them also to the new server all you need to do is to be sure that you will configure them the same way.
Once the move is over don’t forget to return to some normal TTL value as this will decrease your overall DNS traffic and allow again to have the information properly cached.
Note: in case you have the nameserver hosted on some remote service and don’t have full control of your DNS zone you might not be able to do this and you will be limited to the control panel you will have there. In this case talk with your hosting support to have them lower the TTL for you.
A nice and quick way to check how the remote servers will see your DNS zone and check all the parameters is:
http://www.dnsreport.com/
Please feel free to share your experiences in moving to another server. Did you had problems? Was it smooth and without any problems? Share your experience.
>







21st May 2006, 14:04
In WebHost Manager that many Web hosts provide, there are two TTL entries that look like the one that you recommend be temporarily changed:
@ (time) in SOA
and
minimum ttl (shown after refresh, retry, expire)
It’s not clear to me which of those two that you recommend changing when moving Web sites, and your “after” screenshot doesn’t help because it cuts off the list of refresh, retry, expire, minimum ttl info) Please clarify.
21st May 2006, 15:58
Dear ComputerBob,
The example zone was given from a clean server (without any control panel on it) and without too many records just to exemplify this.
Now if you are using CPanel/WHM then here is the situation:
- you can still access your DNS zones and edit manually in case you want that (they should be under /var/named/*.db)
- even if CPanel will assign a default TTL for all the DNS records (default $TTL 86400), it will overwrite this with individual TTL set for each record like this (with a default to 4 hours = 14400sec for each individual record):
www 14400 IN CNAME domain_to_move.com.
- this is true on the CPanel based servers that I have control that are running the latest versions of CPanel (stable/release) but might not be the case with older versions.
- so in this case you will need to change each individual record TTL in order to achieve the same thing (either manually or from WHM).
Hope that this helps and clarifies the situation on your CPanel based server.
- Marius -
21st June 2006, 05:16
Whats the best TTL value to have when you are not planing to change anything?
21st June 2006, 08:23
Michael,
60 seconds should be a good value for this. Don’t forget that you have to wait for the old TTL to expire so other DNS servers don’t have that information in cache.
20th July 2006, 10:23
very good post
Thank you Marius.
23rd December 2006, 16:41
Thanks for the explanation of TTL
23rd December 2006, 16:42
Great
26th January 2007, 15:57
Thank you for the very good post Marius. We are a webdesign company that also provides webhosting our clients and decided to move to a datacenter in Germany (from one in the USA). We installed the OS + CPANEL yesterday and i’m sure your tips will be very helpful when migrating the existing accounts.
By the way, we are also in Sibiu, Romania
20th March 2007, 20:27
Fantastic information really helpful thank you so much
27th April 2007, 03:17
Hey,
Thanks very much for the very helpful post!
We are a hosting company and I got a client who has a website up and running on another hosting company. Both her former server company and we are using Cpanel/WHM. The clients changed the domain registration information to direct it to our name server correctly. We modified the zone file as well. But one weeks past and the site is still accessible on both servers.
Can you give me some hint on how to solve the problem please?
27th April 2007, 09:43
Rocky,
Double check the authoritive DNS server configuration for the domain.
23rd October 2007, 13:53
another method may work for dynamic site specially who dont have access to these options to change the ttl.
the method are:
move the mysql database to new server. change your site’s mysql connection host to that new server. so your database contents are coming from the new server. now move files and change/update the name server.
i think in this method no data will loss.
20th February 2008, 15:47
I’m a bit of a newbie so this might be a stupid question but, what would be the difference between your method and using a failover DNS service
(like mentioned in this post http://www.45n5.com/permalink/the-web-hosting-tutorial-that-doesn-t-suck.html)?
Cheers,
Tori
20th February 2008, 23:38
Tori: these are two different methods and basically they are both useful, depending where you have your DNS nameservers. If under your control, then you will be in charge of preparing properly the move (like I explained here), while if you have this on a specialized 3rd party provider you will expect them to do this automatically, like explained the article you linked. Still you will want to ensure that the service provider you choose is good enough and will not cause you more troubles… look for a specialized, well known provider in this case
.
- Marius -
14th November 2008, 23:42
Thanks for sharing… We move many times many sites to different servers, in my experience it is the best way, but still you can get only 90-95 % your traffic moved with this. The rest is out of your control. The proxy servers, ISP or corporate DNS servers some time will not refresh as per the TTL. I have many experiences that I was getting traffic in old server after a week.
But I don’t know any other better way.
Regards
Sunil
16th November 2008, 21:24
@Sunil: that’s true, there are things we can’t control. In such cases, depending on the complexity and the need to redirect those users to the new site, you could run some sort of proxy (nginx, or even apache/mod_proxy) and send them to the real content.
ps. from my experience those that still come to the old ip after a few days are just junk… normally spam bots that cache the ips to be fast and skip dns requests for ex.
hth,
- Marius -
28th January 2010, 08:20
hello , plz help hv a question … on my domain i want to assign nameservers … so i made with 2003 a nameserver named ns1.circuitcity.gr but dont know what IP do i use ..
nameserver IP = ???? pc static local ip ? pc primary dns ip ? or what ip ? THANK YOU