You have your site running on an old hardware and want to migrate it to a new upgraded hardware which would result in change of the ipaddress of your site and in turn imply downtime for your site. You want to minimize the downtime due to the change in ipaddress. This can be easily achieved using the Time-to-live (TTL) values of the Domain Naming Service (DNS) entries of your website.
The users usually use your site name and not the ipaddress to visit to your site. DNS is used to resolve the site name to the correct ipaddress. The DNS entry is stored at various levels (browser, OS, proxy server, DNS servers, etc) and is cached for a specific period called as Time-to-live (TTL). Once the TTL expires, the DNS record will be fetched again from the DNS Server. Usually the TTL for a DNS entry is specified as 3600 sec (i.e. 1 hr). The TTL values can be even lower (0, i.e. no caching) or higher (up to 68 years).
The TTL values of DNS entry are changed from the Nameservers of your site. They are defined in the DNS Zone files on your nameservers. The variable for TTL is $TTL and the value for TTL is specified in seconds. For example, if you want to set your TTL to 5 minutes you will use the following line in your Zone file:
Here are steps involved around updating the DNS entry. (These steps are to minimize the effect of DNS entry update and not to update the DNS entry)
- Lower the TTL of the record that you want to change to a small value like 5 mins, 1 min, 30 seconds or even less.
- Wait the old TTL value for the servers to update to the new TTL values. That means, if the previous TTL value was 1 hour, you should wait for 1 hour after changing the TTL values for all the servers to update to the new TTL value.
- Now change the DNS entry.
- After changing the DNS entry, wait for the new TTL value for the DNS entry to be updated. After this, the DNS value is updated on all servers which follow the RFC.
- Test your changes, and if everything is fine you should increase your TTL values again to a suitable value for your server like 3600 sec (1 hour). If something goes wrong, or you want to change the DNS entry again, then follow the above steps again to update the DNS record.
In this entire process the values of your DNS entry are inconsistent only for the new TTL values that you had lowered it to. Also, you can keep the TTL values low all the time, however, this will increase the load on your DNS servers and hence, it is not a good practice. Keeping the values always high can reduce the load on your DNS servers. However, you don’t want to do that because when you want to change the entry you will have to wait for at least that amount of time before the changes are reflected everywhere, causing inconsistencies in the entries for longer periods of time. Usually the TTL for DNS entries is kept between 1 hour and 1 day.
Also, a few things to note:
- Not all servers on the internet respect the TTL values of your DNS entry. Some servers may still ignore the lower TTL value of your DNS entry and cache for longer periods like 1 hour.
- Many browsers and Operating Systems also cache the DNS entry, and may or may not respect the TTL value set by you.
- The DNS change would not have any effect on the users who access the site using ipaddress. The DNS entry change would affect only the users who use your domain name to access the site. If the users are using your old ipaddress they will still be using your old servers, unless you have some mechanism to redirect them to your new servers.